forked from juice-shop/juice-shop
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuser.service.ts
81 lines (65 loc) · 2.87 KB
/
user.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Copyright (c) 2014-2023 Bjoern Kimminich & the OWASP Juice Shop contributors.
* SPDX-License-Identifier: MIT
*/
import { environment } from '../../environments/environment'
import { Injectable } from '@angular/core'
import { HttpClient } from '@angular/common/http'
import { catchError, map } from 'rxjs/operators'
import { Subject } from 'rxjs'
interface Passwords {
current?: string
new?: string
repeat?: string
}
@Injectable({
providedIn: 'root'
})
export class UserService {
public isLoggedIn = new Subject<any>()
private readonly hostServer = environment.hostServer
private readonly host = this.hostServer + '/api/Users'
constructor (private readonly http: HttpClient) { }
find (params?: any) {
return this.http.get(this.hostServer + '/rest/user/authentication-details/', { params }).pipe(map((response: any) =>
response.data), catchError((err) => { throw err }))
}
get (id: number) {
return this.http.get(`${this.host}/${id}`).pipe(map((response: any) => response.data), catchError((err) => { throw err }))
}
save (params: any) {
return this.http.post(this.host + '/', params).pipe(
map((response: any) => response.data),
catchError((err) => { throw err })
)
}
login (params: any) {
this.isLoggedIn.next(true)
return this.http.post(this.hostServer + '/rest/user/login', params).pipe(map((response: any) => response.authentication), catchError((err) => { throw err }))
}
getLoggedInState () {
return this.isLoggedIn.asObservable()
}
changePassword (passwords: Passwords) {
return this.http.get(this.hostServer + '/rest/user/change-password?current=' + passwords.current + '&new=' +
passwords.new + '&repeat=' + passwords.repeat).pipe(map((response: any) => response.user), catchError((err) => { throw err.error }))
}
resetPassword (params: any) {
return this.http.post(this.hostServer + '/rest/user/reset-password', params).pipe(map((response: any) => response.user), catchError((err) => { throw err }))
}
whoAmI () {
return this.http.get(this.hostServer + '/rest/user/whoami').pipe(map((response: any) => response.user), catchError((err) => { throw err }))
}
oauthLogin (accessToken: string) {
return this.http.get('https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=' + accessToken)
}
saveLastLoginIp () {
return this.http.get(this.hostServer + '/rest/saveLoginIp').pipe(map((response: any) => response), catchError((err) => { throw err }))
}
deluxeStatus () {
return this.http.get(this.hostServer + '/rest/deluxe-membership').pipe(map((response: any) => response.data), catchError((err) => { throw err }))
}
upgradeToDeluxe (paymentMode: string, paymentId: any) {
return this.http.post(this.hostServer + '/rest/deluxe-membership', { paymentMode, paymentId }).pipe(map((response: any) => response.data), catchError((err) => { throw err }))
}
}