f40ef6b7c0
Align Cloudly with the current typedserver, smartconfig, smartstate, and Docker tooling releases so builds and Docker output stay compatible with the upgraded stack.
53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import * as plugins from '../plugins.js';
|
|
|
|
@plugins.smartdata.managed()
|
|
export class User extends plugins.smartdata.SmartDataDbDoc<
|
|
User,
|
|
plugins.servezoneInterfaces.data.IUser
|
|
> {
|
|
/**
|
|
* creates a machine user
|
|
*/
|
|
public static async createMachineUser(userNameArg: string, roleArg: 'api' | 'cluster') {
|
|
const user = new User();
|
|
user.id = await User.getNewId();
|
|
user.data = {
|
|
type: 'machine',
|
|
username: userNameArg,
|
|
tokens: [
|
|
{
|
|
token: 'machineUser',
|
|
expiresAt: Date.now() + 3600 * 1000 * 24 * 365,
|
|
assignedRoles: ['admin'],
|
|
},
|
|
],
|
|
role: 'api',
|
|
};
|
|
await user.save();
|
|
return user;
|
|
}
|
|
|
|
public static async findUserByUsernameAndPassword(usernameArg: string, passwordArg: string) {
|
|
return await User.getInstance({
|
|
data: {
|
|
username: usernameArg,
|
|
password: passwordArg,
|
|
},
|
|
});
|
|
}
|
|
|
|
constructor(optionsArg?: plugins.servezoneInterfaces.data.IUser) {
|
|
super();
|
|
if (optionsArg) {
|
|
Object.assign(this, optionsArg);
|
|
}
|
|
}
|
|
|
|
// INSTANCE
|
|
@plugins.smartdata.unI()
|
|
public id!: string;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public data!: plugins.servezoneInterfaces.data.IUser['data'];
|
|
}
|