Fix login errors and redirect to home after success
This commit is contained in:
parent
929d1ca928
commit
bcde0c6dc7
|
@ -16,6 +16,7 @@ export class LoginController extends ViewController {
|
|||
},
|
||||
loginError: '',
|
||||
createError: '',
|
||||
loginMessage: '',
|
||||
createMessage: '',
|
||||
pageMessage: '',
|
||||
isChecking: false,
|
||||
|
@ -47,7 +48,7 @@ export class LoginController extends ViewController {
|
|||
|
||||
validateLogin () {
|
||||
const { __ } = this.i18n;
|
||||
this.state.createError = '';
|
||||
this.state.loginError = '';
|
||||
this.state.isChecking = true;
|
||||
|
||||
this.emit('render', () => {
|
||||
|
@ -60,7 +61,7 @@ export class LoginController extends ViewController {
|
|||
loginEmail,
|
||||
loginPassword,
|
||||
].includes('')) {
|
||||
this.state.createError = __('login.create_required_field_blank');
|
||||
this.state.loginError = __('login.login_required_field_blank');
|
||||
this.state.isChecking = false;
|
||||
this.emit('render');
|
||||
return;
|
||||
|
@ -132,6 +133,7 @@ export class LoginController extends ViewController {
|
|||
return;
|
||||
}
|
||||
|
||||
this.appState.isLoggedIn = true;
|
||||
this.state.loginMessage = __(response.message);
|
||||
this.state.isChecking = false;
|
||||
this.clearLoginForm();
|
||||
|
|
|
@ -6,6 +6,28 @@ export const loginView = (state, emit, i18n) => {
|
|||
const controller = new LoginController(state, emit, 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>
|
||||
|
||||
${
|
||||
|
|
|
@ -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);
|
||||
if (formDataIsValid !== true) {
|
||||
return reply.code(400).send(formDataIsValid);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ async function routes(fastify, options) {
|
|||
})
|
||||
.send({
|
||||
error: false,
|
||||
message: 'api.account_create_success',
|
||||
message: 'api.account_login_success',
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue