mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 05:16:07 +00:00
add inactivity page
This commit is contained in:
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
|
||||
import { StorageService } from './storage.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { User, UserForm } from '../models/user.model';
|
||||
import { User, UserForm, UserSession } from '../models/user.model';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { HttpService } from './http.service';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
@@ -12,6 +12,7 @@ import { LocalstoreService } from '../store/localstore.service';
|
||||
import { ToastService } from './toast.service';
|
||||
import { UserStore } from 'src/app/store/user.service'
|
||||
import { SHA1, SHA256, AES, enc } from 'crypto-js'
|
||||
import { SessionStore } from '../store/session.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -37,8 +38,8 @@ export class AuthService {
|
||||
|
||||
this.headers = new HttpHeaders();
|
||||
|
||||
if (this.localstoreService.get('user', null) != null) {
|
||||
this.ValidatedUser = this.localstoreService.get('user',{});
|
||||
if (SessionStore.exist) {
|
||||
this.ValidatedUser = SessionStore.user
|
||||
}
|
||||
|
||||
if (localStorage.getItem("userChat") != null) {
|
||||
@@ -63,22 +64,22 @@ export class AuthService {
|
||||
|
||||
try {
|
||||
response = await this.http.post<User>(environment.apiURL + "UserAuthentication/Login", '', this.opts).toPromise();
|
||||
const session: UserSession = Object.assign(new UserSession(), response)
|
||||
|
||||
console.log(response);
|
||||
|
||||
if (response) {
|
||||
if( response.RoleID == 100000014) {
|
||||
response.Profile = 'PR'
|
||||
} else if(response.RoleID == 100000011) {
|
||||
response.Profile = 'MDGPR'
|
||||
if( session.RoleID == 100000014) {
|
||||
session.Profile = 'PR'
|
||||
} else if(session.RoleID == 100000011) {
|
||||
session.Profile = 'MDGPR'
|
||||
}
|
||||
response.BasicAuthKey = user.BasicAuthKey
|
||||
session.BasicAuthKey = user.BasicAuthKey
|
||||
this.ValidatedUser = response;
|
||||
|
||||
// console.log('response', response)
|
||||
|
||||
this.localstoreService.set('user', response)
|
||||
this.userStore.reset(response)
|
||||
console.log('session', session)
|
||||
|
||||
this.userStore.reset(session)
|
||||
SessionStore.reset(session)
|
||||
|
||||
this.storageService.store(AuthConnstants.USER, response);
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { InativityService } from './inativity.service';
|
||||
|
||||
describe('InativityService', () => {
|
||||
let service: InativityService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(InativityService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { SessionStore } from '../store/session.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class InativityService {
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
) {
|
||||
|
||||
var t;
|
||||
window.onload = resetTimer;
|
||||
window.onmousemove = resetTimer;
|
||||
window.onmousedown = resetTimer; // catches touchscreen presses as well
|
||||
window.ontouchstart = resetTimer; // catches touchscreen swipes as well
|
||||
window.onclick = resetTimer; // catches touchpad clicks as well
|
||||
window.onkeydown = resetTimer;
|
||||
window.addEventListener('scroll', resetTimer, true); // improved; see comments
|
||||
|
||||
function userIsNotActive() {
|
||||
// your function for too long inactivity goes here
|
||||
SessionStore.setInativity(false)
|
||||
// alert('go out')
|
||||
window['inactivity/function']()
|
||||
}
|
||||
|
||||
function resetTimer() {
|
||||
clearTimeout(t);
|
||||
t = setTimeout(userIsNotActive, 60000); // time is in milliseconds
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user