X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fusers%2Fuser.service.ts;h=051e0bfa446a7f3120ec0c0016107979d879d6ff;hb=bf64ed4196938ba9002c887cadb01bd2a6e3127a;hp=20883456fd68edd5a100857a32de5739a847771b;hpb=b91bc1d1f3591c35ab4426f6ab594b4bd9f1ef62;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/users/user.service.ts b/client/src/app/shared/users/user.service.ts index 20883456f..051e0bfa4 100644 --- a/client/src/app/shared/users/user.service.ts +++ b/client/src/app/shared/users/user.service.ts @@ -38,6 +38,20 @@ export class UserService { ) } + changeEmail (password: string, newEmail: string) { + const url = UserService.BASE_USERS_URL + 'me' + const body: UserUpdateMe = { + currentPassword: password, + email: newEmail + } + + return this.authHttp.put(url, body) + .pipe( + map(this.restExtractor.extractDataBool), + catchError(err => this.restExtractor.handleError(err)) + ) + } + updateMyProfile (profile: UserUpdateMe) { const url = UserService.BASE_USERS_URL + 'me' @@ -74,7 +88,7 @@ export class UserService { } getMyVideoQuotaUsed () { - const url = UserService.BASE_USERS_URL + '/me/video-quota-used' + const url = UserService.BASE_USERS_URL + 'me/video-quota-used' return this.authHttp.get(url) .pipe(catchError(err => this.restExtractor.handleError(err))) @@ -104,10 +118,11 @@ export class UserService { ) } - verifyEmail (userId: number, verificationString: string) { + verifyEmail (userId: number, verificationString: string, isPendingEmail: boolean) { const url = `${UserService.BASE_USERS_URL}/${userId}/verify-email` const body = { - verificationString + verificationString, + isPendingEmail } return this.authHttp.post(url, body) @@ -136,6 +151,22 @@ export class UserService { .pipe(catchError(res => this.restExtractor.handleError(res))) } + getNewUsername (oldDisplayName: string, newDisplayName: string, currentUsername: string) { + // Don't update display name, the user seems to have changed it + if (this.displayNameToUsername(oldDisplayName) !== currentUsername) return currentUsername + + return this.displayNameToUsername(newDisplayName) + } + + displayNameToUsername (displayName: string) { + if (!displayName) return '' + + return displayName + .toLowerCase() + .replace(/\s/g, '_') + .replace(/[^a-z0-9_.]/g, '') + } + /* ###### Admin methods ###### */ addUser (userCreate: UserCreate) {