fix: replace client and username with email
fix: error handling in lamassu-register
This commit is contained in:
parent
5ff676553e
commit
4a630f0f53
4 changed files with 30 additions and 23 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
const { asyncLocalStorage, defaultStore } = require('../lib/async-storage')
|
const { asyncLocalStorage, defaultStore } = require('../lib/async-storage')
|
||||||
const userManagement = require('../lib/new-admin/graphql/modules/userManagement')
|
const userManagement = require('../lib/new-admin/graphql/modules/userManagement')
|
||||||
|
const authErrors = require('../lib/new-admin/graphql/errors/authentication')
|
||||||
const options = require('../lib/options')
|
const options = require('../lib/options')
|
||||||
|
|
||||||
const name = process.argv[2]
|
const name = process.argv[2]
|
||||||
|
|
@ -14,29 +15,25 @@ if (!domain) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!name || !role) {
|
if (!name || !role) {
|
||||||
console.log('Usage: lamassu-register <username> <role>')
|
console.log('Usage: lamassu-register <email> <role>')
|
||||||
|
console.log('<role> must be \'user\' or \'superuser\'')
|
||||||
process.exit(2)
|
process.exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
const emailRegex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
const emailRegex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
||||||
|
|
||||||
if (!emailRegex.test(name)) {
|
if (!emailRegex.test(name)) {
|
||||||
console.log('Usage: <name> should be in an email format')
|
console.log('Usage: <email> must be in an email format')
|
||||||
process.exit(2)
|
process.exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role !== 'user' && role !== 'superuser') {
|
if (role !== 'user' && role !== 'superuser') {
|
||||||
console.log('Usage: <role> has two possible values: user | superuser')
|
console.log('Usage: <role> must be \'user\' or \'superuser\'')
|
||||||
process.exit(2)
|
process.exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
asyncLocalStorage.run(defaultStore(), () => {
|
asyncLocalStorage.run(defaultStore(), () => {
|
||||||
userManagement.createRegisterToken(name, role).then(token => {
|
userManagement.createRegisterToken(name, role).then(token => {
|
||||||
if (!token) {
|
|
||||||
console.log(`A user named ${name} already exists!`)
|
|
||||||
process.exit(2)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (domain === 'localhost') {
|
if (domain === 'localhost') {
|
||||||
console.log(`https://${domain}:3001/register?t=${token.token}`)
|
console.log(`https://${domain}:3001/register?t=${token.token}`)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -45,6 +42,12 @@ asyncLocalStorage.run(defaultStore(), () => {
|
||||||
|
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
|
|
||||||
|
if (err instanceof authErrors.UserAlreadyExistsError){
|
||||||
|
console.log(`A user with email ${name} already exists!`)
|
||||||
|
process.exit(2)
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Error: %s', err)
|
console.log('Error: %s', err)
|
||||||
process.exit(3)
|
process.exit(3)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -46,23 +46,24 @@ const GET_USER_DATA = gql`
|
||||||
`
|
`
|
||||||
|
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = Yup.object().shape({
|
||||||
client: Yup.string()
|
email: Yup.string()
|
||||||
.required('Client field is required!')
|
.label('Email')
|
||||||
.email('Username field should be in an email format!'),
|
.required()
|
||||||
|
.email(),
|
||||||
password: Yup.string().required('Password field is required'),
|
password: Yup.string().required('Password field is required'),
|
||||||
rememberMe: Yup.boolean()
|
rememberMe: Yup.boolean()
|
||||||
})
|
})
|
||||||
|
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
client: '',
|
email: '',
|
||||||
password: '',
|
password: '',
|
||||||
rememberMe: false
|
rememberMe: false
|
||||||
}
|
}
|
||||||
|
|
||||||
const getErrorMsg = (formikErrors, formikTouched, mutationError) => {
|
const getErrorMsg = (formikErrors, formikTouched, mutationError) => {
|
||||||
if (!formikErrors || !formikTouched) return null
|
if (!formikErrors || !formikTouched) return null
|
||||||
if (mutationError) return 'Invalid login/password combination'
|
if (mutationError) return 'Invalid email/password combination'
|
||||||
if (formikErrors.client && formikTouched.client) return formikErrors.client
|
if (formikErrors.email && formikTouched.email) return formikErrors.email
|
||||||
if (formikErrors.password && formikTouched.password)
|
if (formikErrors.password && formikTouched.password)
|
||||||
return formikErrors.password
|
return formikErrors.password
|
||||||
return null
|
return null
|
||||||
|
|
@ -142,13 +143,13 @@ const LoginState = ({ state, dispatch, strategy }) => {
|
||||||
validationSchema={validationSchema}
|
validationSchema={validationSchema}
|
||||||
initialValues={initialValues}
|
initialValues={initialValues}
|
||||||
onSubmit={values =>
|
onSubmit={values =>
|
||||||
submitLogin(values.client, values.password, values.rememberMe)
|
submitLogin(values.email, values.password, values.rememberMe)
|
||||||
}>
|
}>
|
||||||
{({ errors, touched }) => (
|
{({ errors, touched }) => (
|
||||||
<Form id="login-form">
|
<Form id="login-form">
|
||||||
<Field
|
<Field
|
||||||
name="client"
|
name="email"
|
||||||
label="Client"
|
label="Email"
|
||||||
size="lg"
|
size="lg"
|
||||||
component={TextInput}
|
component={TextInput}
|
||||||
fullWidth
|
fullWidth
|
||||||
|
|
|
||||||
|
|
@ -210,6 +210,10 @@ const Register = () => {
|
||||||
{!loading && state.result === 'failure' && (
|
{!loading && state.result === 'failure' && (
|
||||||
<>
|
<>
|
||||||
<Label3>Link has expired</Label3>
|
<Label3>Link has expired</Label3>
|
||||||
|
<Label3>
|
||||||
|
To obtain a new link, run the command{' '}
|
||||||
|
<strong>lamassu-register</strong> in your server’s terminal.
|
||||||
|
</Label3>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -140,14 +140,13 @@ const Setup2FAState = ({ state, dispatch }) => {
|
||||||
<>
|
<>
|
||||||
<div className={classes.infoWrapper}>
|
<div className={classes.infoWrapper}>
|
||||||
<Label3 className={classes.info2}>
|
<Label3 className={classes.info2}>
|
||||||
We detected that this account does not have its two-factor
|
This account does not yet have two-factor authentication enabled. To
|
||||||
authentication enabled. In order to protect the resources in the
|
secure the admin, two-factor authentication is required.
|
||||||
system, a two-factor authentication is enforced.
|
|
||||||
</Label3>
|
</Label3>
|
||||||
<Label3 className={classes.info2}>
|
<Label3 className={classes.info2}>
|
||||||
To finish this process, please scan the following QR code or insert
|
To complete the registration process, scan the following QR code or
|
||||||
the secret further below on an authentication app of your choice,
|
insert the secret below on a 2FA app, such as Google Authenticator
|
||||||
such as Google Authenticator or Authy.
|
or AndOTP.
|
||||||
</Label3>
|
</Label3>
|
||||||
</div>
|
</div>
|
||||||
<div className={classes.qrCodeWrapper}>
|
<div className={classes.qrCodeWrapper}>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue