mirror of
https://gitlab.com/Alamantus/Readlebee.git
synced 2025-05-23 02:20:05 +02:00
Fix login errors and redirect to home after success
This commit is contained in:
parent
929d1ca928
commit
bcde0c6dc7
3 changed files with 30 additions and 6 deletions
|
@ -16,6 +16,7 @@ export class LoginController extends ViewController {
|
||||||
},
|
},
|
||||||
loginError: '',
|
loginError: '',
|
||||||
createError: '',
|
createError: '',
|
||||||
|
loginMessage: '',
|
||||||
createMessage: '',
|
createMessage: '',
|
||||||
pageMessage: '',
|
pageMessage: '',
|
||||||
isChecking: false,
|
isChecking: false,
|
||||||
|
@ -47,7 +48,7 @@ export class LoginController extends ViewController {
|
||||||
|
|
||||||
validateLogin () {
|
validateLogin () {
|
||||||
const { __ } = this.i18n;
|
const { __ } = this.i18n;
|
||||||
this.state.createError = '';
|
this.state.loginError = '';
|
||||||
this.state.isChecking = true;
|
this.state.isChecking = true;
|
||||||
|
|
||||||
this.emit('render', () => {
|
this.emit('render', () => {
|
||||||
|
@ -60,7 +61,7 @@ export class LoginController extends ViewController {
|
||||||
loginEmail,
|
loginEmail,
|
||||||
loginPassword,
|
loginPassword,
|
||||||
].includes('')) {
|
].includes('')) {
|
||||||
this.state.createError = __('login.create_required_field_blank');
|
this.state.loginError = __('login.login_required_field_blank');
|
||||||
this.state.isChecking = false;
|
this.state.isChecking = false;
|
||||||
this.emit('render');
|
this.emit('render');
|
||||||
return;
|
return;
|
||||||
|
@ -132,6 +133,7 @@ export class LoginController extends ViewController {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.appState.isLoggedIn = true;
|
||||||
this.state.loginMessage = __(response.message);
|
this.state.loginMessage = __(response.message);
|
||||||
this.state.isChecking = false;
|
this.state.isChecking = false;
|
||||||
this.clearLoginForm();
|
this.clearLoginForm();
|
||||||
|
|
|
@ -6,6 +6,28 @@ export const loginView = (state, emit, i18n) => {
|
||||||
const controller = new LoginController(state, emit, i18n);
|
const controller = new LoginController(state, emit, i18n);
|
||||||
const { __ } = controller.i18n;
|
const { __ } = controller.i18n;
|
||||||
|
|
||||||
|
if (controller.appState.isLoggedIn === true) {
|
||||||
|
setTimeout(() => {
|
||||||
|
controller.state.loginMessage = '';
|
||||||
|
emit('pushState', '/')
|
||||||
|
}, 3000);
|
||||||
|
|
||||||
|
return html`<div class="modal">
|
||||||
|
<input type="checkbox" checked>
|
||||||
|
<label class="overlay"></label>
|
||||||
|
|
||||||
|
<article class="success card">
|
||||||
|
<header>
|
||||||
|
${
|
||||||
|
controller.state.loginMessage === ''
|
||||||
|
? __('login.already_logged_in')
|
||||||
|
: controller.state.loginMessage
|
||||||
|
}
|
||||||
|
</header>
|
||||||
|
</article>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
return html`<section>
|
return html`<section>
|
||||||
|
|
||||||
${
|
${
|
||||||
|
|
|
@ -147,16 +147,16 @@ async function routes(fastify, options) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get('/api/account/login', async (request, reply) => {
|
fastify.post('/api/account/login', async (request, reply) => {
|
||||||
const formDataIsValid = Account.loginDataIsValid(request.body);
|
const formDataIsValid = Account.loginDataIsValid(request.body);
|
||||||
if (formDataIsValid !== true) {
|
if (formDataIsValid !== true) {
|
||||||
return reply.code(400).send(formDataIsValid);
|
return reply.code(400).send(formDataIsValid);
|
||||||
}
|
}
|
||||||
|
|
||||||
const account = new Account(fastify.models.User);
|
const account = new Account(fastify.models.User);
|
||||||
const user = account.validateLogin(request.body.email, request.body.password);
|
const user = await account.validateLogin(request.body.email, request.body.password);
|
||||||
|
|
||||||
if (user.error !== true) {
|
if (user.error === true) {
|
||||||
return reply.code(400).send(user);
|
return reply.code(400).send(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ async function routes(fastify, options) {
|
||||||
})
|
})
|
||||||
.send({
|
.send({
|
||||||
error: false,
|
error: false,
|
||||||
message: 'api.account_create_success',
|
message: 'api.account_login_success',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue