270 lines
9.3 KiB
TypeScript
270 lines
9.3 KiB
TypeScript
|
|
import { Injectable } from '@angular/core';
|
||
|
|
import { User } from '../../_models/Authentication/user';
|
||
|
|
import { HttpClient } from '@angular/common/http';
|
||
|
|
import { JwtHelperService } from '@auth0/angular-jwt';
|
||
|
|
import { map } from 'rxjs/operators';
|
||
|
|
import { ApiService } from '../../app.api.service';
|
||
|
|
import { EnumConfigurationType, EnumRoleType, EnumSystemType, EnumUserType } from '../../_models/enums';
|
||
|
|
import { HRMNotificationService } from '../../app.notification.service';
|
||
|
|
import { Role, RolePermission } from '../../_models/Authentication/role';
|
||
|
|
import { SearchEmployee } from '../../_models/Employee/searchEmployee';
|
||
|
|
import { PayrollType } from '../../_models/Authentication/payrollType';
|
||
|
|
import { UserRole } from '../../_models/Authentication/UserRole';
|
||
|
|
import { UserAccessType } from '../../_models/Authentication/UserAccessType';
|
||
|
|
import { PasswordHistory } from '../../_models/Authentication/passwordHistory';
|
||
|
|
import { Router } from '@angular/router';
|
||
|
|
import { Bookmark } from '../../_models/Basic/bookmark';
|
||
|
|
import { Subject } from 'rxjs';
|
||
|
|
import { PendingJobDTO } from 'src/app/_models/Work-Flow/pendingJobDTO';
|
||
|
|
import { DataPermission } from 'src/app/_models/Basic/DataPermission';
|
||
|
|
|
||
|
|
@Injectable()
|
||
|
|
export class AuthService {
|
||
|
|
|
||
|
|
baseUrl = ApiService.BASE_URL + 'Authentication/';
|
||
|
|
jwtHelper = new JwtHelperService();
|
||
|
|
decodedToken: any;
|
||
|
|
subject: Subject<Bookmark[]>;
|
||
|
|
subject2: Subject<PendingJobDTO[]>;
|
||
|
|
// bookmarks: Bookmark[];
|
||
|
|
constructor(private http: HttpClient,
|
||
|
|
public apiService: ApiService ,
|
||
|
|
public notificationService: HRMNotificationService, private router: Router) {
|
||
|
|
this.subject = new Subject<Bookmark[]>();
|
||
|
|
this.subject2 = new Subject<PendingJobDTO[]>();
|
||
|
|
// this.loadBookmark();
|
||
|
|
// console.log(this.bookmarks);
|
||
|
|
}
|
||
|
|
|
||
|
|
login(model: any) {
|
||
|
|
return this.http.post(this.apiService.base_url + '/Authentication/login', model).pipe(
|
||
|
|
map((response: any) => {
|
||
|
|
const user = response;
|
||
|
|
if (user) {
|
||
|
|
// debugger;
|
||
|
|
localStorage.setItem('token', user);
|
||
|
|
ApiService.AuthenticationToken = user;
|
||
|
|
// this.decodedToken = this.jwtHelper.decodeToken(ApiService.AuthenticationToken);
|
||
|
|
}
|
||
|
|
})
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
userPayrolltypeSwitch(param: any): any {
|
||
|
|
return this.apiService.httpPost<any>('/Authentication/userPayrolltypeSwitch', param);
|
||
|
|
}
|
||
|
|
SwtichUserMode(param: any): any {
|
||
|
|
return this.apiService.httpPost<any>('/Authentication/switchuser', param);
|
||
|
|
}
|
||
|
|
|
||
|
|
GetLogInUserType(): any {
|
||
|
|
return this.apiService.httpGet<EnumUserType>('/Authentication/GetLogInUserType');
|
||
|
|
}
|
||
|
|
|
||
|
|
GetCurrentUser(): any {
|
||
|
|
return this.apiService.httpGet<any>('/Authentication/GetCurrentUser');
|
||
|
|
}
|
||
|
|
getUserByEmail(email: string) {
|
||
|
|
return this.apiService.httpGet<User>('/Authentication/getUserByEmail/' + email);
|
||
|
|
}
|
||
|
|
|
||
|
|
GetUsers(usertype: EnumUserType, loginidid?: string, name?: string): any {
|
||
|
|
//const params = {
|
||
|
|
// LogInID: loginid == undefined ? '' : loginid,
|
||
|
|
// Name: name == undefined ? '' : name,
|
||
|
|
// userType: usertype
|
||
|
|
//};
|
||
|
|
|
||
|
|
const nname = this.apiService.getApiDefaultData(name);
|
||
|
|
const sloginid = this.apiService.getApiDefaultData(loginidid);
|
||
|
|
|
||
|
|
return this.apiService.httpGet<User[]>('/Authentication/GetUsers/' + usertype + '/' + loginidid + '/' + name);
|
||
|
|
}
|
||
|
|
|
||
|
|
GetAllEmpNotYetUser() {
|
||
|
|
return this.apiService.httpGet<User[]>('/Authentication/GetAllEmpNotYetUser');
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
logout() {
|
||
|
|
localStorage.removeItem('forgotpass');
|
||
|
|
|
||
|
|
localStorage.removeItem('token');
|
||
|
|
localStorage.removeItem('menuList');
|
||
|
|
|
||
|
|
this.router.navigate(['/login']);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
SaveUser(oUser: User): any {
|
||
|
|
return this.apiService.httpPost<User>('/Authentication/SaveUser', oUser);
|
||
|
|
}
|
||
|
|
|
||
|
|
ApproveUser(oUser: User): any {
|
||
|
|
return this.apiService.httpPost<User>('/Authentication/ApproveUser', oUser);
|
||
|
|
}
|
||
|
|
|
||
|
|
DoActiveAndIntacive(oUser: User): any {
|
||
|
|
return this.apiService.httpPost<User>('/Authentication/DoActiveAndIntacive', oUser);
|
||
|
|
}
|
||
|
|
GetAllUsers() {
|
||
|
|
return this.apiService.httpGet<User[]>('/Authentication/getAllUsers');
|
||
|
|
}
|
||
|
|
getBookmarks() {
|
||
|
|
return this.apiService.httpGet<Bookmark[]>('/Authentication/getBookmarks');
|
||
|
|
}
|
||
|
|
|
||
|
|
SaveBookmark(oBookmark: Bookmark): any {
|
||
|
|
return this.apiService.httpPost<Bookmark>('/Authentication/SaveBookmark', oBookmark);
|
||
|
|
}
|
||
|
|
|
||
|
|
deleteBookmark(param: any) {
|
||
|
|
return this.apiService.httpPost('/Authentication/deleteBookmark', param);
|
||
|
|
}
|
||
|
|
|
||
|
|
deleteBookmarkByMenuKey(param: any) {
|
||
|
|
return this.apiService.httpPost('/Authentication/deleteBookmarkByMenuKey', param);
|
||
|
|
}
|
||
|
|
|
||
|
|
getPendingJob(employeeId: number) {
|
||
|
|
return this.apiService.httpGet<PendingJobDTO[]>('/Workflow/getPendingJob' + '/' + employeeId);
|
||
|
|
}
|
||
|
|
|
||
|
|
loggedIn() {
|
||
|
|
const token = localStorage.getItem('token');
|
||
|
|
ApiService.AuthenticationToken = token;
|
||
|
|
return !this.jwtHelper.isTokenExpired(token);
|
||
|
|
}
|
||
|
|
|
||
|
|
register(user: User) {
|
||
|
|
return this.http.post(this.baseUrl + 'register', user);
|
||
|
|
}
|
||
|
|
|
||
|
|
loadMenu() {
|
||
|
|
return this.http.get(this.baseUrl + 'loadMenu');
|
||
|
|
}
|
||
|
|
|
||
|
|
getAllRoles() {
|
||
|
|
return this.apiService.httpGet<RolePermission[]>('/Authentication/getAllRoles');
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
getRole(roleID: number) {
|
||
|
|
return this.apiService.httpGet<RolePermission[]>('/Authentication/getRole/' + roleID);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
getMenuesFromConfig() {
|
||
|
|
return this.apiService.httpGet<RolePermission[]>('/Authentication/getMenuesFromConfig');
|
||
|
|
}
|
||
|
|
|
||
|
|
saveRole(params: Role) {
|
||
|
|
return this.apiService.httpPost<number>('/Authentication/saveRole', params);
|
||
|
|
}
|
||
|
|
|
||
|
|
GetRolePermissionbyUserID() {
|
||
|
|
return this.apiService.httpGet<any>('/Authentication/GetRolePermissionbyUserID');
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
getUserRoles(roletype: EnumRoleType, userID?: number, roleid?: number) {
|
||
|
|
|
||
|
|
const nuserid = this.apiService.getApiDefaultIntData(userID);
|
||
|
|
const nroletype = this.apiService.getApiDefaultIntData(roleid);
|
||
|
|
|
||
|
|
return this.apiService.httpGet<UserRole[]>('/Authentication/getUserRoles/' + roletype + '/'
|
||
|
|
+ nuserid + '/' + nroletype);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
GetEmpUserRole(searchemps: SearchEmployee[]) {
|
||
|
|
|
||
|
|
return this.apiService.httpPost<UserRole[]>('/Authentication/GetEmpUserRole', searchemps);
|
||
|
|
}
|
||
|
|
|
||
|
|
saveUserRole(params: any) {
|
||
|
|
return this.apiService.httpPost<number>('/Authentication/saveUserRole', params);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
GetAllPayrollTypes() {
|
||
|
|
return this.apiService.httpGet<PayrollType[]>('/Authentication/GetAllPayrollTypes');
|
||
|
|
}
|
||
|
|
|
||
|
|
GetPayrollTypesByLoginID(loginID: string) {
|
||
|
|
return this.apiService.httpGet<PayrollType[]>('/Authentication/GetPayrollTypesByLoginID/' + loginID);
|
||
|
|
}
|
||
|
|
GetBenifitsProcessStatus() {
|
||
|
|
return this.apiService.httpGet<PayrollType[]>('/Authentication/GetBenifitsProcessStatus' );
|
||
|
|
}
|
||
|
|
|
||
|
|
getSwitchUserId(usertype: EnumUserType) {
|
||
|
|
return this.apiService.httpGet<any>('/Authentication/getSwitchUserId/'+ usertype);
|
||
|
|
}
|
||
|
|
|
||
|
|
GetPayrollTypeByLoginID() {
|
||
|
|
return this.apiService.httpGet<PayrollType>('/Authentication/GetPayrollTypeByLoginID');
|
||
|
|
}
|
||
|
|
getAdminPayrollTypes() {
|
||
|
|
return this.apiService.httpGet<PayrollType[]>('/Authentication/getAdminPayrollTypes');
|
||
|
|
}
|
||
|
|
|
||
|
|
GetUserAccessType(userid: number) {
|
||
|
|
return this.apiService.httpGet<UserAccessType[]>('/Authentication/GetUserAccessType/' + userid);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
SaveUserAccessType(acesssTypes: UserAccessType[]) {
|
||
|
|
return this.apiService.httpPost<boolean>('/Authentication/SaveUserAccessType', acesssTypes);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
changePassword(userData: any) {
|
||
|
|
return this.apiService.httpPost<any>('/Authentication/changePassword', userData);
|
||
|
|
}
|
||
|
|
|
||
|
|
changePasswordbyAdmin(userData: any) {
|
||
|
|
return this.apiService.httpPost<any>('/Authentication/changePasswordbyAdmin', userData);
|
||
|
|
}
|
||
|
|
|
||
|
|
forgotPassword(data: any) {
|
||
|
|
return this.apiService.httpPost<any>('/Authentication/forgotPassword', data);
|
||
|
|
}
|
||
|
|
|
||
|
|
getVersionNumber() {
|
||
|
|
return this.apiService.httpGet<string>('/Authentication/getVersionNumber');
|
||
|
|
}
|
||
|
|
|
||
|
|
GetUserByLoingID(loginid: string, systemType: EnumSystemType) {
|
||
|
|
return this.apiService.httpGet<User>('/Authentication/GetUserByLoingID/' + loginid + '/' + systemType);
|
||
|
|
}
|
||
|
|
GetUserByID(userid:number) {
|
||
|
|
return this.apiService.httpGet<User>('/Authentication/GetUserByID/' + userid);
|
||
|
|
}
|
||
|
|
//Below code is for Data
|
||
|
|
getUserByUserType(param: any): any {
|
||
|
|
return this.apiService.httpPost<any>('/Authentication/getUserByUserType', param);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
addPermission(param: any) {
|
||
|
|
return this.apiService.httpPost<any>('/Authentication/addPermission', param);
|
||
|
|
}
|
||
|
|
|
||
|
|
loadDataPermission(userid: number, payrolltypeid:number) {
|
||
|
|
return this.apiService.httpGet<DataPermission[]>('/Authentication/loadDataPermission/' + userid + "/" + payrolltypeid);
|
||
|
|
}
|
||
|
|
DeletedataPermission(item:any) {
|
||
|
|
return this.apiService.httpPost<any> ('/Authentication/deletePermission' ,item);
|
||
|
|
}
|
||
|
|
|
||
|
|
getSSOStatus() {
|
||
|
|
return this.apiService.httpGet<any>('/Authentication/getSSOStatus');
|
||
|
|
}
|
||
|
|
GetOperationDate() {
|
||
|
|
return this.apiService.httpGet<Date>('/Authentication/getOperationDate');
|
||
|
|
}
|
||
|
|
}
|