Fix the signup.

This commit is contained in:
Yang Luo
2021-04-28 21:25:58 +08:00
parent ea9bdbf45e
commit 35e482f24e
6 changed files with 66 additions and 30 deletions

View File

@ -37,7 +37,9 @@ type RequestForm struct {
Password string `json:"password"` Password string `json:"password"`
Name string `json:"name"` Name string `json:"name"`
Email string `json:"email"` Email string `json:"email"`
PhonePrefix string `json:"phonePrefix"`
Phone string `json:"phone"` Phone string `json:"phone"`
Affiliation string `json:"affiliation"`
Application string `json:"application"` Application string `json:"application"`
Provider string `json:"provider"` Provider string `json:"provider"`
@ -75,26 +77,34 @@ func (c *ApiController) Signup() {
panic(err) 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 != "" { if msg != "" {
resp = Response{Status: "error", Msg: msg, Data: ""} resp = Response{Status: "error", Msg: msg, Data: ""}
} else { } else {
user := &object.User{ user := &object.User{
Owner: form.Organization, Owner: form.Organization,
Name: form.Username, Name: form.Username,
CreatedTime: util.GetCurrentTime(), CreatedTime: util.GetCurrentTime(),
Password: form.Password, Id: util.GenerateId(),
PasswordType: "plain", Type: "normal-user",
DisplayName: form.Name, Password: form.Password,
Email: form.Email, PasswordType: "plain",
Phone: form.Phone, 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) object.AddUser(user)
//c.SetSessionUser(user) //c.SetSessionUser(user)
util.LogInfo(c.Ctx, "API: [%s] is signed up as new user", user) util.LogInfo(c.Ctx, "API: [%s] is signed up as new user", userId)
resp = Response{Status: "ok", Msg: "", Data: user} resp = Response{Status: "ok", Msg: "", Data: userId}
} }
c.Data["json"] = resp c.Data["json"] = resp

View File

@ -24,6 +24,7 @@ import * as Setting from "../Setting";
import {GithubLoginButton, GoogleLoginButton} from "react-social-login-buttons"; import {GithubLoginButton, GoogleLoginButton} from "react-social-login-buttons";
import QqLoginButton from "./QqLoginButton"; import QqLoginButton from "./QqLoginButton";
import i18next from "i18next"; import i18next from "i18next";
import {authConfig} from "./Auth";
class LoginPage extends React.Component { class LoginPage extends React.Component {
constructor(props) { 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) { renderForm(application) {
if (this.state.msg !== null) { if (this.state.msg !== null) {
return Util.renderMessage(this.state.msg) return Util.renderMessage(this.state.msg)
@ -156,15 +165,16 @@ class LoginPage extends React.Component {
style={{width: "250px"}} style={{width: "250px"}}
size="large" size="large"
> >
<Form.Item style={{height: 0, visibility: "hidden"}} <Form.Item
name="organization" style={{height: 0, visibility: "hidden"}}
rules={[{ required: true, message: 'Please input your organization!' }]} name="organization"
rules={[
{
required: true,
message: 'Please input your organization!',
},
]}
> >
<Input
prefix={<UserOutlined className="site-form-item-icon" />}
placeholder="organization"
disabled={!application.enablePassword}
/>
</Form.Item> </Form.Item>
<Form.Item <Form.Item
name="username" name="username"
@ -210,7 +220,7 @@ class LoginPage extends React.Component {
!application.enableSignUp ? null : ( !application.enableSignUp ? null : (
<div style={{float: "right"}}> <div style={{float: "right"}}>
{i18next.t("login:No account yet?")}&nbsp; {i18next.t("login:No account yet?")}&nbsp;
<Link to={"/signup"}> <Link to={this.getSignupPath(application)}>
{i18next.t("login:sign up now")} {i18next.t("login:sign up now")}
</Link> </Link>
</div> </div>
@ -250,7 +260,7 @@ class LoginPage extends React.Component {
<br/> <br/>
<div style={{float: "right"}}> <div style={{float: "right"}}>
No account yet?&nbsp; No account yet?&nbsp;
<Link to={"/signup"}> <Link to={this.getSignupPath(application)}>
sign up now sign up now
</Link> </Link>
</div> </div>

View File

@ -15,6 +15,7 @@
import React from "react"; import React from "react";
import {Link} from "react-router-dom"; import {Link} from "react-router-dom";
import {Result, Button} from 'antd'; import {Result, Button} from 'antd';
import i18next from "i18next";
class ResultPage extends React.Component { class ResultPage extends React.Component {
constructor(props) { constructor(props) {
@ -29,12 +30,12 @@ class ResultPage extends React.Component {
<div> <div>
<Result <Result
status="success" status="success"
title="Your account is created" title={i18next.t("signup:Your account has been created!")}
subTitle="Please click the below button to login" subTitle={i18next.t("signup:Please click the below button to sign in")}
extra={[ extra={[
<Link to="/login"> <Link to="/login">
<Button type="primary" key="login"> <Button type="primary" key="login">
Login {i18next.t("login:Sign In")}
</Button> </Button>
</Link> </Link>
]} ]}

View File

@ -106,7 +106,7 @@ class SignupPage extends React.Component {
renderForm(application) { renderForm(application) {
const prefixSelector = ( const prefixSelector = (
<Form.Item name="prefix" noStyle> <Form.Item name="phonePrefix" noStyle>
<Select <Select
style={{ style={{
width: 80, width: 80,
@ -126,12 +126,23 @@ class SignupPage extends React.Component {
onFinish={(values) => this.onFinish(values)} onFinish={(values) => this.onFinish(values)}
onFinishFailed={(errorInfo) => this.onFinishFailed(errorInfo.values, errorInfo.errorFields, errorInfo.outOfDate)} onFinishFailed={(errorInfo) => this.onFinishFailed(errorInfo.values, errorInfo.errorFields, errorInfo.outOfDate)}
initialValues={{ initialValues={{
application: application.name, organization: application.organization,
prefix: '86', phonePrefix: '86',
}} }}
style={{width: !Setting.isMobile() ? "400px" : "250px"}} style={{width: !Setting.isMobile() ? "400px" : "250px"}}
size="large" size="large"
> >
<Form.Item
style={{height: 0, visibility: "hidden"}}
name="organization"
rules={[
{
required: true,
message: 'Please input your organization!',
},
]}
>
</Form.Item>
<Form.Item <Form.Item
name="username" name="username"
label={i18next.t("signup:Username")} label={i18next.t("signup:Username")}
@ -146,7 +157,7 @@ class SignupPage extends React.Component {
<Input /> <Input />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
name="displayName" name="name"
label={i18next.t("general:Display name")} label={i18next.t("general:Display name")}
rules={[ rules={[
{ {

View File

@ -44,7 +44,9 @@
"Accept": "Accept", "Accept": "Accept",
"Terms of Use": "Terms of Use", "Terms of Use": "Terms of Use",
"Have account?": "Have account?", "Have account?": "Have account?",
"sign in now": "sign in now" "sign in now": "sign in now",
"Your account has been created!": "Your account has been created!",
"Please click the below button to sign in": "Please click the below button to sign in"
}, },
"login": "login":
{ {

View File

@ -44,7 +44,9 @@
"Accept": "阅读并接受", "Accept": "阅读并接受",
"Terms of Use": "《用户协议》", "Terms of Use": "《用户协议》",
"Have account?": "已有账号?", "Have account?": "已有账号?",
"sign in now": "立即登录" "sign in now": "立即登录",
"Your account has been created!": "您的账号已创建!",
"Please click the below button to sign in": "请点击下方按钮登录"
}, },
"login": "login":
{ {