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'
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))
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)
}
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)