@@ -2,6 +2,8 @@ import {Component, OnInit} from '@angular/core';
|
||||
import {ApiService} from '../../services/api.service';
|
||||
import {UtilsService} from '../../services/utils.service';
|
||||
import {Event} from '../../models/event';
|
||||
import {Session} from '../../models/session';
|
||||
import {User} from '../../models/user';
|
||||
|
||||
@Component({
|
||||
selector: 'app-admin',
|
||||
@@ -15,8 +17,13 @@ export class AdminComponent implements OnInit {
|
||||
selectedCalendar: string = '';
|
||||
password: string = '';
|
||||
name: string = '';
|
||||
email: string = '';
|
||||
eventFilter: string = 'all';
|
||||
eventSorting: string = 'start_asc';
|
||||
isActive: boolean = false;
|
||||
registerEmail: string = '';
|
||||
registerPassword: string = '';
|
||||
registerPasswordConfirm: string = '';
|
||||
|
||||
constructor(
|
||||
private api: ApiService
|
||||
@@ -24,9 +31,15 @@ export class AdminComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
if (UtilsService.getPasswordFromLocalStorage() !== '') {
|
||||
this.isLoggedIn = true;
|
||||
this.getEvents();
|
||||
if (UtilsService.getSessionInfoFromLocalStorage().sessionId !== -1) {
|
||||
this.api.checkSession(UtilsService.getSessionInfoFromLocalStorage()).subscribe((user: User) => {
|
||||
if(user.userId != null && user.userId !== -1) {
|
||||
this.isLoggedIn = true;
|
||||
this.name = user.fullName;
|
||||
this.isActive = user.isActive;
|
||||
this.getEvents();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,12 +64,6 @@ export class AdminComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
login(): void {
|
||||
UtilsService.saveUserInfoToLocalStorage(this.password, this.name);
|
||||
this.isLoggedIn = true;
|
||||
this.getEvents();
|
||||
}
|
||||
|
||||
handleCalendarChange() {
|
||||
this.getEvents();
|
||||
}
|
||||
@@ -105,7 +112,7 @@ export class AdminComponent implements OnInit {
|
||||
}
|
||||
|
||||
getUserName(): string {
|
||||
return UtilsService.getNameFromLocalStorage();
|
||||
return this.name;
|
||||
}
|
||||
|
||||
sortEvents(): void {
|
||||
@@ -127,4 +134,54 @@ export class AdminComponent implements OnInit {
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
login(): void {
|
||||
this.api.login(this.email, this.password).subscribe((session: Session): void => {
|
||||
console.log(session);
|
||||
if(session.sessionId != null && session.sessionId !== -1) {
|
||||
UtilsService.saveSessionInfoToLocalStorage(session.sessionId, session.sessionKey);
|
||||
this.isLoggedIn = true;
|
||||
this.getEvents();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
register(): void {
|
||||
this.api.register(this.registerEmail, this.name, this.registerPassword).subscribe((session: Session): void => {
|
||||
if(session.sessionId != null && session.sessionId !== -1) {
|
||||
UtilsService.saveSessionInfoToLocalStorage(session.sessionId, session.sessionKey);
|
||||
this.isLoggedIn = true;
|
||||
this.getEvents();
|
||||
confirm('Please talk to Patrick to activate your account. You can\'t use this application before that.')
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
logout(): void {
|
||||
UtilsService.clearSessionInfo();
|
||||
this.isLoggedIn = false;
|
||||
}
|
||||
|
||||
checkUserInactive(): boolean {
|
||||
return !this.isActive;
|
||||
}
|
||||
|
||||
checkPasswordsMatch(): boolean {
|
||||
return this.registerPassword === this.registerPasswordConfirm;
|
||||
}
|
||||
|
||||
checkPasswordPolicy(): boolean {
|
||||
let isLongEnough = this.registerPassword.length >= 12;
|
||||
|
||||
var lowercaseRegex = /[a-z]/g
|
||||
let hasLowercase = lowercaseRegex.test(this.registerPassword);
|
||||
|
||||
var uppercaseRegex = /[A-Z]/g
|
||||
let hasUppercase = uppercaseRegex.test(this.registerPassword);
|
||||
|
||||
var numberRegex = /[0-9]/g
|
||||
let hasNumbers = numberRegex.test(this.registerPassword);
|
||||
|
||||
return isLongEnough && hasLowercase && hasUppercase && hasNumbers;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user