mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: user: private and public projection (#507)
This commit is contained in:
1 parent
4fe734a6f3
commit
bd13c57d82
6 files changed
+44
-26
No files matched your search
@@ -7,6 +7,7 @@ import {
|
||||
ownerInfo, Udict, Udoc, VUdoc,
|
||||
} from '../interface';
|
||||
import pwhash from '../lib/hash.hydro';
|
||||
import serializer from '../lib/serializer';
|
||||
import * as bus from '../service/bus';
|
||||
import db from '../service/db';
|
||||
import { Value } from '../typeutils';
|
||||
@@ -47,6 +48,7 @@ bus.on('user/delcache', (content) => deleteUserCache(typeof content === 'string'
|
||||
|
||||
export class User {
|
||||
_id: number;
|
||||
_isPrivate = false;
|
||||
|
||||
_udoc: Udoc;
|
||||
_dudoc: any;
|
||||
@@ -149,6 +151,21 @@ export class User {
|
||||
UserModel.setPassword(this._id, password);
|
||||
}
|
||||
}
|
||||
|
||||
async private() {
|
||||
const user = await new User(this._udoc, this._dudoc, this.scope).init();
|
||||
user._isPrivate = true;
|
||||
return user;
|
||||
}
|
||||
|
||||
serialize(options) {
|
||||
if (!this._isPrivate) {
|
||||
const fields = ['_id', 'uname', 'mail', 'perm', 'role', 'priv', 'regat', 'loginat', 'tfa', 'authn'];
|
||||
if (options.showDisplayName) fields.push('displayName');
|
||||
return pick(this, fields);
|
||||
}
|
||||
return JSON.stringify(this, serializer({ showDisplayName: options.showDisplayName }, true));
|
||||
}
|
||||
}
|
||||
|
||||
function handleMailLower(mail: string) {
|
||||
|
||||
Reference in new issue
Block a user