2020-02-13 15:48:12 +01:00
< template >
2020-06-27 19:12:45 +02:00
< div v-if ="loggedUser" >
2020-06-25 11:36:35 +02:00
< nav class = "breadcrumb" aria -label = " breadcrumbs " >
< ul >
< li >
2020-11-30 10:24:11 +01:00
< router -link : to = "{ name: RouteName.ACCOUNT_SETTINGS }" > { {
$t ( "Account" )
} } < / r o u t e r - l i n k >
2020-06-25 11:36:35 +02:00
< / li >
< li class = "is-active" >
< router -link : to = "{ name: RouteName.ACCOUNT_SETTINGS_GENERAL }" > { {
$t ( "General" )
} } < / r o u t e r - l i n k >
< / li >
< / ul >
< / nav >
< section >
< div class = "setting-title" >
< h2 > { { $t ( "Email" ) } } < / h2 >
< / div >
< i18n
tag = "p"
class = "content"
v - if = "loggedUser"
path = "Your current email is {email}. You use it to log in."
2020-02-18 08:57:00 +01:00
>
2020-06-25 11:36:35 +02:00
< b slot = "email" > { { loggedUser . email } } < / b >
< / i18n >
2020-06-27 19:12:45 +02:00
< b -message v-if ="!canChangeEmail" type="is-warning" :closable ="false" >
{ {
2020-11-30 10:24:11 +01:00
$t (
"Your email address was automatically set based on your {provider} account." ,
{
provider : providerName ( loggedUser . provider ) ,
}
)
2020-06-27 19:12:45 +02:00
} }
< / b - m e s s a g e >
2020-06-25 11:36:35 +02:00
< b -notification
type = "is-danger"
has - icon
aria - close - label = "Close notification"
role = "alert"
: key = "error"
v - for = "error in changeEmailErrors"
> { { error } } < / b - n o t i f i c a t i o n
2020-02-18 08:57:00 +01:00
>
2020-11-30 10:24:11 +01:00
< form
@ submit . prevent = "resetEmailAction"
ref = "emailForm"
class = "form"
v - if = "canChangeEmail"
>
2021-08-23 10:20:55 +02:00
< b -field : label = "$t('New email')" label -for = " account -email " >
2020-11-30 10:24:11 +01:00
< b -input
aria - required = "true"
required
type = "email"
2021-08-23 10:20:55 +02:00
id = "account-email"
2020-11-30 10:24:11 +01:00
v - model = "newEmail"
/ >
2020-06-25 11:36:35 +02:00
< / b - f i e l d >
< p class = "help" > { { $t ( "You'll receive a confirmation email." ) } } < / p >
2021-08-23 10:20:55 +02:00
< b -field :label ="$t('Password')" label -for = " account -password " >
2020-06-25 11:36:35 +02:00
< b -input
aria - required = "true"
required
type = "password"
2021-08-23 10:20:55 +02:00
id = "account-password"
2020-06-25 11:36:35 +02:00
password - reveal
minlength = "6"
v - model = "passwordForEmailChange"
/ >
< / b - f i e l d >
< button
class = "button is-primary"
: disabled = "!($refs.emailForm && $refs.emailForm.checkValidity())"
>
{ { $t ( "Change my email" ) } }
< / button >
< / form >
< div class = "setting-title" >
< h2 > { { $t ( "Password" ) } } < / h2 >
< / div >
2020-06-27 19:12:45 +02:00
< b -message v-if ="!canChangePassword" type="is-warning" :closable ="false" >
{ {
2020-11-30 10:24:11 +01:00
$t (
"You can't change your password because you are registered through {provider}." ,
{
provider : providerName ( loggedUser . provider ) ,
}
)
2020-06-27 19:12:45 +02:00
} }
< / b - m e s s a g e >
2020-06-25 11:36:35 +02:00
< b -notification
type = "is-danger"
has - icon
aria - close - label = "Close notification"
role = "alert"
: key = "error"
v - for = "error in changePasswordErrors"
> { { error } } < / b - n o t i f i c a t i o n
>
2020-06-27 19:12:45 +02:00
< form
@ submit . prevent = "resetPasswordAction"
ref = "passwordForm"
class = "form"
v - if = "canChangePassword"
>
2021-08-23 10:20:55 +02:00
< b -field : label = "$t('Old password')" label -for = " account -old -password " >
2020-06-25 11:36:35 +02:00
< b -input
aria - required = "true"
required
type = "password"
password - reveal
minlength = "6"
2021-08-23 10:20:55 +02:00
id = "account-old-password"
2020-06-25 11:36:35 +02:00
v - model = "oldPassword"
/ >
< / b - f i e l d >
2021-08-23 10:20:55 +02:00
< b -field : label = "$t('New password')" label -for = " account -new -password " >
2020-06-25 11:36:35 +02:00
< b -input
aria - required = "true"
required
type = "password"
password - reveal
minlength = "6"
2021-08-23 10:20:55 +02:00
id = "account-new-password"
2020-06-25 11:36:35 +02:00
v - model = "newPassword"
/ >
< / b - f i e l d >
< button
class = "button is-primary"
2020-11-30 10:24:11 +01:00
: disabled = "
! ( $refs . passwordForm && $refs . passwordForm . checkValidity ( ) )
"
2020-06-25 11:36:35 +02:00
>
{ { $t ( "Change my password" ) } }
< / button >
< / form >
< div class = "setting-title" >
< h2 > { { $t ( "Delete account" ) } } < / h2 >
< / div >
2020-11-30 10:24:11 +01:00
< p class = "content" >
{ { $t ( "Deleting my account will delete all of my identities." ) } }
< / p >
2020-06-25 11:36:35 +02:00
< b -button @click ="openDeleteAccountModal" type = "is-danger" >
{ { $t ( "Delete my account" ) } }
< / b - b u t t o n >
2020-02-13 15:48:12 +01:00
2020-06-25 11:36:35 +02:00
< b -modal
: active . sync = "isDeleteAccountModalActive"
has - modal - card
full - screen
: can - cancel = "false"
>
< section class = "hero is-primary is-fullheight" >
< div class = "hero-body has-text-centered" >
< div class = "container" >
< div class = "columns" >
2020-11-30 10:24:11 +01:00
< div
2021-05-17 19:01:08 +02:00
class = "
column
is - one - third - desktop is - offset - one - third - desktop
"
2020-11-30 10:24:11 +01:00
>
< h1 class = "title" >
{ { $t ( "Deleting your Mobilizon account" ) } }
< / h1 >
2020-06-25 11:36:35 +02:00
< p class = "content" >
{ {
$t (
"Are you really sure you want to delete your whole account? You'll lose everything. Identities, settings, events created, messages and participations will be gone forever."
)
} }
< br / >
2020-11-30 10:24:11 +01:00
< b > { {
$t ( "There will be no way to recover your data." )
} } < / b >
2020-06-25 11:36:35 +02:00
< / p >
2020-06-27 19:12:45 +02:00
< p class = "content" v-if ="hasUserGotAPassword" >
2020-11-30 10:24:11 +01:00
{ {
$t ( "Please enter your password to confirm this action." )
} }
2020-06-25 11:36:35 +02:00
< / p >
< form @submit.prevent ="deleteAccount" >
2021-08-23 10:20:31 +02:00
< b -field
: type = "deleteAccountPasswordFieldType"
v - if = "hasUserGotAPassword"
label - for = "account-deletion-password"
>
2020-06-25 11:36:35 +02:00
< b -input
type = "password"
v - model = "passwordForAccountDeletion"
password - reveal
2021-08-23 10:20:31 +02:00
id = "account-deletion-password"
: aria - label = "$t('Password')"
2020-06-25 11:36:35 +02:00
icon = "lock"
: placeholder = "$t('Password')"
/ >
2021-08-23 10:20:31 +02:00
< template # message >
< b -message
type = "is-danger"
v - for = "message in deletePasswordErrors"
: key = "message"
>
{ { message } }
< / b - m e s s a g e >
< / template >
2020-06-25 11:36:35 +02:00
< / b - f i e l d >
2020-11-30 10:24:11 +01:00
< b -button
native - type = "submit"
type = "is-danger"
size = "is-large"
>
2020-06-25 11:36:35 +02:00
{ { $t ( "Delete everything" ) } }
< / b - b u t t o n >
< / form >
< div class = "cancel-button" >
2020-11-30 10:24:11 +01:00
< b -button
type = "is-light"
@ click = "isDeleteAccountModalActive = false"
>
2020-06-25 11:36:35 +02:00
{ { $t ( "Cancel" ) } }
< / b - b u t t o n >
< / div >
2020-02-13 15:48:12 +01:00
< / div >
2020-02-18 08:57:00 +01:00
< / div >
< / div >
< / div >
2020-06-25 11:36:35 +02:00
< / section >
< / b - m o d a l >
< / section >
< / div >
2020-02-13 15:48:12 +01:00
< / template >
< script lang = "ts" >
2020-11-27 19:27:44 +01:00
import { IAuthProvider } from "@/types/enums" ;
2021-08-23 10:20:31 +02:00
import { GraphQLError } from "graphql/error/GraphQLError" ;
2020-02-18 08:57:00 +01:00
import { Component , Vue , Ref } from "vue-property-decorator" ;
2020-09-29 09:53:48 +02:00
import { Route } from "vue-router" ;
2020-11-30 10:24:11 +01:00
import {
CHANGE _EMAIL ,
CHANGE _PASSWORD ,
DELETE _ACCOUNT ,
LOGGED _USER ,
} from "../../graphql/user" ;
2020-02-18 08:57:00 +01:00
import RouteName from "../../router/name" ;
2020-11-27 19:27:44 +01:00
import { IUser } from "../../types/current-user.model" ;
2020-06-27 19:12:45 +02:00
import { logout , SELECTED _PROVIDERS } from "../../utils/auth" ;
2020-02-13 15:48:12 +01:00
@ Component ( {
apollo : {
loggedUser : LOGGED _USER ,
} ,
2021-05-25 16:21:29 +02:00
metaInfo ( ) {
return {
title : this . $t ( "General settings" ) as string ,
} ;
} ,
2020-02-13 15:48:12 +01:00
} )
export default class AccountSettings extends Vue {
2020-02-18 08:57:00 +01:00
@ Ref ( "passwordForm" ) readonly passwordForm ! : HTMLElement ;
2020-06-27 19:12:45 +02:00
loggedUser ! : IUser ;
2020-02-13 15:48:12 +01:00
2020-02-18 08:57:00 +01:00
passwordForEmailChange = "" ;
newEmail = "" ;
2020-02-13 15:48:12 +01:00
changeEmailErrors : string [ ] = [ ] ;
2020-02-18 08:57:00 +01:00
oldPassword = "" ;
newPassword = "" ;
2020-02-13 15:48:12 +01:00
changePasswordErrors : string [ ] = [ ] ;
2021-08-23 10:20:31 +02:00
deletePasswordErrors : string [ ] = [ ] ;
2020-02-18 08:57:00 +01:00
isDeleteAccountModalActive = false ;
passwordForAccountDeletion = "" ;
2020-02-13 15:48:12 +01:00
RouteName = RouteName ;
2020-09-29 09:53:48 +02:00
async resetEmailAction ( ) : Promise < void > {
2020-02-13 15:48:12 +01:00
this . changeEmailErrors = [ ] ;
try {
await this . $apollo . mutate ( {
mutation : CHANGE _EMAIL ,
variables : {
email : this . newEmail ,
password : this . passwordForEmailChange ,
} ,
} ) ;
2020-02-18 08:57:00 +01:00
this . $notifier . info (
this . $t (
"The account's email address was changed. Check your emails to verify it."
) as string
) ;
this . newEmail = "" ;
this . passwordForEmailChange = "" ;
2021-09-29 18:20:33 +02:00
} catch ( err : any ) {
2020-02-18 08:57:00 +01:00
this . handleErrors ( "email" , err ) ;
2020-02-13 15:48:12 +01:00
}
}
2020-09-29 09:53:48 +02:00
async resetPasswordAction ( ) : Promise < void > {
2020-02-13 15:48:12 +01:00
this . changePasswordErrors = [ ] ;
try {
await this . $apollo . mutate ( {
mutation : CHANGE _PASSWORD ,
variables : {
oldPassword : this . oldPassword ,
newPassword : this . newPassword ,
} ,
} ) ;
2021-09-14 19:42:04 +02:00
this . oldPassword = "" ;
this . newPassword = "" ;
2020-11-30 10:24:11 +01:00
this . $notifier . success (
this . $t ( "The password was successfully changed" ) as string
) ;
2021-09-29 18:20:33 +02:00
} catch ( err : any ) {
2020-02-18 08:57:00 +01:00
this . handleErrors ( "password" , err ) ;
2020-02-13 15:48:12 +01:00
}
}
2020-09-29 09:53:48 +02:00
protected openDeleteAccountModal ( ) : void {
2020-02-18 08:57:00 +01:00
this . passwordForAccountDeletion = "" ;
2020-02-13 15:48:12 +01:00
this . isDeleteAccountModalActive = true ;
}
2020-09-29 09:53:48 +02:00
async deleteAccount ( ) : Promise < Route | void > {
2020-02-13 15:48:12 +01:00
try {
2021-08-23 10:20:31 +02:00
this . deletePasswordErrors = [ ] ;
console . debug ( "Asking to delete account..." ) ;
2020-02-13 15:48:12 +01:00
await this . $apollo . mutate ( {
mutation : DELETE _ACCOUNT ,
variables : {
2020-11-30 10:24:11 +01:00
password : this . hasUserGotAPassword
? this . passwordForAccountDeletion
: null ,
2020-02-13 15:48:12 +01:00
} ,
} ) ;
2021-08-23 10:20:31 +02:00
console . debug ( "Deleted account, logging out client..." ) ;
await logout ( this . $apollo . provider . defaultClient , false ) ;
2020-02-13 15:48:12 +01:00
this . $buefy . notification . open ( {
2020-11-30 10:24:11 +01:00
message : this . $t (
"Your account has been successfully deleted"
) as string ,
2020-02-18 08:57:00 +01:00
type : "is-success" ,
position : "is-bottom-right" ,
2020-02-13 15:48:12 +01:00
duration : 5000 ,
} ) ;
return await this . $router . push ( { name : RouteName . HOME } ) ;
2021-09-29 18:20:33 +02:00
} catch ( err : any ) {
2021-08-23 10:20:31 +02:00
this . deletePasswordErrors = err . graphQLErrors . map (
( { message } : GraphQLError ) => message
) ;
2020-02-13 15:48:12 +01:00
}
}
2020-09-29 09:53:48 +02:00
get canChangePassword ( ) : boolean {
2020-06-27 19:12:45 +02:00
return ! this . loggedUser . provider ;
}
2020-09-29 09:53:48 +02:00
get canChangeEmail ( ) : boolean {
2020-06-27 19:12:45 +02:00
return ! this . loggedUser . provider ;
}
2020-10-13 15:05:32 +02:00
// eslint-disable-next-line class-methods-use-this
providerName ( id : string ) : string {
2020-06-27 19:12:45 +02:00
if ( SELECTED _PROVIDERS [ id ] ) {
return SELECTED _PROVIDERS [ id ] ;
}
return id ;
}
get hasUserGotAPassword ( ) : boolean {
return (
this . loggedUser &&
2020-11-30 10:24:11 +01:00
( this . loggedUser . provider == null ||
this . loggedUser . provider === IAuthProvider . LDAP )
2020-06-27 19:12:45 +02:00
) ;
}
2021-08-23 10:20:31 +02:00
get deleteAccountPasswordFieldType ( ) : string | null {
return this . deletePasswordErrors . length > 0 ? "is-danger" : null ;
}
2020-02-13 15:48:12 +01:00
private handleErrors ( type : string , err : any ) {
console . error ( err ) ;
if ( err . graphQLErrors !== undefined ) {
2020-02-18 08:57:00 +01:00
err . graphQLErrors . forEach ( ( { message } : { message : string } ) => {
2020-02-13 15:48:12 +01:00
switch ( type ) {
2020-02-18 08:57:00 +01:00
case "password" :
2020-09-29 09:53:48 +02:00
this . changePasswordErrors . push ( message ) ;
break ;
case "email" :
default :
this . changeEmailErrors . push ( message ) ;
2020-02-13 15:48:12 +01:00
break ;
}
} ) ;
}
}
}
< / script >
2020-06-05 15:37:45 +02:00
< style lang = "scss" scoped >
2021-08-23 10:20:55 +02:00
. modal . is - active . is - full - screen {
. help . is - danger {
font - size : 1 rem ;
}
}
2020-02-18 08:57:00 +01:00
. cancel - button {
margin - top : 2 rem ;
}
2020-02-13 15:48:12 +01:00
2020-11-16 10:04:47 +01:00
: : v - deep . modal . modal - background {
2020-02-18 08:57:00 +01:00
background - color : initial ;
}
2020-02-13 15:48:12 +01:00
< / style >