MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / constructor

Method constructor

packages/hydrooj/src/model/user.ts:79–114  ·  view source on GitHub ↗
(udoc: Udoc, dudoc, scope = PERM.PERM_ALL)

Source from the content-addressed store, hash-verified

77 [key: string]: any;
78
79 constructor(udoc: Udoc, dudoc, scope = PERM.PERM_ALL) {
80 this._id = udoc._id;
81
82 this._udoc = udoc;
83 this._dudoc = dudoc;
84 this._salt = udoc.salt;
85 this._hash = udoc.hash;
86 this._regip = udoc.ip?.[0] || '';
87 this._loginip = udoc.loginip;
88 this._files = udoc._files || [];
89 this._tfa = udoc.tfa;
90 this._authenticators = udoc.authenticators || [];
91
92 this.mail = udoc.mail;
93 this.uname = udoc.uname;
94 this.hashType = udoc.hashType || 'hydro';
95 this.priv = udoc.priv;
96 this.regat = udoc.regat;
97 this.loginat = udoc.loginat;
98 this.perm = dudoc.perm || 0n; // This is a fallback for unknown user
99 this.scope = typeof scope === 'string' ? BigInt(scope) : scope;
100 this.role = dudoc.role || 'default';
101 this.domains = udoc.domains || [];
102 this.tfa = !!udoc.tfa;
103 this.authn = !!udoc.authenticators?.length;
104 if (dudoc.group) this.group = dudoc.group;
105 const load = (settings: Record<string, ReturnType<typeof setting.Setting>>, source: any) => {
106 for (const key in settings) {
107 this[key] = source[key] ?? (settings[key].value || system.get(`preference.${key}`));
108 if (settings[key].flag & setting.FLAG_PUBLIC) this._publicFields.push(key);
109 if (settings[key].flag & setting.FLAG_PRIVATE) this._privateFields.push(key);
110 }
111 };
112 load(setting.SETTINGS_BY_KEY, udoc);
113 load(setting.DOMAIN_USER_SETTINGS_BY_KEY, dudoc);
114 }
115
116 async init() {
117 await bus.parallel('user/get', this);

Callers

nothing calls this directly

Calls 1

loadFunction · 0.50

Tested by

no test coverage detected