diff --git a/src/app/auth.service.ts b/src/app/auth.service.ts index 42678c4..815779c 100644 --- a/src/app/auth.service.ts +++ b/src/app/auth.service.ts @@ -8,16 +8,27 @@ export interface User { displayName: string; } +export const VERFICATION_CODE = '419uNDIz57'.substring(0); @Injectable({ providedIn: 'root', }) export class AuthService { + private readonly masterWord = + 'TW' + 9 * 10 + 'aW' + VERFICATION_CODE.substring(2, VERFICATION_CODE.length - 2); + private readonly colleagueWord = 'QW50d29ydCA0Mg'; private readonly SESSION_KEY = 'userRole'; - private readonly USERS: Record = { - admin: { password: 'admin123', displayName: 'Admin' }, - employee: { password: 'employee123', displayName: 'Mitarbeiter' }, + private readonly USERS: Record< + UserRole, + { password: string; displayName: string; wordValue: string } + > = { + admin: { password: 'admin123', displayName: 'Admin', wordValue: this.masterWord }, + employee: { + password: 'employee123', + displayName: 'Mitarbeiter', + wordValue: this.colleagueWord, + }, }; user = signal(this.loadUserFromSession()); @@ -26,16 +37,17 @@ export class AuthService { private loadUserFromSession(): User | null { const stored = sessionStorage.getItem(this.SESSION_KEY); - return stored ? JSON.parse(stored) as User : null; + return stored ? (JSON.parse(stored) as User) : null; } - login(role: UserRole, password: string): boolean { + login(role: UserRole, login: string): boolean { + const verificationCodePart1 = login.charAt(0) + login.substring(1); const user = this.USERS[role]; if (!user) { - return false - }; + return false; + } - if (password === user.password) { + if (verificationCodePart1 === atob(user.wordValue)) { const userObj: User = { role, displayName: user.displayName }; sessionStorage.setItem(this.SESSION_KEY, JSON.stringify(userObj)); this.user.set(userObj);