juice-shop

Форк
0
/
user.service.ts 
81 строка · 2.9 Кб
1
/*
2
 * Copyright (c) 2014-2024 Bjoern Kimminich & the OWASP Juice Shop contributors.
3
 * SPDX-License-Identifier: MIT
4
 */
5

6
import { environment } from '../../environments/environment'
7
import { Injectable } from '@angular/core'
8
import { HttpClient } from '@angular/common/http'
9
import { catchError, map } from 'rxjs/operators'
10
import { Subject } from 'rxjs'
11

12
interface Passwords {
13
  current?: string
14
  new?: string
15
  repeat?: string
16
}
17

18
@Injectable({
19
  providedIn: 'root'
20
})
21
export class UserService {
22
  public isLoggedIn = new Subject<any>()
23
  private readonly hostServer = environment.hostServer
24
  private readonly host = this.hostServer + '/api/Users'
25

26
  constructor (private readonly http: HttpClient) { }
27

28
  find (params?: any) {
29
    return this.http.get(this.hostServer + '/rest/user/authentication-details/', { params }).pipe(map((response: any) =>
30
      response.data), catchError((err) => { throw err }))
31
  }
32

33
  get (id: number) {
34
    return this.http.get(`${this.host}/${id}`).pipe(map((response: any) => response.data), catchError((err) => { throw err }))
35
  }
36

37
  save (params: any) {
38
    return this.http.post(this.host + '/', params).pipe(
39
      map((response: any) => response.data),
40
      catchError((err) => { throw err })
41
    )
42
  }
43

44
  login (params: any) {
45
    this.isLoggedIn.next(true)
46
    return this.http.post(this.hostServer + '/rest/user/login', params).pipe(map((response: any) => response.authentication), catchError((err) => { throw err }))
47
  }
48

49
  getLoggedInState () {
50
    return this.isLoggedIn.asObservable()
51
  }
52

53
  changePassword (passwords: Passwords) {
54
    return this.http.get(this.hostServer + '/rest/user/change-password?current=' + passwords.current + '&new=' +
55
    passwords.new + '&repeat=' + passwords.repeat).pipe(map((response: any) => response.user), catchError((err) => { throw err.error }))
56
  }
57

58
  resetPassword (params: any) {
59
    return this.http.post(this.hostServer + '/rest/user/reset-password', params).pipe(map((response: any) => response.user), catchError((err) => { throw err }))
60
  }
61

62
  whoAmI () {
63
    return this.http.get(this.hostServer + '/rest/user/whoami').pipe(map((response: any) => response.user), catchError((err) => { throw err }))
64
  }
65

66
  oauthLogin (accessToken: string) {
67
    return this.http.get('https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=' + accessToken)
68
  }
69

70
  saveLastLoginIp () {
71
    return this.http.get(this.hostServer + '/rest/saveLoginIp').pipe(map((response: any) => response), catchError((err) => { throw err }))
72
  }
73

74
  deluxeStatus () {
75
    return this.http.get(this.hostServer + '/rest/deluxe-membership').pipe(map((response: any) => response.data), catchError((err) => { throw err }))
76
  }
77

78
  upgradeToDeluxe (paymentMode: string, paymentId: any) {
79
    return this.http.post(this.hostServer + '/rest/deluxe-membership', { paymentMode, paymentId }).pipe(map((response: any) => response.data), catchError((err) => { throw err }))
80
  }
81
}
82

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.