Skip to content

Commit

Permalink
fix: corrected user enabling/disabling;
Browse files Browse the repository at this point in the history
  • Loading branch information
ncoonrod committed Apr 4, 2024
1 parent ab29f15 commit bf9e369
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hotstaq/userroute",
"description": "A user route for HotStaq. Allows users to be created/edited/deleted securely.",
"version": "0.5.3",
"version": "0.5.4",
"main": "build/src/index.js",
"scripts": {
"test": "hotstaq --dev --env-file .env run --server-type api --api-test",
Expand Down
12 changes: 6 additions & 6 deletions src/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ export class User implements IUser
}

let result: any = await db.queryOne (
`INSERT INTO users (id, userType, displayName, firstName, lastName, email, password, passwordSalt, verifyCode, verified)
VALUES (UNHEX(REPLACE(UUID(),'-','')), ?, ?, ?, ?, ?, ?, ?, ?, ?) returning id;`,
[this.userType, this.displayName, this.firstName, this.lastName, this.email, hash, salt, this.verifyCode, verified]);
`INSERT INTO users (id, userType, displayName, firstName, lastName, email, password, passwordSalt, verifyCode, verified, enabled)
VALUES (UNHEX(REPLACE(UUID(),'-','')), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) returning id;`,
[this.userType, this.displayName, this.firstName, this.lastName, this.email, hash, salt, this.verifyCode, verified, this.enabled]);

if (result.error != null)
throw new Error (result.error);
Expand Down Expand Up @@ -553,14 +553,14 @@ export class User implements IUser
}

/**
* Edit a user. Intended for admin usage. DOES NOT check any JWT tokens
* Edit a user. Intended for admin usage or the user trying to edit their account. THIS DOES NOT check any JWT tokens
* or any other user permissions.
*/
static async editUser (db: HotDBMySQL, user: User): Promise<void>
{
let result: any = await db.queryOne (
`UPDATE users SET userType = ?, displayName = ?, firstName = ?, lastName = ?, email = ?, verified = ? WHERE id = UNHEX(REPLACE(?, '-', ''));`,
[user.userType, user.displayName, user.firstName, user.lastName, user.email, user.verified, user.id]);
`UPDATE users SET userType = ?, displayName = ?, firstName = ?, lastName = ?, email = ?, verified = ?, enabled = ? WHERE id = UNHEX(REPLACE(?, '-', ''));`,
[user.userType, user.displayName, user.firstName, user.lastName, user.email, user.verified, user.enabled, user.id]);

if (result.error != null)
throw new Error (result.error);
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { UserRoute } from './UserRoute';
import { AdminRoute } from './AdminRoute';
import { IUser, User, IJWTToken } from './User';
import { IUser, User, IJWTToken, EmailConfig } from './User';

export {
UserRoute,
AdminRoute,
IUser,
IJWTToken,
User
User,
EmailConfig
};

0 comments on commit bf9e369

Please sign in to comment.