Added signup page.
This commit is contained in:
14
src/auth.js
14
src/auth.js
@@ -41,7 +41,10 @@ export async function login(credentials) {
|
||||
throw new HttpError('Authentication is disabled', 405);
|
||||
}
|
||||
|
||||
const user = await fetchUser(credentials.username.trim(), true);
|
||||
const user = await fetchUser(credentials.username.trim(), {
|
||||
email: true,
|
||||
raw: true,
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new HttpError('Username or password incorrect', 401);
|
||||
@@ -92,8 +95,8 @@ export async function signup(credentials) {
|
||||
}
|
||||
|
||||
const existingUser = await knex('users')
|
||||
.where('username', curatedUsername)
|
||||
.orWhere('email', credentials.email)
|
||||
.where(knex.raw('lower(username)'), curatedUsername.toLowerCase())
|
||||
.orWhere(knex.raw('lower(email)'), credentials.email.toLowerCase())
|
||||
.first();
|
||||
|
||||
if (existingUser) {
|
||||
@@ -120,5 +123,10 @@ export async function signup(credentials) {
|
||||
primary: true,
|
||||
});
|
||||
|
||||
await generateAvatar({
|
||||
id: userId,
|
||||
username: curatedUsername,
|
||||
});
|
||||
|
||||
return fetchUser(userId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user