@@ -98,14 +98,14 @@
|
||||
<script lang="ts">
|
||||
import { Component, Prop, Vue } from "vue-property-decorator";
|
||||
import { Route } from "vue-router";
|
||||
import { ICurrentUser } from "@/types/current-user.model";
|
||||
import { LoginError, LoginErrorCode } from "@/types/enums";
|
||||
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";
|
||||
import AuthProviders from "../../components/User/AuthProviders.vue";
|
||||
|
||||
@@ -52,21 +52,21 @@ export default class PasswordReset extends Vue {
|
||||
errors: string[] = [];
|
||||
|
||||
rules = {
|
||||
passwordLength: (value: string) =>
|
||||
passwordLength: (value: string): boolean | string =>
|
||||
value.length > 6 || "Password must be at least 6 characters long",
|
||||
required: validateRequiredField,
|
||||
passwordEqual: (value: string) =>
|
||||
passwordEqual: (value: string): boolean | string =>
|
||||
value === this.credentials.password || "Passwords must be the same",
|
||||
};
|
||||
|
||||
get samePasswords() {
|
||||
get samePasswords(): boolean {
|
||||
return (
|
||||
this.rules.passwordLength(this.credentials.password) === true &&
|
||||
this.credentials.password === this.credentials.passwordConfirmation
|
||||
);
|
||||
}
|
||||
|
||||
async resetAction(e: Event) {
|
||||
async resetAction(e: Event): Promise<void> {
|
||||
e.preventDefault();
|
||||
this.errors.splice(0);
|
||||
|
||||
|
||||
@@ -1,59 +1,58 @@
|
||||
<template></template>
|
||||
<script lang="ts">
|
||||
import { Component, Prop, Vue } from "vue-property-decorator";
|
||||
import { VALIDATE_USER, UPDATE_CURRENT_USER_CLIENT, LOGGED_USER } from "../../graphql/user";
|
||||
import { Component, Vue } from "vue-property-decorator";
|
||||
import { ICurrentUserRole } from "@/types/enums";
|
||||
import { UPDATE_CURRENT_USER_CLIENT, LOGGED_USER } from "../../graphql/user";
|
||||
import RouteName from "../../router/name";
|
||||
import { saveUserData, changeIdentity } from "../../utils/auth";
|
||||
import { ILogin } from "../../types/login.model";
|
||||
import { ICurrentUserRole, ICurrentUser, IUser } from "../../types/current-user.model";
|
||||
import { IDENTITIES } from "../../graphql/actor";
|
||||
import { IUser } from "../../types/current-user.model";
|
||||
|
||||
@Component
|
||||
export default class ProviderValidate extends Vue {
|
||||
async mounted() {
|
||||
async mounted(): Promise<void> {
|
||||
const accessToken = this.getValueFromMeta("auth-access-token");
|
||||
const refreshToken = this.getValueFromMeta("auth-refresh-token");
|
||||
const userId = this.getValueFromMeta("auth-user-id");
|
||||
const userEmail = this.getValueFromMeta("auth-user-email");
|
||||
const userRole = this.getValueFromMeta("auth-user-role") as ICurrentUserRole;
|
||||
const userActorId = this.getValueFromMeta("auth-user-actor-id");
|
||||
|
||||
if (!(userId && userEmail && userRole && accessToken && refreshToken)) {
|
||||
return this.$router.push("/");
|
||||
}
|
||||
const login = {
|
||||
user: { id: userId, email: userEmail, role: userRole, isLoggedIn: true },
|
||||
accessToken,
|
||||
refreshToken,
|
||||
};
|
||||
saveUserData(login);
|
||||
await this.$apollo.mutate({
|
||||
mutation: UPDATE_CURRENT_USER_CLIENT,
|
||||
variables: {
|
||||
id: userId,
|
||||
email: userEmail,
|
||||
isLoggedIn: true,
|
||||
role: ICurrentUserRole.USER,
|
||||
},
|
||||
});
|
||||
const { data } = await this.$apollo.query<{ loggedUser: IUser }>({
|
||||
query: LOGGED_USER,
|
||||
});
|
||||
const { loggedUser } = data;
|
||||
|
||||
if (loggedUser.defaultActor) {
|
||||
await changeIdentity(this.$apollo.provider.defaultClient, loggedUser.defaultActor);
|
||||
await this.$router.push({ name: RouteName.HOME });
|
||||
await this.$router.push("/");
|
||||
} else {
|
||||
// If the user didn't register any profile yet, let's create one for them
|
||||
await this.$router.push({
|
||||
name: RouteName.REGISTER_PROFILE,
|
||||
params: { email: loggedUser.email, userAlreadyActivated: "true" },
|
||||
const login = {
|
||||
user: { id: userId, email: userEmail, role: userRole, isLoggedIn: true },
|
||||
accessToken,
|
||||
refreshToken,
|
||||
};
|
||||
saveUserData(login);
|
||||
await this.$apollo.mutate({
|
||||
mutation: UPDATE_CURRENT_USER_CLIENT,
|
||||
variables: {
|
||||
id: userId,
|
||||
email: userEmail,
|
||||
isLoggedIn: true,
|
||||
role: ICurrentUserRole.USER,
|
||||
},
|
||||
});
|
||||
const { data } = await this.$apollo.query<{ loggedUser: IUser }>({
|
||||
query: LOGGED_USER,
|
||||
});
|
||||
const { loggedUser } = data;
|
||||
|
||||
if (loggedUser.defaultActor) {
|
||||
await changeIdentity(this.$apollo.provider.defaultClient, loggedUser.defaultActor);
|
||||
await this.$router.push({ name: RouteName.HOME });
|
||||
} else {
|
||||
// If the user didn't register any profile yet, let's create one for them
|
||||
await this.$router.push({
|
||||
name: RouteName.REGISTER_PROFILE,
|
||||
params: { email: loggedUser.email, userAlreadyActivated: "true" },
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getValueFromMeta(name: string) {
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
getValueFromMeta(name: string): string | null {
|
||||
const element = document.querySelector(`meta[name="${name}"]`);
|
||||
if (element && element.getAttribute("content")) {
|
||||
return element.getAttribute("content");
|
||||
|
||||
@@ -143,7 +143,6 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { Component, Prop, Vue } from "vue-property-decorator";
|
||||
import { Route } from "vue-router";
|
||||
import { CREATE_USER } from "../../graphql/user";
|
||||
import RouteName from "../../router/name";
|
||||
import { IConfig } from "../../types/config.model";
|
||||
|
||||
@@ -68,11 +68,11 @@ export default class ResendConfirmation extends Vue {
|
||||
email: validateEmailField,
|
||||
};
|
||||
|
||||
mounted() {
|
||||
mounted(): void {
|
||||
this.credentials.email = this.email;
|
||||
}
|
||||
|
||||
async resendConfirmationAction(e: Event) {
|
||||
async resendConfirmationAction(e: Event): Promise<void> {
|
||||
e.preventDefault();
|
||||
this.error = false;
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { Component, Prop, Vue } from "vue-property-decorator";
|
||||
import { ICurrentUserRole } from "@/types/enums";
|
||||
import { VALIDATE_USER, UPDATE_CURRENT_USER_CLIENT } from "../../graphql/user";
|
||||
import RouteName from "../../router/name";
|
||||
import { saveUserData, saveTokenData, changeIdentity } from "../../utils/auth";
|
||||
import { ILogin } from "../../types/login.model";
|
||||
import { ICurrentUserRole } from "../../types/current-user.model";
|
||||
|
||||
@Component
|
||||
export default class Validate extends Vue {
|
||||
@@ -30,11 +30,11 @@ export default class Validate extends Vue {
|
||||
|
||||
failed = false;
|
||||
|
||||
async created() {
|
||||
async created(): Promise<void> {
|
||||
await this.validateAction();
|
||||
}
|
||||
|
||||
async validateAction() {
|
||||
async validateAction(): Promise<void> {
|
||||
try {
|
||||
const { data } = await this.$apollo.mutate<{ validateUser: ILogin }>({
|
||||
mutation: VALIDATE_USER,
|
||||
|
||||
Reference in New Issue
Block a user