import { ROOT_ID } from "./main"; import Crypto, { SHA256_String } from "../crypto/generate"; import wrap, { type WrapResult } from "./wrap"; const enum SysGroups { Wheel, Users, } const enum GroupSearch { NotFound, WheelResult, UsersResult, } type WrapUserSearch = WrapResult const wheel: User[] = [] const users: User[] = [] function wrap_user_search(status: GroupSearch, result?: User): WrapUserSearch { return wrap(result, status) } function groups_find_user(user_name: string): WrapUserSearch { const exist_in_wheel = wheel.find(user => user.get_uname() === user_name) if (exist_in_wheel) { return wrap_user_search(GroupSearch.WheelResult, exist_in_wheel) } const exist_in_users = users.find(user => user.get_uname() === user_name) if (exist_in_users) { return wrap_user_search(GroupSearch.UsersResult, exist_in_users) } return wrap_user_search(GroupSearch.NotFound) } function group_add(new_user: User, group: User[]): GroupSearch { const dups = groups_find_user(new_user.get_uname()) if (dups.status === GroupSearch.NotFound) { group.push(new_user) } return dups.status } function group_remove(user_name: string, group: User[]): boolean { for (let i = 0; i { if (new_password) { this.password = await new Crypto(new_password).sha256_string() } else { this.password = undefined } } } export default User export { group_wheel_remove, group_users_remove, group_wheel_add, group_users_add, SysGroups, }