fix(big fix upgrade): upgrade multiple areas of the core functionalities
This commit is contained in:
@@ -28,6 +28,10 @@ export class CloudlyAuthManager {
|
||||
this.cloudlyRef.typedrouter.addTypedRouter(this.typedrouter);
|
||||
}
|
||||
|
||||
public async createNewSecureToken() {
|
||||
return plugins.smartunique.uniSimple('secureToken', 64);
|
||||
}
|
||||
|
||||
public async start() {
|
||||
// lets setup the smartjwtInstance
|
||||
this.smartjwtInstance = new plugins.smartjwt.SmartJwt();
|
||||
@@ -53,6 +57,7 @@ export class CloudlyAuthManager {
|
||||
const user = await User.findUserByUsernameAndPassword(dataArg.username, dataArg.password);
|
||||
if (!user) {
|
||||
logger.log('warn', 'login failed');
|
||||
throw new plugins.typedrequest.TypedResponseError('login failed');
|
||||
} else {
|
||||
jwt = await this.smartjwtInstance.createJWT({
|
||||
userId: user.id,
|
||||
@@ -96,7 +101,7 @@ export class CloudlyAuthManager {
|
||||
});
|
||||
|
||||
public adminIdentityGuard = new plugins.smartguard.Guard<{identity: plugins.servezoneInterfaces.data.IIdentity}>(async (dataArg) => {
|
||||
await plugins.smartexpect.expectAsync(this.validIdentityGuard.exec(dataArg)).toBeTrue();
|
||||
await plugins.smartguard.passGuardsOrReject(dataArg, [this.validIdentityGuard]);
|
||||
const jwt = dataArg.identity.jwt;
|
||||
const jwtData: IJwtData = await this.smartjwtInstance.verifyJWTAndGetData(jwt);
|
||||
const user = await this.CUser.getInstance({id: jwtData.userId});
|
||||
|
||||
@@ -5,6 +5,26 @@ 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: {
|
||||
@@ -14,6 +34,13 @@ export class User extends plugins.smartdata.SmartDataDbDoc<
|
||||
});
|
||||
}
|
||||
|
||||
constructor(optionsArg?: plugins.servezoneInterfaces.data.IUser) {
|
||||
super();
|
||||
if (optionsArg) {
|
||||
Object.assign(this, optionsArg);
|
||||
}
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
@plugins.smartdata.unI()
|
||||
public id: string;
|
||||
|
||||
Reference in New Issue
Block a user