2022-02-13 23:39:27 +08:00
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
2021-03-26 21:57:41 +08:00
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2022-07-10 15:45:55 +08:00
import React from "react" ;
2023-01-19 11:39:24 +01:00
import { Button , Form , Input , Result } from "antd" ;
2021-03-26 21:57:41 +08:00
import * as Setting from "../Setting" ;
import * as AuthBackend from "./AuthBackend" ;
2022-08-05 18:59:56 +08:00
import * as ProviderButton from "./ProviderButton" ;
2021-04-28 00:47:12 +08:00
import i18next from "i18next" ;
2021-04-28 15:54:50 +08:00
import * as Util from "./Util" ;
import { authConfig } from "./Auth" ;
import * as ApplicationBackend from "../backend/ApplicationBackend" ;
2023-03-26 18:44:47 +08:00
import * as AgreementModal from "../common/modal/AgreementModal" ;
2023-02-12 18:56:56 +08:00
import { SendCodeInput } from "../common/SendCodeInput" ;
2023-03-26 18:44:47 +08:00
import RegionSelect from "../common/select/RegionSelect" ;
import CustomGithubCorner from "../common/CustomGithubCorner" ;
import LanguageSelect from "../common/select/LanguageSelect" ;
2022-11-13 05:16:49 +01:00
import { withRouter } from "react-router-dom" ;
2023-03-26 18:44:47 +08:00
import { CountryCodeSelect } from "../common/select/CountryCodeSelect" ;
2023-06-17 00:01:20 +08:00
import * as PasswordChecker from "../common/PasswordChecker" ;
2021-03-26 21:57:41 +08:00
const formItemLayout = {
labelCol : {
xs : {
span : 24 ,
} ,
sm : {
2021-07-31 16:02:48 +08:00
span : 8 ,
2021-03-26 21:57:41 +08:00
} ,
} ,
wrapperCol : {
xs : {
span : 24 ,
} ,
sm : {
2022-12-06 00:50:17 +08:00
span : 16 ,
2021-03-26 21:57:41 +08:00
} ,
} ,
} ;
2023-03-26 18:44:47 +08:00
export const tailFormItemLayout = {
2021-03-26 21:57:41 +08:00
wrapperCol : {
xs : {
span : 24 ,
offset : 0 ,
} ,
sm : {
span : 16 ,
offset : 8 ,
} ,
} ,
} ;
2021-04-27 22:47:44 +08:00
class SignupPage extends React . Component {
2021-03-26 21:57:41 +08:00
constructor ( props ) {
super ( props ) ;
this . state = {
classes : props ,
2023-04-25 16:00:24 +08:00
applicationName : ( props . applicationName ? ? props . match ? . params ? . applicationName ) ? ? null ,
2021-05-18 20:11:03 +08:00
email : "" ,
2021-05-20 21:09:12 +08:00
phone : "" ,
2023-02-16 22:53:28 +08:00
countryCode : "" ,
2021-05-20 21:09:12 +08:00
emailCode : "" ,
2021-06-23 11:41:21 +08:00
phoneCode : "" ,
validEmail : false ,
validPhone : false ,
2021-07-31 16:02:48 +08:00
region : "" ,
2021-08-03 21:00:07 +08:00
isTermsOfUseVisible : false ,
2021-08-10 10:43:33 +08:00
termsOfUseContent : "" ,
2021-03-26 21:57:41 +08:00
} ;
this . form = React . createRef ( ) ;
}
2023-02-27 20:10:59 +08:00
componentDidMount ( ) {
2022-07-19 23:31:17 +08:00
const oAuthParams = Util . getOAuthGetParameters ( ) ;
if ( oAuthParams !== null ) {
const signinUrl = window . location . href . replace ( "/signup/oauth/authorize" , "/login/oauth/authorize" ) ;
sessionStorage . setItem ( "signinUrl" , signinUrl ) ;
}
2023-03-24 23:17:54 +08:00
if ( this . getApplicationObj ( ) === undefined ) {
if ( this . state . applicationName !== null ) {
this . getApplication ( this . state . applicationName ) ;
2023-04-22 18:20:45 +08:00
} else if ( oAuthParams !== null ) {
this . getApplicationLogin ( oAuthParams ) ;
2022-12-22 23:39:02 +08:00
} else {
2023-03-24 23:17:54 +08:00
Setting . showMessage ( "error" , ` Unknown application name: ${ this . state . applicationName } ` ) ;
2023-04-22 18:20:45 +08:00
this . onUpdateApplication ( null ) ;
2022-12-22 23:39:02 +08:00
}
2021-04-28 15:54:50 +08:00
}
}
2022-07-19 23:31:17 +08:00
getApplication ( applicationName ) {
if ( applicationName === undefined ) {
2021-04-28 15:54:50 +08:00
return ;
}
2022-07-19 23:31:17 +08:00
ApplicationBackend . getApplication ( "admin" , applicationName )
2023-06-27 20:33:47 +07:00
. then ( ( res ) => {
if ( res . status === "error" ) {
Setting . showMessage ( "error" , res . msg ) ;
return ;
}
2023-07-23 09:49:16 +08:00
this . onUpdateApplication ( res . data ) ;
2021-04-28 15:54:50 +08:00
} ) ;
}
2023-04-22 18:20:45 +08:00
getApplicationLogin ( oAuthParams ) {
AuthBackend . getApplicationLogin ( oAuthParams )
. then ( ( res ) => {
if ( res . status === "ok" ) {
const application = res . data ;
this . onUpdateApplication ( application ) ;
} else {
this . onUpdateApplication ( null ) ;
this . setState ( {
msg : res . msg ,
} ) ;
}
} ) ;
}
2023-08-24 23:20:50 +08:00
getResultPath ( application , signupParams ) {
if ( signupParams ? . plan && signupParams ? . pricing ) {
// the prompt page needs the user to be signed in, so for paid-user sign up, just go to buy-plan page
return ` /buy-plan/ ${ application . organization } / ${ signupParams ? . pricing } ?user= ${ signupParams . username } &plan= ${ signupParams . plan } ` ;
}
2021-04-28 22:40:21 +08:00
if ( authConfig . appName === application . name ) {
return "/result" ;
} else {
2021-06-20 09:46:06 +08:00
if ( Setting . hasPromptPage ( application ) ) {
return ` /prompt/ ${ application . name } ` ;
} else {
return ` /result/ ${ application . name } ` ;
}
2021-04-28 22:40:21 +08:00
}
}
2021-06-14 13:13:39 +08:00
getApplicationObj ( ) {
2023-03-24 23:17:54 +08:00
return this . props . application ;
2021-06-14 13:13:39 +08:00
}
2021-06-20 13:27:26 +08:00
onUpdateAccount ( account ) {
this . props . onUpdateAccount ( account ) ;
}
2022-12-22 23:39:02 +08:00
onUpdateApplication ( application ) {
this . props . onUpdateApplication ( application ) ;
}
2022-10-22 21:43:41 +08:00
parseOffset ( offset ) {
if ( offset === 2 || offset === 4 || Setting . inIframe ( ) || Setting . isMobile ( ) ) {
return "0 auto" ;
}
if ( offset === 1 ) {
return "0 10%" ;
}
if ( offset === 3 ) {
return "0 60%" ;
}
}
2021-03-26 21:57:41 +08:00
onFinish ( values ) {
2021-06-14 13:13:39 +08:00
const application = this . getApplicationObj ( ) ;
2023-05-20 10:56:21 +03:00
const params = new URLSearchParams ( window . location . search ) ;
2023-08-24 23:20:50 +08:00
values . plan = params . get ( "plan" ) ;
values . pricing = params . get ( "pricing" ) ;
2021-04-27 22:47:44 +08:00
AuthBackend . signup ( values )
2021-03-26 21:57:41 +08:00
. then ( ( res ) => {
2022-07-10 15:45:55 +08:00
if ( res . status === "ok" ) {
2023-09-08 21:03:30 +08:00
// the user's id will be returned by `signup()`, if user signup by phone, the `username` in `values` is undefined.
values . username = res . data . split ( "/" ) [ 1 ] ;
2023-08-24 23:20:50 +08:00
if ( Setting . hasPromptPage ( application ) && ( ! values . plan || ! values . pricing ) ) {
2021-08-01 00:16:13 +08:00
AuthBackend . getAccount ( "" )
. then ( ( res ) => {
let account = null ;
if ( res . status === "ok" ) {
account = res . data ;
account . organization = res . data2 ;
this . onUpdateAccount ( account ) ;
2023-08-24 23:20:50 +08:00
Setting . goToLinkSoft ( this , this . getResultPath ( application , values ) ) ;
2021-08-01 00:16:13 +08:00
} else {
2023-03-18 20:42:02 +08:00
Setting . showMessage ( "error" , ` ${ i18next . t ( "application:Failed to sign in" ) } : ${ res . msg } ` ) ;
2021-06-20 13:27:26 +08:00
}
2021-08-01 00:16:13 +08:00
} ) ;
} else {
2023-08-24 23:20:50 +08:00
Setting . goToLinkSoft ( this , this . getResultPath ( application , values ) ) ;
2021-08-01 00:16:13 +08:00
}
2021-03-26 21:57:41 +08:00
} else {
2021-05-18 20:11:03 +08:00
Setting . showMessage ( "error" , i18next . t ( ` signup: ${ res . msg } ` ) ) ;
2021-03-26 21:57:41 +08:00
}
} ) ;
}
onFinishFailed ( values , errorFields , outOfDate ) {
this . form . current . scrollToField ( errorFields [ 0 ] . name ) ;
}
2022-08-05 18:59:56 +08:00
isProviderVisible ( providerItem ) {
2023-04-22 18:20:45 +08:00
return Setting . isProviderVisibleForSignUp ( providerItem ) ;
2022-08-05 18:59:56 +08:00
}
2021-06-16 14:06:41 +08:00
renderFormItem ( application , signupItem ) {
if ( ! signupItem . visible ) {
return null ;
2021-05-08 00:23:08 +08:00
}
2021-06-16 15:25:54 +08:00
const required = signupItem . required ;
2021-06-16 14:06:41 +08:00
if ( signupItem . name === "Username" ) {
return (
2021-03-26 21:57:41 +08:00
< Form . Item
2021-04-28 00:47:12 +08:00
name = "username"
2023-10-15 17:24:38 +08:00
label = { signupItem . label ? signupItem . label : i18next . t ( "signup:Username" ) }
2021-03-26 21:57:41 +08:00
rules = { [
{
2021-06-16 15:25:54 +08:00
required : required ,
2021-06-17 22:43:30 +08:00
message : i18next . t ( "forget:Please input your username!" ) ,
2021-03-26 21:57:41 +08:00
whitespace : true ,
} ,
] }
>
2023-10-15 17:24:38 +08:00
< Input placeholder = { signupItem . placeholder } / >
2021-03-26 21:57:41 +08:00
< / F o r m . I t e m >
2022-07-10 15:45:55 +08:00
) ;
2021-06-16 14:06:41 +08:00
} else if ( signupItem . name === "Display name" ) {
2022-02-27 14:02:52 +08:00
if ( signupItem . rule === "First, last" && Setting . getLanguage ( ) !== "zh" ) {
return (
< React . Fragment >
< Form . Item
name = "firstName"
2023-10-15 17:24:38 +08:00
label = { signupItem . label ? signupItem . label : i18next . t ( "general:First name" ) }
2022-02-27 14:02:52 +08:00
rules = { [
{
required : required ,
message : i18next . t ( "signup:Please input your first name!" ) ,
whitespace : true ,
} ,
] }
>
2023-10-15 17:24:38 +08:00
< Input placeholder = { signupItem . placeholder } / >
2022-02-27 14:02:52 +08:00
< / F o r m . I t e m >
< Form . Item
name = "lastName"
2023-10-15 17:24:38 +08:00
label = { signupItem . label ? signupItem . label : i18next . t ( "general:Last name" ) }
2022-02-27 14:02:52 +08:00
rules = { [
{
required : required ,
message : i18next . t ( "signup:Please input your last name!" ) ,
whitespace : true ,
} ,
] }
>
2023-10-15 17:24:38 +08:00
< Input placeholder = { signupItem . placeholder } / >
2022-02-27 14:02:52 +08:00
< / F o r m . I t e m >
< / R e a c t . F r a g m e n t >
2022-07-10 15:45:55 +08:00
) ;
2022-02-27 14:02:52 +08:00
}
2021-06-16 14:06:41 +08:00
return (
2021-03-26 21:57:41 +08:00
< Form . Item
2021-04-28 21:25:58 +08:00
name = "name"
2023-10-15 17:24:38 +08:00
label = { ( signupItem . label ? signupItem . label : ( signupItem . rule === "Real name" || signupItem . rule === "First, last" ) ? i18next . t ( "general:Real name" ) : i18next . t ( "general:Display name" ) ) }
2021-03-26 21:57:41 +08:00
rules = { [
{
2021-06-16 15:25:54 +08:00
required : required ,
2022-02-27 14:02:52 +08:00
message : ( signupItem . rule === "Real name" || signupItem . rule === "First, last" ) ? i18next . t ( "signup:Please input your real name!" ) : i18next . t ( "signup:Please input your display name!" ) ,
2021-03-26 21:57:41 +08:00
whitespace : true ,
} ,
] }
>
2023-10-15 17:24:38 +08:00
< Input placeholder = { signupItem . placeholder } / >
2021-03-26 21:57:41 +08:00
< / F o r m . I t e m >
2022-07-10 15:45:55 +08:00
) ;
2021-06-16 14:06:41 +08:00
} else if ( signupItem . name === "Affiliation" ) {
return (
2021-03-26 21:57:41 +08:00
< Form . Item
2021-04-27 22:35:14 +08:00
name = "affiliation"
2023-10-15 17:24:38 +08:00
label = { signupItem . label ? signupItem . label : i18next . t ( "user:Affiliation" ) }
2021-03-26 21:57:41 +08:00
rules = { [
{
2021-06-16 15:25:54 +08:00
required : required ,
2021-04-28 00:47:12 +08:00
message : i18next . t ( "signup:Please input your affiliation!" ) ,
2021-03-26 21:57:41 +08:00
whitespace : true ,
} ,
] }
>
2023-10-15 17:24:38 +08:00
< Input placeholder = { signupItem . placeholder } / >
2021-03-26 21:57:41 +08:00
< / F o r m . I t e m >
2022-07-10 15:45:55 +08:00
) ;
2021-12-28 17:48:24 +08:00
} else if ( signupItem . name === "ID card" ) {
return (
< Form . Item
name = "idCard"
2023-10-15 17:24:38 +08:00
label = { signupItem . label ? signupItem . label : i18next . t ( "user:ID card" ) }
2021-12-28 17:48:24 +08:00
rules = { [
{
required : required ,
message : i18next . t ( "signup:Please input your ID card number!" ) ,
whitespace : true ,
} ,
{
required : required ,
pattern : new RegExp ( /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9X]$/ , "g" ) ,
message : i18next . t ( "signup:Please input the correct ID card number!" ) ,
} ,
] }
>
2023-10-15 17:24:38 +08:00
< Input placeholder = { signupItem . placeholder } / >
2021-12-28 17:48:24 +08:00
< / F o r m . I t e m >
2022-07-10 15:45:55 +08:00
) ;
2021-07-31 16:02:48 +08:00
} else if ( signupItem . name === "Country/Region" ) {
return (
< Form . Item
2022-07-10 15:45:55 +08:00
name = "country_region"
2023-10-15 17:24:38 +08:00
label = { signupItem . label ? signupItem . label : i18next . t ( "user:Country/Region" ) }
2022-07-10 15:45:55 +08:00
rules = { [
{
required : required ,
message : i18next . t ( "signup:Please select your country/region!" ) ,
} ,
] }
2021-07-31 16:02:48 +08:00
>
2023-03-26 18:44:47 +08:00
< RegionSelect onChange = { ( value ) => { this . setState ( { region : value } ) ; } } / >
2021-07-31 16:02:48 +08:00
< / F o r m . I t e m >
2022-07-10 15:45:55 +08:00
) ;
2021-06-16 14:06:41 +08:00
} else if ( signupItem . name === "Email" ) {
return (
< React . Fragment >
< Form . Item
name = "email"
2023-10-15 17:24:38 +08:00
label = { signupItem . label ? signupItem . label : i18next . t ( "general:Email" ) }
2021-06-16 14:06:41 +08:00
rules = { [
{
2021-06-16 15:25:54 +08:00
required : required ,
2021-06-16 14:06:41 +08:00
message : i18next . t ( "signup:Please input your Email!" ) ,
} ,
2021-06-23 11:41:21 +08:00
{
2021-09-21 14:04:17 +08:00
validator : ( _ , value ) => {
if ( this . state . email !== "" && ! Setting . isValidEmail ( this . state . email ) ) {
this . setState ( { validEmail : false } ) ;
return Promise . reject ( i18next . t ( "signup:The input is not valid Email!" ) ) ;
2021-06-23 11:41:21 +08:00
}
2021-09-21 14:04:17 +08:00
this . setState ( { validEmail : true } ) ;
return Promise . resolve ( ) ;
2022-08-06 23:54:56 +08:00
} ,
} ,
2021-06-16 14:06:41 +08:00
] }
>
2023-10-15 17:24:38 +08:00
< Input placeholder = { signupItem . placeholder } onChange = { e => this . setState ( { email : e . target . value } ) } / >
2021-06-16 14:06:41 +08:00
< / F o r m . I t e m >
2022-05-02 17:19:40 +08:00
{
2022-07-10 15:45:55 +08:00
signupItem . rule !== "No verification" &&
2022-05-02 17:19:40 +08:00
< Form . Item
name = "emailCode"
2023-10-15 17:24:38 +08:00
label = { signupItem . label ? signupItem . label : i18next . t ( "code:Email code" ) }
2022-05-02 17:19:40 +08:00
rules = { [ {
required : required ,
message : i18next . t ( "code:Please input your verification code!" ) ,
} ] }
>
2023-02-12 18:56:56 +08:00
< SendCodeInput
2022-05-02 17:19:40 +08:00
disabled = { ! this . state . validEmail }
2022-12-11 15:52:36 +08:00
method = { "signup" }
2022-07-10 00:40:52 +08:00
onButtonClickArgs = { [ this . state . email , "email" , Setting . getApplicationName ( application ) ] }
2022-08-23 23:30:45 +08:00
application = { application }
2022-05-02 17:19:40 +08:00
/ >
< / F o r m . I t e m >
}
2021-06-16 14:06:41 +08:00
< / R e a c t . F r a g m e n t >
2022-07-10 15:45:55 +08:00
) ;
2021-06-16 14:06:41 +08:00
} else if ( signupItem . name === "Phone" ) {
return (
< React . Fragment >
2023-10-15 17:24:38 +08:00
< Form . Item label = { signupItem . label ? signupItem . label : i18next . t ( "general:Phone" ) } required = { required } >
2023-02-16 22:53:28 +08:00
< Input . Group compact >
< Form . Item
name = "countryCode"
noStyle
rules = { [
{
required : required ,
message : i18next . t ( "signup:Please select your country code!" ) ,
} ,
] }
>
2023-03-05 21:52:40 +08:00
< CountryCodeSelect
2023-02-16 22:53:28 +08:00
style = { { width : "35%" } }
countryCodes = { this . getApplicationObj ( ) . organizationObj . countryCodes }
/ >
< / F o r m . I t e m >
< Form . Item
name = "phone"
2023-02-27 22:07:28 +08:00
dependencies = { [ "countryCode" ] }
2023-02-16 22:53:28 +08:00
noStyle
rules = { [
{
required : required ,
message : i18next . t ( "signup:Please input your phone number!" ) ,
} ,
2023-02-27 22:07:28 +08:00
( { getFieldValue } ) => ( {
2023-02-16 22:53:28 +08:00
validator : ( _ , value ) => {
2023-03-27 22:52:49 +08:00
if ( ! required && ! value ) {
2023-03-15 23:44:38 +08:00
return Promise . resolve ( ) ;
}
2023-03-27 22:52:49 +08:00
if ( value && ! Setting . isValidPhone ( value , getFieldValue ( "countryCode" ) ) ) {
2023-02-16 22:53:28 +08:00
this . setState ( { validPhone : false } ) ;
return Promise . reject ( i18next . t ( "signup:The input is not valid Phone!" ) ) ;
}
this . setState ( { validPhone : true } ) ;
return Promise . resolve ( ) ;
} ,
2023-02-27 22:07:28 +08:00
} ) ,
2023-02-16 22:53:28 +08:00
] }
>
< Input
2023-10-15 17:24:38 +08:00
placeholder = { signupItem . placeholder }
2023-02-16 22:53:28 +08:00
style = { { width : "65%" } }
onChange = { e => this . setState ( { phone : e . target . value } ) }
/ >
< / F o r m . I t e m >
< / I n p u t . G r o u p >
2021-06-16 14:06:41 +08:00
< / F o r m . I t e m >
2023-04-16 20:34:06 +08:00
{
signupItem . rule !== "No verification" &&
< Form . Item
name = "phoneCode"
2023-10-15 17:24:38 +08:00
label = { signupItem . label ? signupItem . label : i18next . t ( "code:Phone code" ) }
2023-04-16 20:34:06 +08:00
rules = { [
{
required : required ,
message : i18next . t ( "code:Please input your phone verification code!" ) ,
} ,
] }
>
< SendCodeInput
disabled = { ! this . state . validPhone }
method = { "signup" }
onButtonClickArgs = { [ this . state . phone , "phone" , Setting . getApplicationName ( application ) ] }
application = { application }
countryCode = { this . form . current ? . getFieldValue ( "countryCode" ) }
/ >
< / F o r m . I t e m >
}
2021-06-16 14:06:41 +08:00
< / R e a c t . F r a g m e n t >
2022-07-10 15:45:55 +08:00
) ;
2021-09-21 14:04:17 +08:00
} else if ( signupItem . name === "Password" ) {
return (
< Form . Item
name = "password"
2023-10-15 17:24:38 +08:00
label = { signupItem . label ? signupItem . label : i18next . t ( "general:Password" ) }
2021-09-21 14:04:17 +08:00
rules = { [
{
required : required ,
2023-06-17 00:01:20 +08:00
validateTrigger : "onChange" ,
validator : ( rule , value ) => {
const errorMsg = PasswordChecker . checkPasswordComplexity ( value , application . organizationObj . passwordOptions ) ;
if ( errorMsg === "" ) {
return Promise . resolve ( ) ;
} else {
return Promise . reject ( errorMsg ) ;
}
} ,
2021-09-21 14:04:17 +08:00
} ,
] }
hasFeedback
>
2023-10-15 17:24:38 +08:00
< Input . Password placeholder = { signupItem . placeholder } / >
2021-09-21 14:04:17 +08:00
< / F o r m . I t e m >
2022-07-10 15:45:55 +08:00
) ;
2021-09-21 14:04:17 +08:00
} else if ( signupItem . name === "Confirm password" ) {
return (
< Form . Item
name = "confirm"
2023-10-15 17:24:38 +08:00
label = { signupItem . label ? signupItem . label : i18next . t ( "signup:Confirm" ) }
2022-07-10 15:45:55 +08:00
dependencies = { [ "password" ] }
2021-09-21 14:04:17 +08:00
hasFeedback
rules = { [
{
required : required ,
message : i18next . t ( "signup:Please confirm your password!" ) ,
} ,
2022-07-10 15:45:55 +08:00
( { getFieldValue } ) => ( {
2021-09-21 14:04:17 +08:00
validator ( rule , value ) {
2022-07-10 15:45:55 +08:00
if ( ! value || getFieldValue ( "password" ) === value ) {
2021-09-21 14:04:17 +08:00
return Promise . resolve ( ) ;
}
return Promise . reject ( i18next . t ( "signup:Your confirmed password is inconsistent with the password!" ) ) ;
} ,
} ) ,
] }
>
2023-10-15 17:24:38 +08:00
< Input . Password placeholder = { signupItem . placeholder } / >
2021-09-21 14:04:17 +08:00
< / F o r m . I t e m >
2022-07-10 15:45:55 +08:00
) ;
2023-08-24 13:42:17 +08:00
} else if ( signupItem . name === "Invitation code" ) {
return (
< Form . Item
name = "invitationCode"
2023-10-15 17:24:38 +08:00
label = { signupItem . label ? signupItem . label : i18next . t ( "application:Invitation code" ) }
2023-08-24 13:42:17 +08:00
rules = { [
{
required : required ,
message : i18next . t ( "signup:Please input your invitation code!" ) ,
} ,
] }
>
2023-10-15 17:24:38 +08:00
< Input placeholder = { signupItem . placeholder } / >
2023-08-24 13:42:17 +08:00
< / F o r m . I t e m >
) ;
2021-06-16 14:06:41 +08:00
} else if ( signupItem . name === "Agreement" ) {
2023-03-26 18:44:47 +08:00
return AgreementModal . renderAgreementFormItem ( application , required , tailFormItemLayout , this ) ;
2021-06-16 14:06:41 +08:00
}
}
2021-03-26 21:57:41 +08:00
2021-06-16 14:06:41 +08:00
renderForm ( application ) {
if ( ! application . enableSignUp ) {
return (
< Result
status = "error"
2022-11-27 14:04:45 +01:00
title = { i18next . t ( "application:Sign Up Error" ) }
subTitle = { i18next . t ( "application:The application does not allow to sign up new account" ) }
2021-06-16 14:06:41 +08:00
extra = { [
2022-11-13 05:16:49 +01:00
< Button type = "primary" key = "signin" onClick = { ( ) => Setting . redirectToLoginPage ( application , this . props . history ) } >
2022-10-27 20:23:57 +02:00
{
i18next . t ( "login:Sign In" )
}
2022-08-06 23:54:56 +08:00
< / B u t t o n > ,
2021-03-26 21:57:41 +08:00
] }
>
2021-06-16 14:06:41 +08:00
< / R e s u l t >
2022-07-10 15:45:55 +08:00
) ;
2021-06-16 14:06:41 +08:00
}
return (
< Form
{ ... formItemLayout }
ref = { this . form }
name = "signup"
onFinish = { ( values ) => this . onFinish ( values ) }
onFinishFailed = { ( errorInfo ) => this . onFinishFailed ( errorInfo . values , errorInfo . errorFields , errorInfo . outOfDate ) }
initialValues = { {
application : application . name ,
organization : application . organization ,
2023-02-27 22:07:28 +08:00
countryCode : application . organizationObj . countryCodes ? . [ 0 ] ,
2021-06-16 14:06:41 +08:00
} }
size = "large"
2022-12-06 00:50:17 +08:00
layout = { Setting . isMobile ( ) ? "vertical" : "horizontal" }
style = { { width : Setting . isMobile ( ) ? "300px" : "400px" } }
2021-06-16 14:06:41 +08:00
>
2021-03-26 21:57:41 +08:00
< Form . Item
2021-06-16 14:06:41 +08:00
name = "application"
2022-12-06 00:50:17 +08:00
hidden = { true }
2021-03-26 21:57:41 +08:00
rules = { [
{
required : true ,
2022-07-10 15:45:55 +08:00
message : "Please input your application!" ,
2021-03-26 21:57:41 +08:00
} ,
] }
>
< / F o r m . I t e m >
2021-05-18 20:11:03 +08:00
< Form . Item
2021-06-16 14:06:41 +08:00
name = "organization"
2022-12-06 00:50:17 +08:00
hidden = { true }
2021-05-18 20:11:03 +08:00
rules = { [
{
required : true ,
2022-07-10 15:45:55 +08:00
message : "Please input your organization!" ,
2021-05-18 20:11:03 +08:00
} ,
] }
>
2021-03-26 21:57:41 +08:00
< / F o r m . I t e m >
2021-06-16 14:06:41 +08:00
{
2021-06-22 11:31:53 +08:00
application . signupItems ? . map ( signupItem => this . renderFormItem ( application , signupItem ) )
2021-06-16 14:06:41 +08:00
}
2021-03-26 21:57:41 +08:00
< Form . Item { ... tailFormItemLayout } >
< Button type = "primary" htmlType = "submit" >
2021-04-28 00:47:12 +08:00
{ i18next . t ( "account:Sign Up" ) }
2021-03-26 21:57:41 +08:00
< / B u t t o n >
2022-12-06 00:50:17 +08:00
& nbsp ; & nbsp ; { i18next . t ( "signup:Have account?" ) } & nbsp ;
2022-06-17 19:57:11 +08:00
< a onClick = { ( ) => {
2022-08-08 23:35:24 +08:00
const linkInStorage = sessionStorage . getItem ( "signinUrl" ) ;
2022-09-04 19:40:30 +08:00
if ( linkInStorage !== null && linkInStorage !== "" ) {
2022-07-10 15:45:55 +08:00
Setting . goToLink ( linkInStorage ) ;
2022-09-04 19:40:30 +08:00
} else {
2022-11-13 05:16:49 +01:00
Setting . redirectToLoginPage ( application , this . props . history ) ;
2022-03-05 16:47:08 +08:00
}
2021-04-28 22:40:21 +08:00
} } >
2021-04-28 00:47:12 +08:00
{ i18next . t ( "signup:sign in now" ) }
2021-07-16 17:04:16 +08:00
< / a >
2021-03-26 21:57:41 +08:00
< / F o r m . I t e m >
2022-08-05 18:59:56 +08:00
{
application . providers . filter ( providerItem => this . isProviderVisible ( providerItem ) ) . map ( providerItem => {
2022-09-28 21:09:39 +08:00
return ProviderButton . renderProviderLogo ( providerItem . provider , application , 30 , 5 , "small" , this . props . location ) ;
2022-08-05 18:59:56 +08:00
} )
}
2021-03-26 21:57:41 +08:00
< / F o r m >
2022-07-10 15:45:55 +08:00
) ;
2021-03-26 21:57:41 +08:00
}
render ( ) {
2021-06-14 13:13:39 +08:00
const application = this . getApplicationObj ( ) ;
2023-03-24 23:17:54 +08:00
if ( application === undefined || application === null ) {
2021-04-28 15:54:50 +08:00
return null ;
}
2021-10-26 13:11:21 +08:00
if ( application . signupHtml !== "" ) {
return (
2022-07-10 15:45:55 +08:00
< div dangerouslySetInnerHTML = { { _ _html : application . signupHtml } } / >
) ;
2021-10-26 13:11:21 +08:00
}
2021-03-26 21:57:41 +08:00
return (
2022-12-22 23:39:02 +08:00
< React . Fragment >
2021-11-06 22:04:20 +08:00
< CustomGithubCorner / >
2022-12-24 17:47:05 +08:00
< div className = "login-content" style = { { margin : this . props . preview ? ? this . parseOffset ( application . formOffset ) } } >
2022-12-04 15:53:46 +08:00
{ Setting . inIframe ( ) || Setting . isMobile ( ) ? null : < div dangerouslySetInnerHTML = { { _ _html : application . formCss } } / > }
2023-05-12 12:16:03 +08:00
{ Setting . inIframe ( ) || ! Setting . isMobile ( ) ? null : < div dangerouslySetInnerHTML = { { _ _html : application . formCssMobile } } / > }
2022-10-22 21:43:41 +08:00
< div className = "login-panel" >
< div className = "side-image" style = { { display : application . formOffset !== 4 ? "none" : null } } >
< div dangerouslySetInnerHTML = { { _ _html : application . formSideHtml } } / >
< / d i v >
< div className = "login-form" >
2022-12-06 00:50:17 +08:00
{
Setting . renderHelmet ( application )
}
{
Setting . renderLogo ( application )
}
2023-03-26 18:44:47 +08:00
< LanguageSelect languages = { application . organizationObj . languages } style = { { top : "55px" , right : "5px" , position : "absolute" } } / >
2022-12-06 00:50:17 +08:00
{
this . renderForm ( application )
}
2021-04-28 15:54:50 +08:00
< / d i v >
2022-10-22 21:43:41 +08:00
< / d i v >
< / d i v >
2022-12-22 23:39:02 +08:00
< / R e a c t . F r a g m e n t >
2022-07-10 15:45:55 +08:00
) ;
2021-03-26 21:57:41 +08:00
}
}
2022-11-13 05:16:49 +01:00
export default withRouter ( SignupPage ) ;