2019-01-21 15:08:22 +01:00
|
|
|
<template>
|
2019-12-20 13:04:34 +01:00
|
|
|
<section class="section container" v-if="!currentUser.isLoggedIn">
|
|
|
|
<div class="columns is-mobile is-centered">
|
|
|
|
<div class="column is-half-desktop">
|
2020-02-18 08:57:00 +01:00
|
|
|
<h1 class="title">{{ $t("Welcome back!") }}</h1>
|
|
|
|
<b-message
|
|
|
|
v-if="errorCode === LoginErrorCode.NEED_TO_LOGIN"
|
|
|
|
title="Info"
|
|
|
|
type="is-info"
|
|
|
|
:aria-close-label="$t('Close')"
|
|
|
|
>{{ $t("You need to login.") }}</b-message
|
|
|
|
>
|
2020-06-27 19:12:45 +02:00
|
|
|
<b-message
|
|
|
|
v-else-if="errorCode === LoginError.LOGIN_PROVIDER_ERROR"
|
|
|
|
type="is-danger"
|
|
|
|
:aria-close-label="$t('Close')"
|
|
|
|
>{{
|
|
|
|
$t("Error while login with {provider}. Retry or login another way.", {
|
|
|
|
provider: $route.query.provider,
|
|
|
|
})
|
|
|
|
}}</b-message
|
|
|
|
>
|
|
|
|
<b-message
|
|
|
|
v-else-if="errorCode === LoginError.LOGIN_PROVIDER_NOT_FOUND"
|
|
|
|
type="is-danger"
|
|
|
|
:aria-close-label="$t('Close')"
|
|
|
|
>{{
|
|
|
|
$t("Error while login with {provider}. This login provider doesn't exist.", {
|
|
|
|
provider: $route.query.provider,
|
|
|
|
})
|
|
|
|
}}</b-message
|
|
|
|
>
|
2019-12-20 13:04:34 +01:00
|
|
|
<b-message title="Error" type="is-danger" v-for="error in errors" :key="error">
|
|
|
|
<span v-if="error === LoginError.USER_NOT_CONFIRMED">
|
2020-02-18 08:57:00 +01:00
|
|
|
<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>
|
2019-12-20 13:04:34 +01:00
|
|
|
<i18n path="You may also ask to {resend_confirmation_email}.">
|
2020-02-18 08:57:00 +01:00
|
|
|
<router-link
|
|
|
|
slot="resend_confirmation_email"
|
|
|
|
:to="{ name: RouteName.RESEND_CONFIRMATION }"
|
|
|
|
>{{ $t("resend confirmation email") }}</router-link
|
|
|
|
>
|
2019-12-20 13:04:34 +01:00
|
|
|
</i18n>
|
|
|
|
</span>
|
2020-02-18 08:57:00 +01:00
|
|
|
<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?")
|
|
|
|
}}</span>
|
2020-07-06 17:33:40 +02:00
|
|
|
<span v-if="error === LoginError.USER_DISABLED">
|
|
|
|
{{ $t("This user has been disabled") }}
|
|
|
|
</span>
|
2019-12-20 13:04:34 +01:00
|
|
|
</b-message>
|
|
|
|
<form @submit="loginAction">
|
2020-02-18 08:57:00 +01:00
|
|
|
<b-field :label="$t('Email')" label-for="email">
|
|
|
|
<b-input
|
|
|
|
aria-required="true"
|
|
|
|
required
|
|
|
|
id="email"
|
|
|
|
type="email"
|
|
|
|
v-model="credentials.email"
|
|
|
|
/>
|
2019-12-20 13:04:34 +01:00
|
|
|
</b-field>
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
<b-field :label="$t('Password')" label-for="password">
|
2019-12-20 13:04:34 +01:00
|
|
|
<b-input
|
|
|
|
aria-required="true"
|
2020-02-18 08:57:00 +01:00
|
|
|
id="password"
|
2019-12-20 13:04:34 +01:00
|
|
|
required
|
|
|
|
type="password"
|
|
|
|
password-reveal
|
|
|
|
v-model="credentials.password"
|
|
|
|
/>
|
|
|
|
</b-field>
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-12-20 13:04:34 +01:00
|
|
|
<p class="control has-text-centered">
|
2020-02-18 08:57:00 +01:00
|
|
|
<button class="button is-primary is-large">{{ $t("Login") }}</button>
|
2019-12-20 13:04:34 +01:00
|
|
|
</p>
|
2020-06-27 19:12:45 +02:00
|
|
|
|
|
|
|
<div class="control" v-if="config && config.auth.oauthProviders.length > 0">
|
|
|
|
<auth-providers :oauthProviders="config.auth.oauthProviders" />
|
|
|
|
</div>
|
|
|
|
|
2019-12-20 13:04:34 +01:00
|
|
|
<p class="control">
|
|
|
|
<router-link
|
|
|
|
class="button is-text"
|
2020-02-18 08:57:00 +01:00
|
|
|
:to="{ name: RouteName.SEND_PASSWORD_RESET, params: { email: credentials.email } }"
|
|
|
|
>{{ $t("Forgot your password ?") }}</router-link
|
2019-12-20 13:04:34 +01:00
|
|
|
>
|
|
|
|
</p>
|
2020-06-18 16:01:14 +02:00
|
|
|
<router-link
|
|
|
|
class="button is-text"
|
|
|
|
:to="{ name: RouteName.RESEND_CONFIRMATION, params: { email: credentials.email } }"
|
|
|
|
>{{ $t("Didn't receive the instructions ?") }}</router-link
|
|
|
|
>
|
2019-12-20 13:04:34 +01:00
|
|
|
<p class="control" v-if="config && config.registrationsOpen">
|
|
|
|
<router-link
|
|
|
|
class="button is-text"
|
2020-02-18 08:57:00 +01:00
|
|
|
:to="{
|
|
|
|
name: RouteName.REGISTER,
|
|
|
|
params: {
|
|
|
|
default_email: credentials.email,
|
|
|
|
default_password: credentials.password,
|
|
|
|
},
|
|
|
|
}"
|
|
|
|
>{{ $t("Register") }}</router-link
|
2019-12-20 13:04:34 +01:00
|
|
|
>
|
|
|
|
</p>
|
|
|
|
</form>
|
2019-01-21 15:08:22 +01:00
|
|
|
</div>
|
2019-12-20 13:04:34 +01:00
|
|
|
</div>
|
|
|
|
</section>
|
2019-01-21 15:08:22 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-02-18 08:57:00 +01:00
|
|
|
import { Component, Prop, Vue } from "vue-property-decorator";
|
|
|
|
import { LOGIN } from "../../graphql/auth";
|
|
|
|
import { validateEmailField, validateRequiredField } from "../../utils/validators";
|
|
|
|
import { initializeCurrentActor, NoIdentitiesException, saveUserData } from "../../utils/auth";
|
|
|
|
import { ILogin } from "../../types/login.model";
|
|
|
|
import { CURRENT_USER_CLIENT, UPDATE_CURRENT_USER_CLIENT } from "../../graphql/user";
|
|
|
|
import RouteName from "../../router/name";
|
|
|
|
import { LoginErrorCode, LoginError } from "../../types/login-error-code.model";
|
|
|
|
import { ICurrentUser } from "../../types/current-user.model";
|
|
|
|
import { CONFIG } from "../../graphql/config";
|
|
|
|
import { IConfig } from "../../types/config.model";
|
2020-06-27 19:12:45 +02:00
|
|
|
import AuthProviders from "../../components/User/AuthProviders.vue";
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-03-22 13:58:19 +01:00
|
|
|
@Component({
|
|
|
|
apollo: {
|
|
|
|
config: {
|
2019-04-03 17:29:03 +02:00
|
|
|
query: CONFIG,
|
2019-04-01 11:49:54 +02:00
|
|
|
},
|
|
|
|
currentUser: {
|
2019-04-03 17:29:03 +02:00
|
|
|
query: CURRENT_USER_CLIENT,
|
|
|
|
},
|
2019-10-10 16:47:38 +02:00
|
|
|
},
|
2020-06-27 19:12:45 +02:00
|
|
|
components: {
|
|
|
|
AuthProviders,
|
|
|
|
},
|
2019-10-10 16:47:38 +02:00
|
|
|
metaInfo() {
|
|
|
|
return {
|
|
|
|
// if no subcomponents specify a metaInfo.title, this title will be used
|
2020-02-18 08:57:00 +01:00
|
|
|
title: this.$t("Login on Mobilizon!") as string,
|
2019-10-10 16:47:38 +02:00
|
|
|
// all titles will be injected into this template
|
2020-02-18 08:57:00 +01:00
|
|
|
titleTemplate: "%s | Mobilizon",
|
2019-10-10 16:47:38 +02:00
|
|
|
};
|
2019-04-03 17:29:03 +02:00
|
|
|
},
|
2019-03-22 13:58:19 +01:00
|
|
|
})
|
2019-01-21 15:08:22 +01:00
|
|
|
export default class Login extends Vue {
|
2020-02-18 08:57:00 +01:00
|
|
|
@Prop({ type: String, required: false, default: "" }) email!: string;
|
|
|
|
|
|
|
|
@Prop({ type: String, required: false, default: "" }) password!: string;
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-04-01 11:49:54 +02:00
|
|
|
LoginErrorCode = LoginErrorCode;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-10-15 18:13:05 +02:00
|
|
|
LoginError = LoginError;
|
2019-04-01 11:49:54 +02:00
|
|
|
|
|
|
|
errorCode: LoginErrorCode | null = null;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-03-22 13:58:19 +01:00
|
|
|
config!: IConfig;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-04-01 11:49:54 +02:00
|
|
|
currentUser!: ICurrentUser;
|
|
|
|
|
2019-10-03 12:32:20 +02:00
|
|
|
RouteName = RouteName;
|
|
|
|
|
2019-01-21 15:08:22 +01:00
|
|
|
credentials = {
|
2020-02-18 08:57:00 +01:00
|
|
|
email: "",
|
|
|
|
password: "",
|
2019-01-21 15:08:22 +01:00
|
|
|
};
|
2019-04-01 11:49:54 +02:00
|
|
|
|
2019-01-21 15:08:22 +01:00
|
|
|
errors: string[] = [];
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-01-21 15:08:22 +01:00
|
|
|
rules = {
|
|
|
|
required: validateRequiredField,
|
2019-03-22 10:57:14 +01:00
|
|
|
email: validateEmailField,
|
2019-01-21 15:08:22 +01:00
|
|
|
};
|
|
|
|
|
2019-04-01 11:49:54 +02:00
|
|
|
private redirect: string | null = null;
|
2019-01-21 15:08:22 +01:00
|
|
|
|
|
|
|
mounted() {
|
|
|
|
this.credentials.email = this.email;
|
|
|
|
this.credentials.password = this.password;
|
2019-04-01 11:49:54 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
const { query } = this.$route;
|
|
|
|
this.errorCode = query.code as LoginErrorCode;
|
|
|
|
this.redirect = query.redirect as string;
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async loginAction(e: Event) {
|
|
|
|
e.preventDefault();
|
2019-04-01 11:49:54 +02:00
|
|
|
|
|
|
|
this.errors = [];
|
2019-01-21 15:08:22 +01:00
|
|
|
|
|
|
|
try {
|
2019-09-02 18:52:23 +02:00
|
|
|
const { data } = await this.$apollo.mutate<{ login: ILogin }>({
|
2019-01-21 15:08:22 +01:00
|
|
|
mutation: LOGIN,
|
|
|
|
variables: {
|
|
|
|
email: this.credentials.email,
|
2019-03-22 10:57:14 +01:00
|
|
|
password: this.credentials.password,
|
|
|
|
},
|
2019-01-21 15:08:22 +01:00
|
|
|
});
|
2019-09-02 18:52:23 +02:00
|
|
|
if (data == null) {
|
2020-02-18 08:57:00 +01:00
|
|
|
throw new Error("Data is undefined");
|
2019-09-02 18:52:23 +02:00
|
|
|
}
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-09-02 18:52:23 +02:00
|
|
|
saveUserData(data.login);
|
2019-01-21 15:08:22 +01:00
|
|
|
|
|
|
|
await this.$apollo.mutate({
|
|
|
|
mutation: UPDATE_CURRENT_USER_CLIENT,
|
|
|
|
variables: {
|
2019-09-02 18:52:23 +02:00
|
|
|
id: data.login.user.id,
|
2019-03-22 10:57:14 +01:00
|
|
|
email: this.credentials.email,
|
2019-04-01 11:49:54 +02:00
|
|
|
isLoggedIn: true,
|
2019-09-09 09:31:08 +02:00
|
|
|
role: data.login.user.role,
|
2019-03-22 10:57:14 +01:00
|
|
|
},
|
2019-01-21 15:08:22 +01:00
|
|
|
});
|
2019-10-12 13:16:36 +02:00
|
|
|
try {
|
|
|
|
await initializeCurrentActor(this.$apollo.provider.defaultClient);
|
2020-02-18 08:57:00 +01:00
|
|
|
} catch (err) {
|
|
|
|
if (err instanceof NoIdentitiesException) {
|
|
|
|
return this.$router.push({
|
2019-10-12 13:16:36 +02:00
|
|
|
name: RouteName.REGISTER_PROFILE,
|
2020-02-18 08:57:00 +01:00
|
|
|
params: {
|
|
|
|
email: this.currentUser.email,
|
|
|
|
userAlreadyActivated: "true",
|
|
|
|
},
|
2019-10-12 13:16:36 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-04-01 11:49:54 +02:00
|
|
|
if (this.redirect) {
|
2020-02-18 08:57:00 +01:00
|
|
|
return this.$router.push(this.redirect);
|
2019-04-01 11:49:54 +02:00
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
window.localStorage.setItem("welcome-back", "yes");
|
|
|
|
return this.$router.push({ name: RouteName.HOME });
|
2019-01-21 15:08:22 +01:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
2020-02-18 08:57:00 +01:00
|
|
|
err.graphQLErrors.forEach(({ message }: { message: string }) => {
|
2019-01-21 15:08:22 +01:00
|
|
|
this.errors.push(message);
|
|
|
|
});
|
2020-02-18 08:57:00 +01:00
|
|
|
return undefined;
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
2019-10-10 14:20:09 +02:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2020-02-18 08:57:00 +01:00
|
|
|
.container .columns {
|
|
|
|
margin: 1rem auto 3rem;
|
|
|
|
}
|
2019-11-21 16:07:43 +01:00
|
|
|
</style>
|