Skip to content

Commit

Permalink
Registration - choice of methods in config
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed May 5, 2024
1 parent 8901797 commit 0bc52a8
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 39 deletions.
6 changes: 6 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
"signing_key": "5K67PNheLkmxkgJ5UjvR8Nyt3GVPoLEN1dMZjFuNETzrNyMecPG",
"delegation": "75000.000000 GESTS",
"free_regs_per_day": 10,
"methods": {
"social": true,
"invite_code": true,
"transfer": true,
"uia": true
},
"uias": {
"assets": ["YMUSDT", "YMPZM", "YMHIVE", "YMXMR", "TESTF"],
"YMXMR": ["YMXHR/YMPZM", "YMPZM/YMUSDT", "YMUSDT/GOLOS"]
Expand Down
84 changes: 56 additions & 28 deletions src/elements/register/VerifyWayTabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,74 @@ class VerifyWayTabs extends React.Component {
}

render() {
const { currentWay } = this.props
const { clientCfg, currentWay } = this.props

const methods = clientCfg.config.registrar.methods

const path = this.getPath()

let social = tt('verify_way_tabs_jsx.social')
if (currentWay === 'social') {
social = <span>{social}</span>
} else {
social = <Link href={path}>{social}</Link>
const methodObjs = []

let k = 0
const curKey = () => {
return ++k
}

const separator = () => <React.Fragment key={curKey()}>&nbsp;|&nbsp;</React.Fragment>

const addMethod = (method) => {
if (methodObjs.length) {
methodObjs.push(separator())
}
methodObjs.push(method)
}

let social
if (!methods || methods.social) {
social = tt('verify_way_tabs_jsx.social')
if (currentWay === 'social') {
social = <span key={curKey()}>{social}</span>
} else {
social = <Link key={curKey()} href={path}>{social}</Link>
}
addMethod(social)
}

let invite = tt('verify_way_tabs_jsx.invite_code')
if (currentWay === 'invite_code') {
invite = <span>{invite}</span>
} else {
invite = <Link href={path + '?invite'}>{invite}</Link>
let invite
if (!methods || methods.invite_code) {
invite = tt('verify_way_tabs_jsx.invite_code')
if (currentWay === 'invite_code') {
invite = <span key={curKey()}>{invite}</span>
} else {
invite = <Link key={curKey()} href={path + '?invite'}>{invite}</Link>
}
addMethod(invite)
}

let transfer = tt('verify_way_tabs_jsx.transfer')
if (currentWay === 'transfer') {
transfer = <span>{transfer}</span>
} else {
transfer = <Link href={path + '?transfer'}>{transfer}</Link>
let transfer
if (!methods || methods.transfer) {
transfer = tt('verify_way_tabs_jsx.transfer')
if (currentWay === 'transfer') {
transfer = <span key={curKey()}>{transfer}</span>
} else {
transfer = <Link key={curKey()} href={path + '?transfer'}>{transfer}</Link>
}
addMethod(transfer)
}

let uia = tt('verify_way_tabs_jsx.with_uia')
if (currentWay === 'uia') {
uia = <span>{uia}</span>
} else {
uia = <Link href={path + '?uia'}>{uia}</Link>
let uia
if (!methods || methods.uia) {
uia = tt('verify_way_tabs_jsx.with_uia')
if (currentWay === 'uia') {
uia = <span key={curKey()}>{uia}</span>
} else {
uia = <Link key={curKey()} href={path + '?uia'}>{uia}</Link>
}
addMethod(uia)
}

return <div style={{ marginBottom: '1.0rem' }}>
{social}
&nbsp;|&nbsp;
{invite}
&nbsp;|&nbsp;
{transfer}
&nbsp;|&nbsp;
{uia}
{methodObjs}
</div>
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
"zero": "0 free registrations remain.",
"one": "1 free registration remains.",
"other": "%(count)s free registrations remain."
}
},
"no_registration": "Registration closed."
},
"transfer_register_jsx": {
"please_send_transfer": "Please send at least ",
Expand Down
3 changes: 2 additions & 1 deletion src/locales/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
"zero": "0 бесплатных регистраций.",
"one": "1 бесплатная регистрация.",
"other": "%(count)s бесплатных регистраций."
}
},
"no_registration": "Регистрация закрыта."
},
"transfer_register_jsx": {
"please_send_transfer": "Пожалуйста, отправьте перевод не менее ",
Expand Down
2 changes: 1 addition & 1 deletion src/modules/register/TransferRegister.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class TransferRegister extends React.Component {
noValidate
method='post'
>
<VerifyWayTabs currentWay={'transfer'} />
<VerifyWayTabs clientCfg={this.props.clientCfg} currentWay={'transfer'} />
{this.renderStep1()}
{this.renderStep2()}
{this.renderStep3()}
Expand Down
4 changes: 3 additions & 1 deletion src/modules/register/UIARegister.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,9 @@ class UIARegister extends React.Component {
}

return <div className='UIARegister'>
<VerifyWayTabs currentWay={'uia'} />
<VerifyWayTabs
clientCfg={this.props.clientCfg}
currentWay={'uia'} />
{content}
</div>
}
Expand Down
35 changes: 28 additions & 7 deletions src/pages/register/[[...client]].jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@ class Register extends React.Component {
};

processQuery = () => {
const { clientCfg } = this.props
const methods = clientCfg.config.registrar.methods

const params = new URLSearchParams(window.location.search)
const invite = params.get('invite')
if (invite || params.has('invite')) {
if (!validate_account_name(invite)) {
console.log('Referrer account will be', invite);
if (this.state.referrer !== invite)
this.setState({referrer: invite});
} else {
} else if (!methods || methods.invite_code) {
const verificationWay = 'invite_code'
if (this.state.verificationWay !== verificationWay) {
this.setState({
Expand All @@ -87,24 +90,36 @@ class Register extends React.Component {
})
}
}
} else if (params.has('transfer')) {
} else if (params.has('transfer') && (!methods || methods.transfer)) {
const verificationWay = 'transfer'
if (this.state.verificationWay !== verificationWay)
this.setState({
verificationWay,
})
} else if (params.has('uia')) {
} else if (params.has('uia') && (!methods || methods.uia)) {
const verificationWay = 'uia'
if (this.state.verificationWay !== verificationWay)
this.setState({
verificationWay,
})
} else {
} else if (!methods || methods.social) {
const verificationWay = 'social'
if (!this.state.verificationWay.startsWith(verificationWay))
this.setState({
verificationWay,
})
} else if (methods) {
let verificationWay
const keys = Object.keys(methods).filter(k => methods[k])
if (keys[0]) {
verificationWay = keys[0]
} else {
verificationWay = 'no_registration'
}
if (!this.state.verificationWay.startsWith(verificationWay))
this.setState({
verificationWay,
})
}
}

Expand Down Expand Up @@ -336,7 +351,7 @@ class Register extends React.Component {
oauthEnabled,
} = state;

if (cryptographyFailure) {
if (cryptographyFailure ) {
return <CryptoFailure />
}

Expand Down Expand Up @@ -398,7 +413,9 @@ class Register extends React.Component {
const { dailyLimit } = this.props
if (dailyLimit.limit && dailyLimit.limit.exceed) {
form = <div>
<VerifyWayTabs currentWay='social' />
<VerifyWayTabs
clientCfg={this.props.clientCfg}
currentWay='social' />
<div className='callout alert'>
{tt('register_jsx.email_exceed')}
</div>
Expand All @@ -410,6 +427,8 @@ class Register extends React.Component {
afterRedirect={this.state.afterRedirect}
updateApiState={this.updateApiState}
/>
} else if (this.state.verificationWay === 'no_registration') {
form = <div>{tt('register_jsx.no_registration')}</div>
}

form = form || (<form
Expand All @@ -420,7 +439,9 @@ class Register extends React.Component {
>
{(showMailForm) && (
<div>
{showMailForm && <VerifyWayTabs currentWay={state.verificationWay} />}
{showMailForm && <VerifyWayTabs
clientCfg={this.props.clientCfg}
currentWay={state.verificationWay} />}
{isInviteWay && <div>
<label>
{this._renderInviteCodeField(true)}
Expand Down

0 comments on commit 0bc52a8

Please sign in to comment.