Added Widget-Onboarding and dependent Services
[portal.git] / portal-FE-common / src / app / shared / services / admins / admins.service.ts
1 import { Injectable } from '@angular/core';
2 import { HttpClient, HttpParams } from '@angular/common/http';
3 import { environment } from 'src/environments/environment';
4 import { Observable } from 'rxjs';
5
6 @Injectable({
7   providedIn: 'root'
8 })
9 export class AdminsService {
10
11   constructor(private httpClient: HttpClient) { }
12   apiUrl = environment.api;
13
14   getAccountAdmins(): Observable<any> {
15     return this.httpClient.get(this.apiUrl.accountAdmins);
16   };
17
18   getAdminAppsRoles(orgUserId: string): Observable<any> {
19     let params = new HttpParams().set('user', orgUserId);
20     return this.httpClient.get(this.apiUrl.adminAppsRoles, { params: params });
21   };
22
23
24   getRolesByApp(_appId: any): Observable<any> {
25     return this.httpClient.get(this.apiUrl.adminAppsRoles + '/' + _appId);
26   };
27
28   updateAdminAppsRoles(_newAdminAppRoles: any): Observable<any> {
29     return this.httpClient.put(this.apiUrl.adminAppsRoles, _newAdminAppRoles);
30   };
31
32
33   isComplexPassword(str) {
34     let minLength = 8;
35     let message = 'Password is too simple.  Minimum length is ' + minLength + ', '
36       + 'and it must use letters, digits and special characters.';
37     if (str == null)
38       return message;
39
40     let hasLetter = false;
41     let hasDigit = false;
42     let hasSpecial = false;
43     var code, i, len;
44     for (i = 0, len = str.length; i < len; i++) {
45       code = str.charCodeAt(i);
46       if (code > 47 && code < 58) // numeric (0-9)
47         hasDigit = true;
48       else if ((code > 64 && code < 91) || (code > 96 && code < 123)) // A-Z, a-z
49         hasLetter = true;
50       else
51         hasSpecial = true;
52     } // for
53
54     if (str.length < minLength || !hasLetter || !hasDigit || !hasSpecial)
55       return message;
56
57     // All is well.
58     return null;
59
60   };
61
62   addNewUser(newUser, checkDuplicate): Observable<any> {
63     return this.httpClient.post(this.apiUrl.saveNewUser + '?isCheck=' + checkDuplicate, newUser);
64   };
65
66 }