Skip to content

Commit

Permalink
update password reset functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mpfeil committed Sep 25, 2024
1 parent f90bec2 commit 64ff906
Show file tree
Hide file tree
Showing 8 changed files with 634 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/api/lib/controllers/usersController.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const { User } = require('@sensebox/opensensemap-api-models'),
refreshJwt,
invalidateToken,
} = require('../helpers/jwtHelpers');
const { createUser, findUserByNameOrEmail, checkPassword } = require('@sensebox/opensensemap-api-models/src/user/user');
const { createUser, findUserByNameOrEmail, checkPassword, initPasswordReset } = require('@sensebox/opensensemap-api-models/src/user/user');

/**
* define for nested user parameter for box creation request
Expand Down Expand Up @@ -188,7 +188,7 @@ const signOut = async function signOut (req, res) {
// generate new password reset token and send the token to the user
const requestResetPassword = async function requestResetPassword (req, res) {
try {
await User.initPasswordReset(req._userParams);
await initPasswordReset(req._userParams);
res.send(200, { code: 'Ok', message: 'Password reset initiated' });
} catch (err) {
return handleError(err);
Expand Down
12 changes: 12 additions & 0 deletions packages/models/migrations/0002_add_password_reset_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE TABLE IF NOT EXISTS "password_reset" (
"user_id" text NOT NULL,
"token" text NOT NULL,
"expires_at" timestamp NOT NULL,
CONSTRAINT "password_reset_user_id_unique" UNIQUE("user_id")
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "password_reset" ADD CONSTRAINT "password_reset_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
Loading

0 comments on commit 64ff906

Please sign in to comment.