aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/auth/auth.service.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-04-06 21:21:03 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-04-06 21:21:03 +0200
commitaf5e743b01f20f24d0c25e786d57f557b21f3a24 (patch)
tree5186d587135f13f00687f8ed6cd8504cdd35799f /client/src/app/core/auth/auth.service.ts
parent92fb909c9b4a92a00b0d0da7629e6fb003de281b (diff)
downloadPeerTube-af5e743b01f20f24d0c25e786d57f557b21f3a24.tar.gz
PeerTube-af5e743b01f20f24d0c25e786d57f557b21f3a24.tar.zst
PeerTube-af5e743b01f20f24d0c25e786d57f557b21f3a24.zip
Client: add ability for user to change nsfw settings
Diffstat (limited to 'client/src/app/core/auth/auth.service.ts')
-rw-r--r--client/src/app/core/auth/auth.service.ts33
1 files changed, 27 insertions, 6 deletions
diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts
index 2e7328197..00a4216ef 100644
--- a/client/src/app/core/auth/auth.service.ts
+++ b/client/src/app/core/auth/auth.service.ts
@@ -125,7 +125,7 @@ export class AuthService {
125 res.username = username; 125 res.username = username;
126 return res; 126 return res;
127 }) 127 })
128 .flatMap(res => this.fetchUserInformations(res)) 128 .flatMap(res => this.mergeUserInformations(res))
129 .map(res => this.handleLogin(res)) 129 .map(res => this.handleLogin(res))
130 .catch((res) => this.restExtractor.handleError(res)); 130 .catch((res) => this.restExtractor.handleError(res));
131 } 131 }
@@ -178,7 +178,23 @@ export class AuthService {
178 }); 178 });
179 } 179 }
180 180
181 private fetchUserInformations (obj: any) { 181 refreshUserInformations() {
182 const obj = {
183 access_token: this.user.getAccessToken()
184 };
185
186 this.mergeUserInformations(obj)
187 .subscribe(
188 res => {
189 this.user.displayNSFW = res.displayNSFW;
190 this.user.role = res.role;
191
192 this.user.save();
193 }
194 );
195 }
196
197 private mergeUserInformations(obj: { access_token: string }) {
182 // Do not call authHttp here to avoid circular dependencies headaches 198 // Do not call authHttp here to avoid circular dependencies headaches
183 199
184 const headers = new Headers(); 200 const headers = new Headers();
@@ -187,9 +203,13 @@ export class AuthService {
187 return this.http.get(AuthService.BASE_USER_INFORMATIONS_URL, { headers }) 203 return this.http.get(AuthService.BASE_USER_INFORMATIONS_URL, { headers })
188 .map(res => res.json()) 204 .map(res => res.json())
189 .map(res => { 205 .map(res => {
190 obj.id = res.id; 206 const newProperties = {
191 obj.role = res.role; 207 id: res.id,
192 return obj; 208 role: res.role,
209 displayNSFW: res.displayNSFW
210 };
211
212 return Object.assign(obj, newProperties);
193 } 213 }
194 ); 214 );
195 } 215 }
@@ -198,13 +218,14 @@ export class AuthService {
198 const id = obj.id; 218 const id = obj.id;
199 const username = obj.username; 219 const username = obj.username;
200 const role = obj.role; 220 const role = obj.role;
221 const displayNSFW = obj.displayNSFW;
201 const hashTokens = { 222 const hashTokens = {
202 access_token: obj.access_token, 223 access_token: obj.access_token,
203 token_type: obj.token_type, 224 token_type: obj.token_type,
204 refresh_token: obj.refresh_token 225 refresh_token: obj.refresh_token
205 }; 226 };
206 227
207 this.user = new AuthUser({ id, username, role }, hashTokens); 228 this.user = new AuthUser({ id, username, role, displayNSFW }, hashTokens);
208 this.user.save(); 229 this.user.save();
209 230
210 this.setStatus(AuthStatus.LoggedIn); 231 this.setStatus(AuthStatus.LoggedIn);