From 0385d3ce5678a400b872b595bdd9fbb3404cc55b Mon Sep 17 00:00:00 2001 From: Chneemann Date: Fri, 24 May 2024 07:52:45 +0200 Subject: [PATCH] added sessionId to user --- .../contact-form/contact-form.component.ts | 1 + src/app/interfaces/user.interface.ts | 1 + src/app/services/login.service.ts | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.ts b/src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.ts index 63ade57..d0ea302 100644 --- a/src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.ts +++ b/src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.ts @@ -56,6 +56,7 @@ export class ContactFormComponent implements OnInit, OnChanges { color: '', status: false, lastLogin: 0, + sessionId: '', }; ngOnInit() { diff --git a/src/app/interfaces/user.interface.ts b/src/app/interfaces/user.interface.ts index c631ff3..59743d0 100644 --- a/src/app/interfaces/user.interface.ts +++ b/src/app/interfaces/user.interface.ts @@ -9,4 +9,5 @@ export interface User { color: string; status: boolean; lastLogin: number; + sessionId: string; } diff --git a/src/app/services/login.service.ts b/src/app/services/login.service.ts index 35ee6c5..5e0491a 100644 --- a/src/app/services/login.service.ts +++ b/src/app/services/login.service.ts @@ -21,7 +21,6 @@ import { } from '@angular/fire/firestore'; import { SharedService } from './shared.service'; import { User } from '../interfaces/user.interface'; -import { NgForm } from '@angular/forms'; import { Router } from '@angular/router'; @Injectable({ providedIn: 'root', @@ -88,6 +87,7 @@ export class LoginService { : '', color: this.sharedService.generateRandomColor(), lastLogin: new Date().getTime(), + sessionId: this.generateRandomString(30), }; this.createUserInFirestore(userDataToSave); }) @@ -122,6 +122,7 @@ export class LoginService { initials: firstName.slice(0, 1) + lastName.slice(0, 1), color: this.sharedService.generateRandomColor(), lastLogin: 0, + sessionId: this.generateRandomString(30), }); } else { this.ifExistUser(user.uid); @@ -144,6 +145,7 @@ export class LoginService { initials: user.initials, color: user.color, lastLogin: new Date().getTime(), + sessionId: this.generateRandomString(30), }; const usersCollection = collection(this.firestore, 'users'); try { @@ -166,6 +168,7 @@ export class LoginService { await updateDoc(doc(collection(this.firestore, 'users'), userId), { status: status, lastLogin: new Date().getTime(), + sessionId: this.generateRandomString(30), }); window.location.reload(); } @@ -187,6 +190,19 @@ export class LoginService { localStorage.setItem('currentUserJOIN', JSON.stringify(userId)); } + generateRandomString(length: number): string { + const characters = + 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+{}:"<>?|[];\',./`~'; + let result = ''; + const charactersLength = characters.length; + + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * charactersLength)); + } + + return result; + } + // LOGOUT logout(userId: string) {