From 35e482f24e19191973b24f368551bff5cd24b5d1 Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Wed, 28 Apr 2021 21:25:58 +0800 Subject: [PATCH] Fix the signup. --- controllers/account.go | 32 +++++++++++++++++++++----------- web/src/auth/LoginPage.js | 30 ++++++++++++++++++++---------- web/src/auth/ResultPage.js | 7 ++++--- web/src/auth/SignupPage.js | 19 +++++++++++++++---- web/src/locales/en.json | 4 +++- web/src/locales/zh.json | 4 +++- 6 files changed, 66 insertions(+), 30 deletions(-) diff --git a/controllers/account.go b/controllers/account.go index bac576e5..a5d1efbf 100644 --- a/controllers/account.go +++ b/controllers/account.go @@ -37,7 +37,9 @@ type RequestForm struct { Password string `json:"password"` Name string `json:"name"` Email string `json:"email"` + PhonePrefix string `json:"phonePrefix"` Phone string `json:"phone"` + Affiliation string `json:"affiliation"` Application string `json:"application"` Provider string `json:"provider"` @@ -75,26 +77,34 @@ func (c *ApiController) Signup() { panic(err) } - msg := object.CheckUserSignup(form.Username, form.Password) + userId := fmt.Sprintf("%s/%s", form.Organization, form.Username) + msg := object.CheckUserSignup(userId, form.Password) if msg != "" { resp = Response{Status: "error", Msg: msg, Data: ""} } else { user := &object.User{ - Owner: form.Organization, - Name: form.Username, - CreatedTime: util.GetCurrentTime(), - Password: form.Password, - PasswordType: "plain", - DisplayName: form.Name, - Email: form.Email, - Phone: form.Phone, + Owner: form.Organization, + Name: form.Username, + CreatedTime: util.GetCurrentTime(), + Id: util.GenerateId(), + Type: "normal-user", + Password: form.Password, + PasswordType: "plain", + DisplayName: form.Name, + Avatar: "https://casbin.org/img/casbin.svg", + Email: form.Email, + PhonePrefix: form.PhonePrefix, + Phone: form.Phone, + Affiliation: form.Affiliation, + IsAdmin: false, + IsGlobalAdmin: false, } object.AddUser(user) //c.SetSessionUser(user) - util.LogInfo(c.Ctx, "API: [%s] is signed up as new user", user) - resp = Response{Status: "ok", Msg: "", Data: user} + util.LogInfo(c.Ctx, "API: [%s] is signed up as new user", userId) + resp = Response{Status: "ok", Msg: "", Data: userId} } c.Data["json"] = resp diff --git a/web/src/auth/LoginPage.js b/web/src/auth/LoginPage.js index d1006ef4..28f7e14f 100644 --- a/web/src/auth/LoginPage.js +++ b/web/src/auth/LoginPage.js @@ -24,6 +24,7 @@ import * as Setting from "../Setting"; import {GithubLoginButton, GoogleLoginButton} from "react-social-login-buttons"; import QqLoginButton from "./QqLoginButton"; import i18next from "i18next"; +import {authConfig} from "./Auth"; class LoginPage extends React.Component { constructor(props) { @@ -139,6 +140,14 @@ class LoginPage extends React.Component { } } + getSignupPath(application) { + if (authConfig.appName === application.name) { + return "/signup"; + } else { + return `/signup/${application.name}`; + } + } + renderForm(application) { if (this.state.msg !== null) { return Util.renderMessage(this.state.msg) @@ -156,15 +165,16 @@ class LoginPage extends React.Component { style={{width: "250px"}} size="large" > - - } - placeholder="organization" - disabled={!application.enablePassword} - /> {i18next.t("login:No account yet?")}  - + {i18next.t("login:sign up now")} @@ -250,7 +260,7 @@ class LoginPage extends React.Component {
No account yet?  - + sign up now
diff --git a/web/src/auth/ResultPage.js b/web/src/auth/ResultPage.js index ff1885df..e4aaba75 100644 --- a/web/src/auth/ResultPage.js +++ b/web/src/auth/ResultPage.js @@ -15,6 +15,7 @@ import React from "react"; import {Link} from "react-router-dom"; import {Result, Button} from 'antd'; +import i18next from "i18next"; class ResultPage extends React.Component { constructor(props) { @@ -29,12 +30,12 @@ class ResultPage extends React.Component {
]} diff --git a/web/src/auth/SignupPage.js b/web/src/auth/SignupPage.js index 05418232..b46eead9 100644 --- a/web/src/auth/SignupPage.js +++ b/web/src/auth/SignupPage.js @@ -106,7 +106,7 @@ class SignupPage extends React.Component { renderForm(application) { const prefixSelector = ( - +