Skip to content

Commit f3279f6

Browse files
authored
feat: forgot password (#24)
* make login/reg pages look like openai's * add password reset data services * new form designs similar to openai, add password reset pages * add api's for password reset * email utils for password reset * remove bcrypt salt rounds from process.env
1 parent 4579264 commit f3279f6

27 files changed

+1644
-492
lines changed

api/models/User.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,23 +167,14 @@ userSchema.methods.comparePassword = function (candidatePassword, callback) {
167167
};
168168

169169
module.exports.hashPassword = async (password) => {
170-
const saltRounds = 10;
171170

172171
const hashedPassword = await new Promise((resolve, reject) => {
173-
bcrypt.hash(password, saltRounds, function (err, hash) {
172+
bcrypt.hash(password, 10, function (err, hash) {
174173
if (err) reject(err);
175174
else resolve(hash);
176175
});
177176
});
178177

179-
log({
180-
title: 'Hash Password',
181-
parameters: [
182-
{ name: 'password', value: password },
183-
{ name: 'hashed password', value: hashedPassword }
184-
]
185-
});
186-
187178
return hashedPassword;
188179
};
189180

api/models/schema/tokenSchema.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const mongoose = require("mongoose");
2+
const Schema = mongoose.Schema;
3+
4+
const tokenSchema = new Schema({
5+
userId: {
6+
type: Schema.Types.ObjectId,
7+
required: true,
8+
ref: "user",
9+
},
10+
token: {
11+
type: String,
12+
required: true,
13+
},
14+
createdAt: {
15+
type: Date,
16+
required: true,
17+
default: Date.now,
18+
expires: 900,
19+
},
20+
});
21+
22+
module.exports = mongoose.model("Token", tokenSchema);

0 commit comments

Comments
 (0)