Skip to content

Commit

Permalink
Merge pull request #9 from OurFreeLight/dev
Browse files Browse the repository at this point in the history
0.4.8 merge
  • Loading branch information
ncoonrod committed Jan 25, 2024
2 parents 494f57c + 3d7cd65 commit 251ad3a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 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.4.6",
"version": "0.4.8",
"main": "build/src/index.js",
"scripts": {
"test": "hotstaq --dev --env-file .env run --server-type api --api-test",
Expand Down
17 changes: 16 additions & 1 deletion src/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ export class User implements IUser
*/
async register (db: HotDBMySQL, emailConfig: EmailConfig = null, verifyCode: string = ""): Promise<User>
{
this.email = this.email.toLowerCase ();

let tempUser: User | null = await User.getUser (db, this.email);

if (tempUser != null)
Expand Down Expand Up @@ -421,7 +423,7 @@ 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, verificationCode, verified]);
[this.userType, this.displayName, this.firstName, this.lastName, this.email, hash, salt, this.verifyCode, verified]);

if (result.error != null)
throw new Error (result.error);
Expand Down Expand Up @@ -505,9 +507,16 @@ export class User implements IUser
let foundUser: User = null;

if (typeof (ip) === "string")
{
email = email.toLowerCase ();

foundUser = await User.getUser (db, email, true);
}
else
{
foundUser = ip;
foundUser.email = foundUser.email.toLowerCase ();
}

if (foundUser == null)
throw new Error (`Wrong email or password.`);
Expand Down Expand Up @@ -640,6 +649,12 @@ export class User implements IUser
*/
static async changePassword (db: HotDBMySQL, user: User, newPassword: string): Promise<void>
{
if (newPassword === "")
throw new Error (`New password cannot be empty!`);

if (user.id === "")
throw new Error (`No user id supplied!`);

const salt: string = await User.generateSalt ();
const hash: string = await User.generateHash (newPassword, salt);

Expand Down
2 changes: 1 addition & 1 deletion src/UserRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export class UserRoute extends HotRoute

await newUser.register (this.db, emailConfig, verifyCodeOverride);

req.passObject.passType = PassType.Update;
req.passObject.passType = PassType.Ignore;
req.passObject.jsonObj = { verifyCode: newUser.verifyCode, user: newUser };

newUser.verifyCode = "";
Expand Down

0 comments on commit 251ad3a

Please sign in to comment.