From 101d41825755d521ec3fc27f796df097bfccfe64 Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Sun, 14 Feb 2021 00:54:42 +0800 Subject: [PATCH] Fix code format. --- controllers/auth_github.go | 5 ++- web/src/App.js | 4 +-- web/src/backend/AccountBackend.js | 2 +- .../common/{AuthBox.js => AuthCallback.js} | 32 ++++++++----------- 4 files changed, 18 insertions(+), 25 deletions(-) rename web/src/common/{AuthBox.js => AuthCallback.js} (71%) diff --git a/controllers/auth_github.go b/controllers/auth_github.go index c66c7e5f..f80f763b 100644 --- a/controllers/auth_github.go +++ b/controllers/auth_github.go @@ -89,7 +89,7 @@ func (c *ApiController) AuthGithub() { if err != nil { panic(err) } - req.Header.Add("Authorization", "token " + token.AccessToken) + req.Header.Add("Authorization", "token "+token.AccessToken) response, err := httpClient.Do(req) if err != nil { panic(err) @@ -115,7 +115,7 @@ func (c *ApiController) AuthGithub() { if err != nil { panic(err) } - req.Header.Add("Authorization", "token " + token.AccessToken) + req.Header.Add("Authorization", "token "+token.AccessToken) response2, err := httpClient.Do(req) if err != nil { panic(err) @@ -175,6 +175,5 @@ func (c *ApiController) AuthGithub() { } c.Data["json"] = resp - c.ServeJSON() } diff --git a/web/src/App.js b/web/src/App.js index 3bc8296a..2c0e7484 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -32,7 +32,7 @@ import AccountPage from "./account/AccountPage"; import LoginPage from "./account/LoginPage"; import HomePage from "./basic/HomePage"; import CustomGithubCorner from "./CustomGithubCorner"; -import CallbackBox from "./common/AuthBox"; +import AuthCallback from "./common/AuthCallback"; const { Header, Footer } = Layout; @@ -274,7 +274,7 @@ class App extends Component { this.renderHomeIfLoggedIn()}/> - + this.renderLoginIfNotLoggedIn()}/> this.renderLoginIfNotLoggedIn()}/> this.renderLoginIfNotLoggedIn()}/> diff --git a/web/src/backend/AccountBackend.js b/web/src/backend/AccountBackend.js index 35e5b418..3f73895f 100644 --- a/web/src/backend/AccountBackend.js +++ b/web/src/backend/AccountBackend.js @@ -51,7 +51,7 @@ export function logout() { }).then(res => res.json()); } -export function githubLogin(providerName, code, state, redirectUrl, addition) { +export function authLogin(providerName, code, state, redirectUrl, addition) { console.log(redirectUrl) return fetch(`${Setting.ServerUrl}/api/auth/github?provider=${providerName}&code=${code}&state=${state}&redirect_url=${redirectUrl}&addition=${addition}`, { method: 'GET', diff --git a/web/src/common/AuthBox.js b/web/src/common/AuthCallback.js similarity index 71% rename from web/src/common/AuthBox.js rename to web/src/common/AuthCallback.js index 293ac2e1..ace8b77b 100644 --- a/web/src/common/AuthBox.js +++ b/web/src/common/AuthCallback.js @@ -17,40 +17,34 @@ import {withRouter} from "react-router-dom"; import * as Setting from "../Setting"; import * as AccountBackend from "../backend/AccountBackend"; -class CallbackBox extends React.Component { +class AuthCallback extends React.Component { constructor(props) { super(props); + const params = new URLSearchParams(this.props.location.search); this.state = { classes: props, providerType: props.match.params.providerType, providerName: props.match.params.providerName, addition: props.match.params.addition, - state: "", - code: "", + state: params.get("state"), + code: params.get("code"), isAuthenticated: false, isSignedUp: false, email: "" }; - const params = new URLSearchParams(this.props.location.search); - this.state.code = params.get("code"); - this.state.state = params.get("state"); } getAuthenticatedInfo() { let redirectUrl; redirectUrl = `${Setting.ClientUrl}/callback/${this.state.providerType}/${this.state.providerName}/${this.state.addition}`; - switch (this.state.providerType) { - case "github": - AccountBackend.githubLogin(this.state.providerName, this.state.code, this.state.state, redirectUrl, this.state.addition) - .then((res) => { - if (res.status === "ok") { - window.location.href = '/'; - }else { - Setting.showMessage("error", res?.msg); - } - }); - break; - } + AccountBackend.authLogin(this.state.providerName, this.state.code, this.state.state, redirectUrl, this.state.addition) + .then((res) => { + if (res.status === "ok") { + window.location.href = '/'; + }else { + Setting.showMessage("error", res?.msg); + } + }); } componentDidMount() { @@ -68,4 +62,4 @@ class CallbackBox extends React.Component { } } -export default withRouter(CallbackBox); +export default withRouter(AuthCallback);