Fix login process: add permissionLevels
This commit is contained in:
parent
f12f8b987a
commit
e3b4809478
|
@ -13,6 +13,7 @@ export class LoginController extends ViewController {
|
||||||
createDisplayName: '',
|
createDisplayName: '',
|
||||||
createPassword: '',
|
createPassword: '',
|
||||||
createConfirm: '',
|
createConfirm: '',
|
||||||
|
createPermission: 100,
|
||||||
},
|
},
|
||||||
loginError: '',
|
loginError: '',
|
||||||
createError: '',
|
createError: '',
|
||||||
|
@ -146,7 +147,8 @@ export class LoginController extends ViewController {
|
||||||
createEmail,
|
createEmail,
|
||||||
createUsername,
|
createUsername,
|
||||||
createDisplayName,
|
createDisplayName,
|
||||||
createPassword
|
createPassword,
|
||||||
|
createPermission
|
||||||
} = this.state.fieldValues;
|
} = this.state.fieldValues;
|
||||||
|
|
||||||
fetch('/api/account/create', {
|
fetch('/api/account/create', {
|
||||||
|
@ -159,6 +161,7 @@ export class LoginController extends ViewController {
|
||||||
username: createUsername,
|
username: createUsername,
|
||||||
displayName: createDisplayName,
|
displayName: createDisplayName,
|
||||||
password: createPassword,
|
password: createPassword,
|
||||||
|
permissionLevel: createPermission,
|
||||||
}),
|
}),
|
||||||
}).then(response => response.json())
|
}).then(response => response.json())
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|
|
@ -127,6 +127,22 @@ export const loginView = (state, emit, i18n) => {
|
||||||
onkeyup=${e => { if (e.key === 'Enter') controller.validateCreateAccount() }}
|
onkeyup=${e => { if (e.key === 'Enter') controller.validateCreateAccount() }}
|
||||||
>
|
>
|
||||||
</label>
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>${__('login.permissions.label')}</span>
|
||||||
|
<select name="new_visibility"
|
||||||
|
onchange=${e => controller.state.fieldValues.createPermission = e.target.value.trim()}
|
||||||
|
>
|
||||||
|
<option value="100" ${controller.state.fieldValues.createPermission === 100 ? 'selected' : null}>
|
||||||
|
${__('login.permissions.public')}
|
||||||
|
</option>
|
||||||
|
<option value="33" ${controller.state.fieldValues.createPermission === 33 ? 'selected' : null}>
|
||||||
|
${__('login.permissions.following')}
|
||||||
|
</option>
|
||||||
|
<option value="0" ${controller.state.fieldValues.createPermission === 0 ? 'selected' : null}>
|
||||||
|
${__('login.permissions.private')}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
${
|
${
|
||||||
controller.state.createError === ''
|
controller.state.createError === ''
|
||||||
? null
|
? null
|
||||||
|
|
|
@ -27,6 +27,7 @@ class AccountController {
|
||||||
if (typeof createAccountData.email === 'undefined'
|
if (typeof createAccountData.email === 'undefined'
|
||||||
|| typeof createAccountData.username === 'undefined'
|
|| typeof createAccountData.username === 'undefined'
|
||||||
|| typeof createAccountData.password === 'undefined'
|
|| typeof createAccountData.password === 'undefined'
|
||||||
|
|| typeof createAccountData.permissionLevel === 'undefined'
|
||||||
|| createAccountData.password === '') {
|
|| createAccountData.password === '') {
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
|
@ -45,6 +46,12 @@ class AccountController {
|
||||||
message: 'api.account.create.invalid_username',
|
message: 'api.account.create.invalid_username',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (![100, 33, 0].includes(createAccountData.permissionLevel)) {
|
||||||
|
return {
|
||||||
|
error: true,
|
||||||
|
message: 'api.account.create.invalid_permissionLevel',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -75,6 +82,7 @@ class AccountController {
|
||||||
username: formData.username.toString().trim(),
|
username: formData.username.toString().trim(),
|
||||||
displayName: displayName.length > 0 ? displayName : 'A Bee',
|
displayName: displayName.length > 0 ? displayName : 'A Bee',
|
||||||
password: formData.password,
|
password: formData.password,
|
||||||
|
permissionLevel: formData.permissionLevel,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +138,7 @@ class AccountController {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createUser (email, username, displayName, password, needsConfirmation) {
|
async createUser (email, username, displayName, permissionLevel, password, needsConfirmation) {
|
||||||
const hashData = AccountController.hashPassword(password);
|
const hashData = AccountController.hashPassword(password);
|
||||||
// The data should already have gone through AccountController.cleanCreateAccountFormData()
|
// The data should already have gone through AccountController.cleanCreateAccountFormData()
|
||||||
try {
|
try {
|
||||||
|
@ -138,6 +146,7 @@ class AccountController {
|
||||||
email,
|
email,
|
||||||
username,
|
username,
|
||||||
displayName,
|
displayName,
|
||||||
|
permissionLevel,
|
||||||
passwordHash: hashData.hash,
|
passwordHash: hashData.hash,
|
||||||
passwordSalt: hashData.salt,
|
passwordSalt: hashData.salt,
|
||||||
accountConfirm: needsConfirmation ? crypto.randomBytes(32).toString('hex') : null,
|
accountConfirm: needsConfirmation ? crypto.randomBytes(32).toString('hex') : null,
|
||||||
|
|
|
@ -41,6 +41,12 @@
|
||||||
"confirm_password": "Confirm Password",
|
"confirm_password": "Confirm Password",
|
||||||
"username": "Username",
|
"username": "Username",
|
||||||
"display_name": "Display Name",
|
"display_name": "Display Name",
|
||||||
|
"permissions": {
|
||||||
|
"label": "Profile Visibility",
|
||||||
|
"public": "Public (anyone can see you)",
|
||||||
|
"following": "Following (only accounts you follow can see you)",
|
||||||
|
"private": "Private (nobody can see you)"
|
||||||
|
},
|
||||||
"create_account_button": "Create Account!",
|
"create_account_button": "Create Account!",
|
||||||
"login_required_field_blank": "You must enter both a valid email address and password.",
|
"login_required_field_blank": "You must enter both a valid email address and password.",
|
||||||
"create_required_field_blank": "You must complete all required fields.",
|
"create_required_field_blank": "You must complete all required fields.",
|
||||||
|
@ -93,7 +99,8 @@
|
||||||
"fail": "Something went wrong and the account could not be created. Please try again later.",
|
"fail": "Something went wrong and the account could not be created. Please try again later.",
|
||||||
"required_data_missing": "Could not create account because required data is missing.",
|
"required_data_missing": "Could not create account because required data is missing.",
|
||||||
"invalid_email": "The email address entered is not valid.",
|
"invalid_email": "The email address entered is not valid.",
|
||||||
"invalid_username": "The username entered is not valid. Usernames must be at least 2 characters long and can only contain letters a–z, numbers 0–9, and underscores",
|
"invalid_username": "The username entered is not valid. Usernames must be at least 2 characters long and can only contain letters a–z, numbers 0–9, and underscores.",
|
||||||
|
"invalid_permissionLevel": "The permissionLevel entered is not valid. PermissionLevel must be one 100, 33, or 0. Contact the front-end developer and ask them to fix their permission selector.",
|
||||||
"success": "Account created successfully! You may now log in using the email address and password you provided."
|
"success": "Account created successfully! You may now log in using the email address and password you provided."
|
||||||
},
|
},
|
||||||
"confirm": {
|
"confirm": {
|
||||||
|
|
|
@ -30,14 +30,14 @@ async function routes(fastify, options) {
|
||||||
return reply.code(400).send(canCreateUser);
|
return reply.code(400).send(canCreateUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
const newUser = await account.createUser(formData.email, formData.username, formData.displayName, formData.password, fastify.canEmail);
|
const newUser = await account.createUser(formData.email, formData.username, formData.displayName, formData.permissionLevel, formData.password, fastify.canEmail);
|
||||||
|
|
||||||
if (typeof newUser.error !== 'undefined' && newUser.error !== false) {
|
if (typeof newUser.error !== 'undefined' && newUser.error !== false) {
|
||||||
newUser.message = 'api.account.create.fail';
|
newUser.message = 'api.account.create.fail';
|
||||||
return reply.code(400).send(newUser);
|
return reply.code(400).send(newUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
const shelf = new ShelfController(fastify.models.Shelf, fastify.models.ShelfItem);
|
const shelf = new ShelfController(fastify.models, null);
|
||||||
const defaultShelvesCreated = await shelf.createDefaultShelves(newUser);
|
const defaultShelvesCreated = await shelf.createDefaultShelves(newUser);
|
||||||
|
|
||||||
// If some of the default shelves are not created successfully, delete the user and send an error
|
// If some of the default shelves are not created successfully, delete the user and send an error
|
||||||
|
|
Loading…
Reference in New Issue