summaryrefslogtreecommitdiffstats
path: root/portal-FE-common/src/app/shared/services/admins/admins.service.ts
blob: fe76bd4b3344b5e1b1d019fc278418f83ba665b8 (plain)
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
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class AdminsService {

  constructor(private httpClient: HttpClient) { }
  apiUrl = environment.api;

  getAccountAdmins(): Observable<any> {
    return this.httpClient.get(this.apiUrl.accountAdmins);
  };

  getAdminAppsRoles(orgUserId: string): Observable<any> {
    let params = new HttpParams().set('user', orgUserId);
    return this.httpClient.get(this.apiUrl.adminAppsRoles, { params: params });
  };


  getRolesByApp(_appId: any): Observable<any> {
    return this.httpClient.get(this.apiUrl.adminAppsRoles + '/' + _appId);
  };

  updateAdminAppsRoles(_newAdminAppRoles: any): Observable<any> {
    return this.httpClient.put(this.apiUrl.adminAppsRoles, _newAdminAppRoles);
  };


  isComplexPassword(str) {
    let minLength = 8;
    let message = 'Password is too simple.  Minimum length is ' + minLength + ', '
      + 'and it must use letters, digits and special characters.';
    if (str == null)
      return message;

    let hasLetter = false;
    let hasDigit = false;
    let hasSpecial = false;
    var code, i, len;
    for (i = 0, len = str.length; i < len; i++) {
      code = str.charCodeAt(i);
      if (code > 47 && code < 58) // numeric (0-9)
        hasDigit = true;
      else if ((code > 64 && code < 91) || (code > 96 && code < 123)) // A-Z, a-z
        hasLetter = true;
      else
        hasSpecial = true;
    } // for

    if (str.length < minLength || !hasLetter || !hasDigit || !hasSpecial)
      return message;

    // All is well.
    return null;

  };

  addNewUser(newUser, checkDuplicate): Observable<any> {
    return this.httpClient.post(this.apiUrl.saveNewUser + '?isCheck=' + checkDuplicate, newUser);
  };

}