added sessionId to user
This commit is contained in:
parent
31297d93ae
commit
0385d3ce56
3 changed files with 19 additions and 1 deletions
|
|
@ -56,6 +56,7 @@ export class ContactFormComponent implements OnInit, OnChanges {
|
||||||
color: '',
|
color: '',
|
||||||
status: false,
|
status: false,
|
||||||
lastLogin: 0,
|
lastLogin: 0,
|
||||||
|
sessionId: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,5 @@ export interface User {
|
||||||
color: string;
|
color: string;
|
||||||
status: boolean;
|
status: boolean;
|
||||||
lastLogin: number;
|
lastLogin: number;
|
||||||
|
sessionId: string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ import {
|
||||||
} from '@angular/fire/firestore';
|
} from '@angular/fire/firestore';
|
||||||
import { SharedService } from './shared.service';
|
import { SharedService } from './shared.service';
|
||||||
import { User } from '../interfaces/user.interface';
|
import { User } from '../interfaces/user.interface';
|
||||||
import { NgForm } from '@angular/forms';
|
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
|
|
@ -88,6 +87,7 @@ export class LoginService {
|
||||||
: '',
|
: '',
|
||||||
color: this.sharedService.generateRandomColor(),
|
color: this.sharedService.generateRandomColor(),
|
||||||
lastLogin: new Date().getTime(),
|
lastLogin: new Date().getTime(),
|
||||||
|
sessionId: this.generateRandomString(30),
|
||||||
};
|
};
|
||||||
this.createUserInFirestore(userDataToSave);
|
this.createUserInFirestore(userDataToSave);
|
||||||
})
|
})
|
||||||
|
|
@ -122,6 +122,7 @@ export class LoginService {
|
||||||
initials: firstName.slice(0, 1) + lastName.slice(0, 1),
|
initials: firstName.slice(0, 1) + lastName.slice(0, 1),
|
||||||
color: this.sharedService.generateRandomColor(),
|
color: this.sharedService.generateRandomColor(),
|
||||||
lastLogin: 0,
|
lastLogin: 0,
|
||||||
|
sessionId: this.generateRandomString(30),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.ifExistUser(user.uid);
|
this.ifExistUser(user.uid);
|
||||||
|
|
@ -144,6 +145,7 @@ export class LoginService {
|
||||||
initials: user.initials,
|
initials: user.initials,
|
||||||
color: user.color,
|
color: user.color,
|
||||||
lastLogin: new Date().getTime(),
|
lastLogin: new Date().getTime(),
|
||||||
|
sessionId: this.generateRandomString(30),
|
||||||
};
|
};
|
||||||
const usersCollection = collection(this.firestore, 'users');
|
const usersCollection = collection(this.firestore, 'users');
|
||||||
try {
|
try {
|
||||||
|
|
@ -166,6 +168,7 @@ export class LoginService {
|
||||||
await updateDoc(doc(collection(this.firestore, 'users'), userId), {
|
await updateDoc(doc(collection(this.firestore, 'users'), userId), {
|
||||||
status: status,
|
status: status,
|
||||||
lastLogin: new Date().getTime(),
|
lastLogin: new Date().getTime(),
|
||||||
|
sessionId: this.generateRandomString(30),
|
||||||
});
|
});
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
|
|
@ -187,6 +190,19 @@ export class LoginService {
|
||||||
localStorage.setItem('currentUserJOIN', JSON.stringify(userId));
|
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
|
||||||
|
|
||||||
logout(userId: string) {
|
logout(userId: string) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue