]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/auth/auth.service.ts
Fix log in with special password character (+)
[github/Chocobozzz/PeerTube.git] / client / src / app / core / auth / auth.service.ts
index 8a2ba77d6b16d30bb40f6bd47f530df4cccab392..f5ca2fcdc9d088c582702d286919082d2340ea3f 100644 (file)
@@ -14,7 +14,6 @@ import { User } from '../../../../../shared/models/users'
 import { UserLogin } from '../../../../../shared/models/users/user-login.model'
 import { environment } from '../../../environments/environment'
 import { RestExtractor } from '../../shared/rest'
-import { UserConstructorHash } from '../../shared/users/user.model'
 import { AuthStatus } from './auth-status.model'
 import { AuthUser } from './auth-user.model'
 
@@ -113,17 +112,17 @@ export class AuthService {
 
   login (username: string, password: string) {
     // Form url encoded
-    const body = new HttpParams().set('client_id', this.clientId)
-                                 .set('client_secret', this.clientSecret)
-                                 .set('response_type', 'code')
-                                 .set('grant_type', 'password')
-                                 .set('scope', 'upload')
-                                 .set('username', username)
-                                 .set('password', password)
+    const body = new URLSearchParams()
+    body.set('client_id', this.clientId)
+    body.set('client_secret', this.clientSecret)
+    body.set('response_type', 'code')
+    body.set('grant_type', 'password')
+    body.set('scope', 'upload')
+    body.set('username', username)
+    body.set('password', password)
 
     const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
-
-    return this.http.post<UserLogin>(AuthService.BASE_TOKEN_URL, body, { headers })
+    return this.http.post<UserLogin>(AuthService.BASE_TOKEN_URL, body.toString(), { headers })
                     .map(res => Object.assign(res, { username }))
                     .flatMap(res => this.mergeUserInformation(res))
                     .map(res => this.handleLogin(res))
@@ -178,12 +177,7 @@ export class AuthService {
     this.mergeUserInformation(obj)
       .subscribe(
         res => {
-          this.user.displayNSFW = res.displayNSFW
-          this.user.autoPlayVideo = res.autoPlayVideo
-          this.user.role = res.role
-          this.user.videoChannels = res.videoChannels
-          this.user.account = res.account
-
+          this.user.patch(res)
           this.user.save()
 
           this.userInformationLoaded.next(true)
@@ -200,24 +194,13 @@ export class AuthService {
   }
 
   private handleLogin (obj: UserLoginWithUserInformation) {
-    const hashUser: UserConstructorHash = {
-      id: obj.id,
-      username: obj.username,
-      role: obj.role,
-      email: obj.email,
-      displayNSFW: obj.displayNSFW,
-      autoPlayVideo: obj.autoPlayVideo,
-      videoQuota: obj.videoQuota,
-      videoChannels: obj.videoChannels,
-      account: obj.account
-    }
     const hashTokens = {
       accessToken: obj.access_token,
       tokenType: obj.token_type,
       refreshToken: obj.refresh_token
     }
 
-    this.user = new AuthUser(hashUser, hashTokens)
+    this.user = new AuthUser(obj, hashTokens)
     this.user.save()
 
     this.setStatus(AuthStatus.LoggedIn)