2019-01-21 14:08:22 +00:00
|
|
|
|
<template>
|
2019-04-03 15:29:03 +00:00
|
|
|
|
<div class="container">
|
2019-04-01 09:49:54 +00:00
|
|
|
|
<b-message v-if="errorCode === LoginErrorCode.NEED_TO_LOGIN" title="Info" type="is-info">
|
2019-09-12 09:34:01 +00:00
|
|
|
|
{{ $t('You need to login.') }}
|
2019-04-01 09:49:54 +00:00
|
|
|
|
</b-message>
|
|
|
|
|
<section v-if="!currentUser.isLoggedIn">
|
2019-01-21 14:08:22 +00:00
|
|
|
|
<div class="columns is-mobile is-centered">
|
2019-10-10 12:20:09 +00:00
|
|
|
|
<div class="column is-half-desktop">
|
|
|
|
|
<h1 class="title">
|
|
|
|
|
{{ $t('Welcome back!') }}
|
|
|
|
|
</h1>
|
2019-10-15 16:13:05 +00:00
|
|
|
|
<b-message title="Error" type="is-danger" v-for="error in errors" :key="error">
|
|
|
|
|
<span v-if="error === LoginError.USER_NOT_CONFIRMED">
|
|
|
|
|
<span>{{ $t("The user account you're trying to login as has not been confirmed yet. Check your email inbox and eventually your spam folder.") }}</span>
|
|
|
|
|
<i18n path="You may also ask to {resend_confirmation_email}.">
|
|
|
|
|
<router-link slot="resend_confirmation_email" :to="{ name: RouteName.RESEND_CONFIRMATION }">{{ $t('resend confirmation email') }}</router-link>
|
|
|
|
|
</i18n>
|
|
|
|
|
</span>
|
|
|
|
|
<span v-if="error === LoginError.USER_EMAIL_PASSWORD_INVALID">
|
|
|
|
|
{{ $t('Impossible to login, your email or password seems incorrect.') }}
|
|
|
|
|
</span>
|
|
|
|
|
<!-- TODO: Shouldn't we hide this information ? -->
|
|
|
|
|
<span v-if="error === LoginError.USER_DOES_NOT_EXIST">
|
|
|
|
|
{{ $t('No user account with this email was found. Maybe you made a typo?') }}
|
2019-10-17 13:07:41 +00:00
|
|
|
|
</span>
|
|
|
|
|
<!-- Warning that we delete everything every now and then -->
|
2019-11-21 15:07:43 +00:00
|
|
|
|
<span v-if="error === LoginError.USER_DOES_NOT_EXIST && config.demoMode">
|
2019-10-17 13:07:41 +00:00
|
|
|
|
{{ $t('User accounts and every other data is currently deleted every 48 hours, so you may want to register again.') }}
|
2019-10-15 16:13:05 +00:00
|
|
|
|
</span>
|
|
|
|
|
</b-message>
|
2019-01-21 14:08:22 +00:00
|
|
|
|
<form @submit="loginAction">
|
2019-09-12 09:34:01 +00:00
|
|
|
|
<b-field :label="$t('Email')">
|
2019-01-21 14:08:22 +00:00
|
|
|
|
<b-input aria-required="true" required type="email" v-model="credentials.email"/>
|
|
|
|
|
</b-field>
|
|
|
|
|
|
2019-09-12 09:34:01 +00:00
|
|
|
|
<b-field :label="$t('Password')">
|
2019-01-21 14:08:22 +00:00
|
|
|
|
<b-input
|
|
|
|
|
aria-required="true"
|
|
|
|
|
required
|
|
|
|
|
type="password"
|
|
|
|
|
password-reveal
|
|
|
|
|
v-model="credentials.password"
|
|
|
|
|
/>
|
|
|
|
|
</b-field>
|
|
|
|
|
|
2019-10-10 12:20:09 +00:00
|
|
|
|
<p class="control has-text-centered">
|
2019-01-21 14:08:22 +00:00
|
|
|
|
<button class="button is-primary is-large">
|
2019-09-12 09:34:01 +00:00
|
|
|
|
{{ $t('Login') }}
|
2019-01-21 14:08:22 +00:00
|
|
|
|
</button>
|
2019-10-10 12:20:09 +00:00
|
|
|
|
</p>
|
|
|
|
|
<p class="control">
|
2019-01-21 14:08:22 +00:00
|
|
|
|
<router-link
|
|
|
|
|
class="button is-text"
|
2019-10-03 10:32:20 +00:00
|
|
|
|
:to="{ name: RouteName.SEND_PASSWORD_RESET, params: { email: credentials.email }}"
|
2019-01-21 14:08:22 +00:00
|
|
|
|
>
|
2019-09-12 09:34:01 +00:00
|
|
|
|
{{ $t('Forgot your password ?') }}
|
2019-01-21 14:08:22 +00:00
|
|
|
|
</router-link>
|
2019-10-10 12:20:09 +00:00
|
|
|
|
</p>
|
|
|
|
|
<p class="control" v-if="config && config.registrationsOpen">
|
2019-01-21 14:08:22 +00:00
|
|
|
|
<router-link
|
|
|
|
|
class="button is-text"
|
2019-10-03 10:32:20 +00:00
|
|
|
|
:to="{ name: RouteName.REGISTER, params: { default_email: credentials.email, default_password: credentials.password }}"
|
2019-01-21 14:08:22 +00:00
|
|
|
|
>
|
2019-09-12 09:34:01 +00:00
|
|
|
|
{{ $t('Register') }}
|
2019-01-21 14:08:22 +00:00
|
|
|
|
</router-link>
|
2019-10-10 12:20:09 +00:00
|
|
|
|
</p>
|
2019-01-21 14:08:22 +00:00
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
2019-04-01 09:49:54 +00:00
|
|
|
|
|
|
|
|
|
<b-message v-else title="Error" type="is-error">
|
2019-09-12 09:34:01 +00:00
|
|
|
|
{{ $t('You are already logged-in.') }}
|
2019-04-01 09:49:54 +00:00
|
|
|
|
</b-message>
|
2019-01-21 14:08:22 +00:00
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
2019-03-22 09:57:14 +00:00
|
|
|
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
|
|
|
|
import { LOGIN } from '@/graphql/auth';
|
|
|
|
|
import { validateEmailField, validateRequiredField } from '@/utils/validators';
|
2019-10-12 11:16:36 +00:00
|
|
|
|
import { initializeCurrentActor, NoIdentitiesException, saveUserData } from '@/utils/auth';
|
2019-03-22 09:57:14 +00:00
|
|
|
|
import { ILogin } from '@/types/login.model';
|
2019-04-01 09:49:54 +00:00
|
|
|
|
import { CURRENT_USER_CLIENT, UPDATE_CURRENT_USER_CLIENT } from '@/graphql/user';
|
2019-03-22 09:57:14 +00:00
|
|
|
|
import { onLogin } from '@/vue-apollo';
|
|
|
|
|
import { RouteName } from '@/router';
|
2019-10-15 16:13:05 +00:00
|
|
|
|
import { LoginErrorCode, LoginError } from '@/types/login-error-code.model';
|
2019-04-03 15:29:03 +00:00
|
|
|
|
import { ICurrentUser } from '@/types/current-user.model';
|
|
|
|
|
import { CONFIG } from '@/graphql/config';
|
|
|
|
|
import { IConfig } from '@/types/config.model';
|
2019-01-21 14:08:22 +00:00
|
|
|
|
|
2019-03-22 12:58:19 +00:00
|
|
|
|
@Component({
|
|
|
|
|
apollo: {
|
|
|
|
|
config: {
|
2019-04-03 15:29:03 +00:00
|
|
|
|
query: CONFIG,
|
2019-04-01 09:49:54 +00:00
|
|
|
|
},
|
|
|
|
|
currentUser: {
|
2019-04-03 15:29:03 +00:00
|
|
|
|
query: CURRENT_USER_CLIENT,
|
|
|
|
|
},
|
2019-10-10 14:47:38 +00:00
|
|
|
|
},
|
|
|
|
|
metaInfo() {
|
|
|
|
|
return {
|
|
|
|
|
// if no subcomponents specify a metaInfo.title, this title will be used
|
|
|
|
|
title: this.$t('Login on Mobilizon!') as string,
|
|
|
|
|
// all titles will be injected into this template
|
|
|
|
|
titleTemplate: '%s | Mobilizon',
|
|
|
|
|
};
|
2019-04-03 15:29:03 +00:00
|
|
|
|
},
|
2019-03-22 12:58:19 +00:00
|
|
|
|
})
|
2019-01-21 14:08:22 +00:00
|
|
|
|
export default class Login extends Vue {
|
2019-03-22 09:57:14 +00:00
|
|
|
|
@Prop({ type: String, required: false, default: '' }) email!: string;
|
|
|
|
|
@Prop({ type: String, required: false, default: '' }) password!: string;
|
2019-01-21 14:08:22 +00:00
|
|
|
|
|
2019-04-01 09:49:54 +00:00
|
|
|
|
LoginErrorCode = LoginErrorCode;
|
2019-10-15 16:13:05 +00:00
|
|
|
|
LoginError = LoginError;
|
2019-04-01 09:49:54 +00:00
|
|
|
|
|
|
|
|
|
errorCode: LoginErrorCode | null = null;
|
2019-03-22 12:58:19 +00:00
|
|
|
|
config!: IConfig;
|
2019-04-01 09:49:54 +00:00
|
|
|
|
currentUser!: ICurrentUser;
|
|
|
|
|
|
2019-10-03 10:32:20 +00:00
|
|
|
|
RouteName = RouteName;
|
|
|
|
|
|
2019-01-21 14:08:22 +00:00
|
|
|
|
credentials = {
|
2019-03-22 09:57:14 +00:00
|
|
|
|
email: '',
|
|
|
|
|
password: '',
|
2019-01-21 14:08:22 +00:00
|
|
|
|
};
|
2019-04-01 09:49:54 +00:00
|
|
|
|
|
2019-01-21 14:08:22 +00:00
|
|
|
|
errors: string[] = [];
|
|
|
|
|
rules = {
|
|
|
|
|
required: validateRequiredField,
|
2019-03-22 09:57:14 +00:00
|
|
|
|
email: validateEmailField,
|
2019-01-21 14:08:22 +00:00
|
|
|
|
};
|
|
|
|
|
|
2019-04-01 09:49:54 +00:00
|
|
|
|
private redirect: string | null = null;
|
2019-01-21 14:08:22 +00:00
|
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
|
this.credentials.email = this.email;
|
|
|
|
|
this.credentials.password = this.password;
|
2019-04-01 09:49:54 +00:00
|
|
|
|
|
2019-04-03 15:29:03 +00:00
|
|
|
|
const query = this.$route.query;
|
|
|
|
|
this.errorCode = query['code'] as LoginErrorCode;
|
|
|
|
|
this.redirect = query['redirect'] as string;
|
2019-01-21 14:08:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async loginAction(e: Event) {
|
|
|
|
|
e.preventDefault();
|
2019-04-01 09:49:54 +00:00
|
|
|
|
|
|
|
|
|
this.errors = [];
|
2019-01-21 14:08:22 +00:00
|
|
|
|
|
|
|
|
|
try {
|
2019-09-02 16:52:23 +00:00
|
|
|
|
const { data } = await this.$apollo.mutate<{ login: ILogin }>({
|
2019-01-21 14:08:22 +00:00
|
|
|
|
mutation: LOGIN,
|
|
|
|
|
variables: {
|
|
|
|
|
email: this.credentials.email,
|
2019-03-22 09:57:14 +00:00
|
|
|
|
password: this.credentials.password,
|
|
|
|
|
},
|
2019-01-21 14:08:22 +00:00
|
|
|
|
});
|
2019-09-02 16:52:23 +00:00
|
|
|
|
if (data == null) {
|
|
|
|
|
throw new Error('Data is undefined');
|
|
|
|
|
}
|
2019-01-21 14:08:22 +00:00
|
|
|
|
|
2019-09-02 16:52:23 +00:00
|
|
|
|
saveUserData(data.login);
|
2019-01-21 14:08:22 +00:00
|
|
|
|
|
|
|
|
|
await this.$apollo.mutate({
|
|
|
|
|
mutation: UPDATE_CURRENT_USER_CLIENT,
|
|
|
|
|
variables: {
|
2019-09-02 16:52:23 +00:00
|
|
|
|
id: data.login.user.id,
|
2019-03-22 09:57:14 +00:00
|
|
|
|
email: this.credentials.email,
|
2019-04-01 09:49:54 +00:00
|
|
|
|
isLoggedIn: true,
|
2019-09-09 07:31:08 +00:00
|
|
|
|
role: data.login.user.role,
|
2019-03-22 09:57:14 +00:00
|
|
|
|
},
|
2019-01-21 14:08:22 +00:00
|
|
|
|
});
|
2019-10-12 11:16:36 +00:00
|
|
|
|
try {
|
|
|
|
|
await initializeCurrentActor(this.$apollo.provider.defaultClient);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (e instanceof NoIdentitiesException) {
|
|
|
|
|
return await this.$router.push({
|
|
|
|
|
name: RouteName.REGISTER_PROFILE,
|
|
|
|
|
params: { email: this.currentUser.email, userAlreadyActivated: 'true' },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-21 14:08:22 +00:00
|
|
|
|
|
|
|
|
|
onLogin(this.$apollo);
|
|
|
|
|
|
2019-04-01 09:49:54 +00:00
|
|
|
|
if (this.redirect) {
|
2019-08-21 09:25:09 +00:00
|
|
|
|
await this.$router.push(this.redirect);
|
2019-04-01 09:49:54 +00:00
|
|
|
|
} else {
|
2019-10-14 12:25:08 +00:00
|
|
|
|
window.localStorage.setItem('welcome-back', 'yes');
|
2019-08-21 09:25:09 +00:00
|
|
|
|
await this.$router.push({ name: RouteName.HOME });
|
2019-04-01 09:49:54 +00:00
|
|
|
|
}
|
2019-01-21 14:08:22 +00:00
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
err.graphQLErrors.forEach(({ message }) => {
|
|
|
|
|
this.errors.push(message);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
2019-10-10 12:20:09 +00:00
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.container .columns {
|
|
|
|
|
margin: 1rem auto 3rem;
|
|
|
|
|
}
|
2019-11-21 15:07:43 +00:00
|
|
|
|
</style>
|