remove chat data and ownerCalendar

This commit is contained in:
Peter Maquiran
2024-11-06 08:24:37 +01:00
parent 52d333ad16
commit ecb2f6c08e
39 changed files with 1845 additions and 264 deletions
@@ -0,0 +1,135 @@
import { Injectable } from '@angular/core';
import { UserEntity } from 'src/app/core/user/entity/userEntity';
import { SHA1 } from 'crypto-js'
import { localstoreService } from 'src/app/store/localstore.service';
import { Preference } from 'src/app/core/user/entity/preference';
@Injectable({
providedIn: 'root'
})
export class SessionService {
user?:UserEntity
preference = new Preference()
forceToLoginWithForceToLogInWithPassword = false
private keyName: string;
constructor() {
if(this.exist) {
this.keyName = (SHA1("")).toString()
let restore: any = this.getDataFromLocalStorage()
if(restore?.user) {
this.user = new UserEntity(restore.user)
}
if(this.preference.LoginPreference == 'Pin') {
this.preference.Inactivity = false
}
}
}
getDataFromLocalStorage() {
return localstoreService.get(this.keyName, {}).user as UserEntity
}
get exist() {
let restore = localstoreService.get(this.keyName, {})
let user: UserEntity = restore.user
if(user) {
if(user.Profile) {
console.log('exist')
return true
}
}
console.log('exist not', restore)
return false
}
setLoginPreference(loginPreference: 'None' | 'Password' | 'Pin' | null) {
this.preference.LoginPreference = loginPreference
this.save()
}
setPin(pin: string) {
this.preference.PIN = SHA1(pin).toString()
this.save()
}
validatePin(pin: string) {
return this.preference.PIN == SHA1(pin).toString()
}
needToValidateUser() {
return this.preference.Inactivity
}
isUserActive() {
return this.preference.Inactivity
}
setInativity(value: boolean) {
this.preference.Inactivity = value
this.preference.UrlBeforeInactivity = ''
this.save()
}
setUrlBeforeInactivity(pathname: string) {
this.preference.UrlBeforeInactivity = pathname
this.save()
}
get hasPin() {
if(!this.preference.PIN) {
return false
}
return this.preference.PIN.length >= 2
}
reset(user) {
console.log('reset')
console.log('user', user)
this.user = user
this.setInativity(true)
this.save()
}
delete() {
console.log('edeletet')
localstoreService.delete(this.keyName)
this.preference = new Preference()
delete this.user
}
save() {
console.log('save')
localstoreService.set(this.keyName, {
user: this.user,
preference: this.preference
})
}
get getInitials() {
let names = this.user.wxFullName.split(' ') || ' ',
initials = names[0].substring(0, 1).toUpperCase();
if (names.length > 1) {
initials += names[names.length - 1].substring(0, 1).toUpperCase();
}
return initials;
}
}
export const SessionStore = new SessionService()
@@ -0,0 +1,26 @@
import { Injectable } from '@angular/core';
import { IUserRemoteRepository } from 'src/app/core/user/repository/user-remote-repository';
import { UserLoginInput, UserLoginUseCaseService } from 'src/app/core/user/use-case/user-login-use-case.service';
import { SessionStore } from './service/session.service'
import { UserEntity } from 'src/app/core/user/entity/userEntity';
@Injectable({
providedIn: 'root'
})
export class UserService {
constructor(
private userLoginUseCaseService: UserLoginUseCaseService,
) { }
async login(input: UserLoginInput) {
const result = await this.userLoginUseCaseService.execute(input)
if(result.isOk()) {
SessionStore.reset(new UserEntity({...result.value, ...result.value.user}))
}
return result
}
}
+27
View File
@@ -0,0 +1,27 @@
import { NgModule } from '@angular/core';
import { HttpModule } from 'src/app/infra/http/http.module';
import { IUserRemoteRepository } from 'src/app/core/user/repository/user-remote-repository';
import { UserRemoteRepositoryService } from './data/datasource/user-remote-repository.service';
import { UserService } from './domain/user.service'
@NgModule({
imports: [HttpModule],
providers: [
{
provide: IUserRemoteRepository,
useClass: UserRemoteRepositoryService, // or MockDataService
},
],
declarations: [],
schemas: [],
entryComponents: [
]
})
export class UserModule {
constructor(
private UserService:UserService
) {}
}