aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/users/user.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/users/user.service.ts')
-rw-r--r--client/src/app/shared/users/user.service.ts38
1 files changed, 35 insertions, 3 deletions
diff --git a/client/src/app/shared/users/user.service.ts b/client/src/app/shared/users/user.service.ts
index cc5c051f1..41ee87197 100644
--- a/client/src/app/shared/users/user.service.ts
+++ b/client/src/app/shared/users/user.service.ts
@@ -9,6 +9,7 @@ import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
9import { SortMeta } from 'primeng/api' 9import { SortMeta } from 'primeng/api'
10import { BytesPipe } from 'ngx-pipes' 10import { BytesPipe } from 'ngx-pipes'
11import { I18n } from '@ngx-translate/i18n-polyfill' 11import { I18n } from '@ngx-translate/i18n-polyfill'
12import { UserRegister } from '@shared/models/users/user-register.model'
12 13
13@Injectable() 14@Injectable()
14export class UserService { 15export class UserService {
@@ -37,6 +38,20 @@ export class UserService {
37 ) 38 )
38 } 39 }
39 40
41 changeEmail (password: string, newEmail: string) {
42 const url = UserService.BASE_USERS_URL + 'me'
43 const body: UserUpdateMe = {
44 currentPassword: password,
45 email: newEmail
46 }
47
48 return this.authHttp.put(url, body)
49 .pipe(
50 map(this.restExtractor.extractDataBool),
51 catchError(err => this.restExtractor.handleError(err))
52 )
53 }
54
40 updateMyProfile (profile: UserUpdateMe) { 55 updateMyProfile (profile: UserUpdateMe) {
41 const url = UserService.BASE_USERS_URL + 'me' 56 const url = UserService.BASE_USERS_URL + 'me'
42 57
@@ -64,7 +79,7 @@ export class UserService {
64 .pipe(catchError(err => this.restExtractor.handleError(err))) 79 .pipe(catchError(err => this.restExtractor.handleError(err)))
65 } 80 }
66 81
67 signup (userCreate: UserCreate) { 82 signup (userCreate: UserRegister) {
68 return this.authHttp.post(UserService.BASE_USERS_URL + 'register', userCreate) 83 return this.authHttp.post(UserService.BASE_USERS_URL + 'register', userCreate)
69 .pipe( 84 .pipe(
70 map(this.restExtractor.extractDataBool), 85 map(this.restExtractor.extractDataBool),
@@ -103,10 +118,11 @@ export class UserService {
103 ) 118 )
104 } 119 }
105 120
106 verifyEmail (userId: number, verificationString: string) { 121 verifyEmail (userId: number, verificationString: string, isPendingEmail: boolean) {
107 const url = `${UserService.BASE_USERS_URL}/${userId}/verify-email` 122 const url = `${UserService.BASE_USERS_URL}/${userId}/verify-email`
108 const body = { 123 const body = {
109 verificationString 124 verificationString,
125 isPendingEmail
110 } 126 }
111 127
112 return this.authHttp.post(url, body) 128 return this.authHttp.post(url, body)
@@ -135,6 +151,22 @@ export class UserService {
135 .pipe(catchError(res => this.restExtractor.handleError(res))) 151 .pipe(catchError(res => this.restExtractor.handleError(res)))
136 } 152 }
137 153
154 getNewUsername (oldDisplayName: string, newDisplayName: string, currentUsername: string) {
155 // Don't update display name, the user seems to have changed it
156 if (this.displayNameToUsername(oldDisplayName) !== currentUsername) return currentUsername
157
158 return this.displayNameToUsername(newDisplayName)
159 }
160
161 displayNameToUsername (displayName: string) {
162 if (!displayName) return ''
163
164 return displayName
165 .toLowerCase()
166 .replace(/\s/g, '_')
167 .replace(/[^a-z0-9_.]/g, '')
168 }
169
138 /* ###### Admin methods ###### */ 170 /* ###### Admin methods ###### */
139 171
140 addUser (userCreate: UserCreate) { 172 addUser (userCreate: UserCreate) {