added email verification

This commit is contained in:
andrei-mihnea-cerbu
2025-02-04 19:08:34 +02:00
parent 9baec7a7cb
commit dcf505c89b
67 changed files with 3922 additions and 3638 deletions
+137
View File
@@ -0,0 +1,137 @@
import { JsonDatabase } from '../database/database'
import { DatabaseScheme } from '../database/schemes/database_scheme'
import path from 'path'
import { EncryptionKeyScheme, UserInfoScheme } from '../database/schemes/app_config_scheme'
import { FileItemTask } from '../database/helpers/queue_manager'
import { DirectoryInfo, DirectorySchemes } from '../database/schemes/local_resources_scheme'
const pathToDatabaseFile = path.join(__dirname, '..', 'database.json')
class IpcDatabaseHandler {
private readonly db: JsonDatabase<DatabaseScheme, any>
constructor(pathToDatabaseFile: string) {
this.db = new JsonDatabase(pathToDatabaseFile)
}
async getAppType(): Promise<string> {
const data = await this.db.read()
return data.app_config.app_type
}
async getUserInfo(): Promise<UserInfoScheme> {
const data = await this.db.read()
return data.app_config.user_info
}
async getActiveUsers(): Promise<any> {
const data = await this.db.read()
return data.network.usersInLan
}
async getLocalResources(): Promise<DirectorySchemes> {
const data = await this.db.read()
return data.local_resources.directory_schemes
}
async getDirectoryInfo(id: string): Promise<DirectoryInfo> {
const data = await this.db.read()
const directorySchemes = data.local_resources.directory_schemes
switch (id) {
case directorySchemes.backup.id: {
return directorySchemes.backup
}
case directorySchemes.department.id: {
return directorySchemes.department
}
case directorySchemes.shared.id: {
return directorySchemes.shared
}
default: {
throw new Error(`Directory with id ${id} not found`)
}
}
}
async writeDirectoryPath(id: string, path: string): Promise<boolean> {
try {
await this.db.update((data) => {
switch (id) {
case data.local_resources.directory_schemes.backup.id: {
data.local_resources.directory_schemes.backup.path = path
break
}
case data.local_resources.directory_schemes.department.id: {
data.local_resources.directory_schemes.department.path = path
break
}
case data.local_resources.directory_schemes.shared.id: {
data.local_resources.directory_schemes.shared.path = path
break
}
default: {
throw new Error(`Directory with id ${id} not found`)
}
}
return data
})
return true
}
catch (e) {
return false
}
}
async isBackupSet(): Promise<boolean> {
const data = await this.db.read()
return data.local_resources.directory_schemes.backup.path !== ''
}
async writeUserInfo(userInfo: UserInfoScheme): Promise<boolean> {
await this.db.update((data) => {
data.app_config.user_info = userInfo
return data
})
return true
}
async writeEncryptionKey(encryptionKey: EncryptionKeyScheme): Promise<boolean> {
await this.db.update((data) => {
data.app_config.encryption_key = encryptionKey
return data
})
return true
}
async setLoginStatus(status: boolean): Promise<boolean> {
await this.db.update((data) => {
data.app_config.logged_in = status
return data
})
return true
}
async addTaskToSendFileQueue(task: FileItemTask) {
this.db.pushQueue(task)
}
async resetInternalDatabase(): Promise<boolean> {
await this.db.reset()
return true
}
}
export const ipcDatabaseHandler = new IpcDatabaseHandler(pathToDatabaseFile)
+60
View File
@@ -0,0 +1,60 @@
import { TcpCommunicator } from '../helpers/tcp_communicator'
import dotenv from 'dotenv'
import path from 'path'
import { JsonDatabase } from '../database/database'
import { DatabaseScheme } from '../database/schemes/database_scheme'
import { operationCodes } from '../network/operation_codes'
dotenv.config({ path: path.join(__dirname, '..', '..', '.env') })
const pathToDatabaseFile = path.join(__dirname, '..', 'database.json')
class IpcUCHandler {
private readonly TCP_PORT: number
private readonly db: JsonDatabase<DatabaseScheme, any>
private tcpCommunicator: TcpCommunicator | null = null
constructor(pathToDatabaseFile: string) {
this.TCP_PORT = process.env.TCP_PORT ? parseInt(process.env.TCP_PORT) : 41234
this.db = new JsonDatabase(pathToDatabaseFile)
}
async openUcSocket(): Promise<boolean> {
if (!this.db) throw new Error('TcpMethods is not initialized.')
const data = await this.db.read()
const serverIp = data.network.serverIp
this.tcpCommunicator = new TcpCommunicator(serverIp, this.TCP_PORT)
return await this.tcpCommunicator.connect()
}
async sendUcMessage(
operationCode: string,
metaInfo?: { [key: string]: any },
fileContent?: Buffer,
) {
if (!this.tcpCommunicator) throw new Error('TcpMethods is not initialized.')
return await this.tcpCommunicator.sendMessage(operationCode, metaInfo, fileContent)
}
async hasResponseArrived() {
if (!this.tcpCommunicator) throw new Error('TcpMethods is not initialized.')
return this.tcpCommunicator.hasResponseArrived()
}
async getLastUcResult() {
if (!this.tcpCommunicator) throw new Error('TcpMethods is not initialized.')
return this.tcpCommunicator.getLastResult()
}
async closeUcSocket() {
if (!this.tcpCommunicator) throw new Error('TcpMethods is not initialized.')
return await this.tcpCommunicator.disconnect()
}
async getOperationsCodes(): Promise<{ [key: string]: string }> {
return operationCodes
}
}
export const ipcUCHandler = new IpcUCHandler(pathToDatabaseFile)
View File