|
|
@@ -95,23 +95,35 @@ module.exports = class UserService extends Schmervice.Service {
|
|
95
|
95
|
if (matchingEmails.length > 0) {
|
|
96
|
96
|
throw `User ${userInfo.user_email} already exists: Cannot create a user without a unique email`
|
|
97
|
97
|
}
|
|
|
98
|
+ // const todayTest = new Date.now()
|
|
|
99
|
+ console.log("password passed to .signup()", password)
|
|
|
100
|
+ const steak = process.env.PEPPER+password
|
|
|
101
|
+ console.log("steak", steak)
|
|
|
102
|
+ console.log("user_email", userInfo.user_email)
|
|
98
|
103
|
|
|
99
|
|
- // Library: Secure-Password
|
|
100
|
|
- const pepper = process.env.PEPPER
|
|
101
|
|
-
|
|
102
|
|
- // add pepper to pw and convert to buffer to prep for hash bytes
|
|
103
|
|
- const steak = Buffer.from(password + pepper, 'utf-8')
|
|
104
|
|
-
|
|
105
|
|
- // send peppered pw to (argon algorithm) library for salted hash
|
|
106
|
|
- const hashed = await hasher(this.pwd, steak)
|
|
107
|
|
- console.log("hashed", hashed)
|
|
108
|
|
-
|
|
109
|
|
- const newAuth = await Auth.query(txn).insert({
|
|
|
104
|
+ const { email } = await Auth.query(txn).insert({
|
|
110
|
105
|
user_email: userInfo.user_email,
|
|
111
|
106
|
created_at: new Date.now(),
|
|
112
|
|
- token: hashed,
|
|
113
|
107
|
})
|
|
114
|
|
- console.log("newAuth", newAuth)
|
|
|
108
|
+ await this.changePassword(email, steak, txn)
|
|
|
109
|
+ return userInfo.user_email
|
|
|
110
|
+ console.log("signup return finished")
|
|
|
111
|
+ // Library: Secure-Password
|
|
|
112
|
+ // console.log('data type of create_at', )
|
|
|
113
|
+ // add pepper to pw and convert to buffer to prep for hash bytes
|
|
|
114
|
+ // const steak = Buffer.from(password + pepper, 'utf-8')
|
|
|
115
|
+ // console.log("steak", steak)
|
|
|
116
|
+ // send peppered pw to (argon algorithm) library for salted hash
|
|
|
117
|
+ // hashed is actually for logging in
|
|
|
118
|
+ // const hashed = await hasher(this.pwd, steak)
|
|
|
119
|
+ // console.log("hashed", hashed)
|
|
|
120
|
+ // console.log ("user_email", userInfo.user_email)
|
|
|
121
|
+ // const newAuth = await Auth.query(txn).insert({
|
|
|
122
|
+ // user_email: userInfo.user_email,
|
|
|
123
|
+ // created_at: new Date.now(),
|
|
|
124
|
+ // token: steak,
|
|
|
125
|
+ // })
|
|
|
126
|
+ // console.log("newAuth", newAuth)
|
|
115
|
127
|
// return newAuth
|
|
116
|
128
|
|
|
117
|
129
|
// const user = await User.query(txn).insert(userInfo)
|
|
|
@@ -202,10 +214,19 @@ module.exports = class UserService extends Schmervice.Service {
|
|
202
|
214
|
* @param {*} txn
|
|
203
|
215
|
* @returns {number}
|
|
204
|
216
|
*/
|
|
205
|
|
- async changePassword(id, password, txn) {
|
|
206
|
|
- const { User } = this.server.models()
|
|
207
|
|
- return 'done'
|
|
208
|
|
- // rework with Auth model
|
|
|
217
|
+ async changePassword(email, password, txn) {
|
|
|
218
|
+ const { User, Auth } = this.server.models()
|
|
|
219
|
+
|
|
|
220
|
+ await Auth.query(txn)
|
|
|
221
|
+ .throwIfNotFound()
|
|
|
222
|
+ .where({ email })
|
|
|
223
|
+ .patch({
|
|
|
224
|
+ // user_email: email,
|
|
|
225
|
+ token: await this.pwd.hash(Buffer.from(password)),
|
|
|
226
|
+ })
|
|
|
227
|
+ console.log("changed pw return", email)
|
|
|
228
|
+ console.log("token created in changePassword", this.pwd.hash(Buffer.from(password)))
|
|
|
229
|
+ return email
|
|
209
|
230
|
|
|
210
|
231
|
// await User.query(txn)
|
|
211
|
232
|
// .throwIfNotFound()
|