@mjhls/mjh-framework 1.0.1002 → 1.0.1003

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # mjh-framework v. 1.0.1002
1
+ # mjh-framework v. 1.0.1003
2
2
 
3
3
  [![NPM](https://img.shields.io/npm/v/mjh-framework.svg)](https://www.npmjs.com/package/mjh-framework) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
4
4
 
@@ -200,68 +200,145 @@ var authenticateUser = function () {
200
200
  return _ref3.apply(this, arguments);
201
201
  };
202
202
  }();
203
+ var authenticateUserByForm = function () {
204
+ var _ref4 = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee4(email, password, form_name) {
205
+ var secret = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'fnAEG3Bb7AACAC0BiSQFYGBLFUtHjn3QOTKE1iBX';
206
+ var client, result, hashedPassword, isAuth;
207
+ return asyncToGenerator.regenerator.wrap(function _callee4$(_context4) {
208
+ while (1) {
209
+ switch (_context4.prev = _context4.next) {
210
+ case 0:
211
+ _context4.prev = 0;
212
+ client = new faunadb.Client({ secret: secret });
213
+ _context4.next = 4;
214
+ return client.query(q.Get(q.Match(q.Index('Email_and_FormName'), [email, form_name])));
215
+
216
+ case 4:
217
+ result = _context4.sent;
218
+ hashedPassword = result.data.Password;
219
+ _context4.next = 8;
220
+ return comparePassword(password, hashedPassword);
221
+
222
+ case 8:
223
+ isAuth = _context4.sent;
224
+ return _context4.abrupt('return', isAuth ? { email: email } : false);
225
+
226
+ case 12:
227
+ _context4.prev = 12;
228
+ _context4.t0 = _context4['catch'](0);
229
+
230
+ console.log(_context4.t0);
231
+ return _context4.abrupt('return', false);
232
+
233
+ case 16:
234
+ case 'end':
235
+ return _context4.stop();
236
+ }
237
+ }
238
+ }, _callee4, this, [[0, 12]]);
239
+ }));
240
+
241
+ return function authenticateUserByForm(_x8, _x9, _x10) {
242
+ return _ref4.apply(this, arguments);
243
+ };
244
+ }();
245
+
246
+ var findUserByEmailAndForm = function () {
247
+ var _ref5 = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee5(email, form_name) {
248
+ var secret = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'fnAEG3Bb7AACAC0BiSQFYGBLFUtHjn3QOTKE1iBX';
249
+ var client, result;
250
+ return asyncToGenerator.regenerator.wrap(function _callee5$(_context5) {
251
+ while (1) {
252
+ switch (_context5.prev = _context5.next) {
253
+ case 0:
254
+ _context5.prev = 0;
255
+ client = new faunadb.Client({ secret: secret });
256
+ _context5.next = 4;
257
+ return client.query(q.Get(q.Match(q.Index('Email_and_FormName'), [email, form_name])));
258
+
259
+ case 4:
260
+ result = _context5.sent;
261
+ return _context5.abrupt('return', result ? true : false);
262
+
263
+ case 8:
264
+ _context5.prev = 8;
265
+ _context5.t0 = _context5['catch'](0);
266
+ return _context5.abrupt('return', false);
267
+
268
+ case 11:
269
+ case 'end':
270
+ return _context5.stop();
271
+ }
272
+ }
273
+ }, _callee5, this, [[0, 8]]);
274
+ }));
275
+
276
+ return function findUserByEmailAndForm(_x12, _x13) {
277
+ return _ref5.apply(this, arguments);
278
+ };
279
+ }();
203
280
 
204
281
  var updateUserSecret = function () {
205
- var _ref4 = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee4(email, hash) {
282
+ var _ref6 = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee6(email, hash) {
206
283
  var secret = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'fnAEG3Bb7AACAC0BiSQFYGBLFUtHjn3QOTKE1iBX';
207
284
  var expiration, client, result;
208
- return asyncToGenerator.regenerator.wrap(function _callee4$(_context4) {
285
+ return asyncToGenerator.regenerator.wrap(function _callee6$(_context6) {
209
286
  while (1) {
210
- switch (_context4.prev = _context4.next) {
287
+ switch (_context6.prev = _context6.next) {
211
288
  case 0:
212
289
  expiration = new Date().getTime() + 43200000; //1day
213
290
 
214
- _context4.prev = 1;
291
+ _context6.prev = 1;
215
292
 
216
293
  console.log(email, hash, expiration);
217
294
  client = new faunadb.Client({ secret: secret });
218
- _context4.next = 6;
295
+ _context6.next = 6;
219
296
  return client.query(q.Update(q.Select(['ref'], q.Get(q.Match(q.Index('Email'), email))), { data: { secretKey: hash, secretExpiration: expiration } }));
220
297
 
221
298
  case 6:
222
- result = _context4.sent;
223
- return _context4.abrupt('return', result ? true : false);
299
+ result = _context6.sent;
300
+ return _context6.abrupt('return', result ? true : false);
224
301
 
225
302
  case 10:
226
- _context4.prev = 10;
227
- _context4.t0 = _context4['catch'](1);
303
+ _context6.prev = 10;
304
+ _context6.t0 = _context6['catch'](1);
228
305
 
229
- console.log(_context4.t0);
230
- return _context4.abrupt('return', false);
306
+ console.log(_context6.t0);
307
+ return _context6.abrupt('return', false);
231
308
 
232
309
  case 14:
233
310
  case 'end':
234
- return _context4.stop();
311
+ return _context6.stop();
235
312
  }
236
313
  }
237
- }, _callee4, this, [[1, 10]]);
314
+ }, _callee6, this, [[1, 10]]);
238
315
  }));
239
316
 
240
- return function updateUserSecret(_x8, _x9) {
241
- return _ref4.apply(this, arguments);
317
+ return function updateUserSecret(_x15, _x16) {
318
+ return _ref6.apply(this, arguments);
242
319
  };
243
320
  }();
244
321
 
245
322
  var updateUserPassword = function () {
246
- var _ref5 = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee5(hash, newPassword) {
323
+ var _ref7 = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee7(hash, newPassword) {
247
324
  var secret = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'fnAEG3Bb7AACAC0BiSQFYGBLFUtHjn3QOTKE1iBX';
248
325
  var now, client, result, expiration, password, updatePassword;
249
- return asyncToGenerator.regenerator.wrap(function _callee5$(_context5) {
326
+ return asyncToGenerator.regenerator.wrap(function _callee7$(_context7) {
250
327
  while (1) {
251
- switch (_context5.prev = _context5.next) {
328
+ switch (_context7.prev = _context7.next) {
252
329
  case 0:
253
- _context5.prev = 0;
330
+ _context7.prev = 0;
254
331
  now = Date.now();
255
332
  client = new faunadb.Client({ secret: secret });
256
- _context5.next = 5;
333
+ _context7.next = 5;
257
334
  return client.query(q.Get(q.Match(q.Index('SecretKey'), hash)));
258
335
 
259
336
  case 5:
260
- result = _context5.sent;
337
+ result = _context7.sent;
261
338
  expiration = result.data.secretExpiration;
262
339
 
263
340
  if (!(now > expiration)) {
264
- _context5.next = 9;
341
+ _context7.next = 9;
265
342
  break;
266
343
  }
267
344
 
@@ -269,23 +346,23 @@ var updateUserPassword = function () {
269
346
 
270
347
  case 9:
271
348
  if (!(now < expiration)) {
272
- _context5.next = 18;
349
+ _context7.next = 18;
273
350
  break;
274
351
  }
275
352
 
276
- _context5.next = 12;
353
+ _context7.next = 12;
277
354
  return encrypt(newPassword);
278
355
 
279
356
  case 12:
280
- password = _context5.sent;
281
- _context5.next = 15;
357
+ password = _context7.sent;
358
+ _context7.next = 15;
282
359
  return client.query(q.Update(q.Select(['ref'], q.Get(q.Match(q.Index('SecretKey'), hash))), { data: { Password: password, secretKey: '' } }));
283
360
 
284
361
  case 15:
285
- updatePassword = _context5.sent;
362
+ updatePassword = _context7.sent;
286
363
 
287
364
  if (updatePassword) {
288
- _context5.next = 18;
365
+ _context7.next = 18;
289
366
  break;
290
367
  }
291
368
 
@@ -293,35 +370,37 @@ var updateUserPassword = function () {
293
370
 
294
371
  case 18:
295
372
  if (!(!result || result.error)) {
296
- _context5.next = 20;
373
+ _context7.next = 20;
297
374
  break;
298
375
  }
299
376
 
300
377
  throw new Error('User not found');
301
378
 
302
379
  case 20:
303
- return _context5.abrupt('return', true);
380
+ return _context7.abrupt('return', true);
304
381
 
305
382
  case 23:
306
- _context5.prev = 23;
307
- _context5.t0 = _context5['catch'](0);
308
- return _context5.abrupt('return', { err: _context5.t0 });
383
+ _context7.prev = 23;
384
+ _context7.t0 = _context7['catch'](0);
385
+ return _context7.abrupt('return', { err: _context7.t0 });
309
386
 
310
387
  case 26:
311
388
  case 'end':
312
- return _context5.stop();
389
+ return _context7.stop();
313
390
  }
314
391
  }
315
- }, _callee5, this, [[0, 23]]);
392
+ }, _callee7, this, [[0, 23]]);
316
393
  }));
317
394
 
318
- return function updateUserPassword(_x11, _x12) {
319
- return _ref5.apply(this, arguments);
395
+ return function updateUserPassword(_x18, _x19) {
396
+ return _ref7.apply(this, arguments);
320
397
  };
321
398
  }();
322
399
 
323
400
  exports.authenticateUser = authenticateUser;
401
+ exports.authenticateUserByForm = authenticateUserByForm;
324
402
  exports.findUserByEmail = findUserByEmail;
403
+ exports.findUserByEmailAndForm = findUserByEmailAndForm;
325
404
  exports.registerUser = registerUser;
326
405
  exports.updateUserPassword = updateUserPassword;
327
406
  exports.updateUserSecret = updateUserSecret;
@@ -196,68 +196,145 @@ var authenticateUser = function () {
196
196
  return _ref3.apply(this, arguments);
197
197
  };
198
198
  }();
199
+ var authenticateUserByForm = function () {
200
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(email, password, form_name) {
201
+ var secret = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'fnAEG3Bb7AACAC0BiSQFYGBLFUtHjn3QOTKE1iBX';
202
+ var client, result, hashedPassword, isAuth;
203
+ return regenerator.wrap(function _callee4$(_context4) {
204
+ while (1) {
205
+ switch (_context4.prev = _context4.next) {
206
+ case 0:
207
+ _context4.prev = 0;
208
+ client = new faunadb.Client({ secret: secret });
209
+ _context4.next = 4;
210
+ return client.query(q.Get(q.Match(q.Index('Email_and_FormName'), [email, form_name])));
211
+
212
+ case 4:
213
+ result = _context4.sent;
214
+ hashedPassword = result.data.Password;
215
+ _context4.next = 8;
216
+ return comparePassword(password, hashedPassword);
217
+
218
+ case 8:
219
+ isAuth = _context4.sent;
220
+ return _context4.abrupt('return', isAuth ? { email: email } : false);
221
+
222
+ case 12:
223
+ _context4.prev = 12;
224
+ _context4.t0 = _context4['catch'](0);
225
+
226
+ console.log(_context4.t0);
227
+ return _context4.abrupt('return', false);
228
+
229
+ case 16:
230
+ case 'end':
231
+ return _context4.stop();
232
+ }
233
+ }
234
+ }, _callee4, this, [[0, 12]]);
235
+ }));
236
+
237
+ return function authenticateUserByForm(_x8, _x9, _x10) {
238
+ return _ref4.apply(this, arguments);
239
+ };
240
+ }();
241
+
242
+ var findUserByEmailAndForm = function () {
243
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(email, form_name) {
244
+ var secret = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'fnAEG3Bb7AACAC0BiSQFYGBLFUtHjn3QOTKE1iBX';
245
+ var client, result;
246
+ return regenerator.wrap(function _callee5$(_context5) {
247
+ while (1) {
248
+ switch (_context5.prev = _context5.next) {
249
+ case 0:
250
+ _context5.prev = 0;
251
+ client = new faunadb.Client({ secret: secret });
252
+ _context5.next = 4;
253
+ return client.query(q.Get(q.Match(q.Index('Email_and_FormName'), [email, form_name])));
254
+
255
+ case 4:
256
+ result = _context5.sent;
257
+ return _context5.abrupt('return', result ? true : false);
258
+
259
+ case 8:
260
+ _context5.prev = 8;
261
+ _context5.t0 = _context5['catch'](0);
262
+ return _context5.abrupt('return', false);
263
+
264
+ case 11:
265
+ case 'end':
266
+ return _context5.stop();
267
+ }
268
+ }
269
+ }, _callee5, this, [[0, 8]]);
270
+ }));
271
+
272
+ return function findUserByEmailAndForm(_x12, _x13) {
273
+ return _ref5.apply(this, arguments);
274
+ };
275
+ }();
199
276
 
200
277
  var updateUserSecret = function () {
201
- var _ref4 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(email, hash) {
278
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(email, hash) {
202
279
  var secret = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'fnAEG3Bb7AACAC0BiSQFYGBLFUtHjn3QOTKE1iBX';
203
280
  var expiration, client, result;
204
- return regenerator.wrap(function _callee4$(_context4) {
281
+ return regenerator.wrap(function _callee6$(_context6) {
205
282
  while (1) {
206
- switch (_context4.prev = _context4.next) {
283
+ switch (_context6.prev = _context6.next) {
207
284
  case 0:
208
285
  expiration = new Date().getTime() + 43200000; //1day
209
286
 
210
- _context4.prev = 1;
287
+ _context6.prev = 1;
211
288
 
212
289
  console.log(email, hash, expiration);
213
290
  client = new faunadb.Client({ secret: secret });
214
- _context4.next = 6;
291
+ _context6.next = 6;
215
292
  return client.query(q.Update(q.Select(['ref'], q.Get(q.Match(q.Index('Email'), email))), { data: { secretKey: hash, secretExpiration: expiration } }));
216
293
 
217
294
  case 6:
218
- result = _context4.sent;
219
- return _context4.abrupt('return', result ? true : false);
295
+ result = _context6.sent;
296
+ return _context6.abrupt('return', result ? true : false);
220
297
 
221
298
  case 10:
222
- _context4.prev = 10;
223
- _context4.t0 = _context4['catch'](1);
299
+ _context6.prev = 10;
300
+ _context6.t0 = _context6['catch'](1);
224
301
 
225
- console.log(_context4.t0);
226
- return _context4.abrupt('return', false);
302
+ console.log(_context6.t0);
303
+ return _context6.abrupt('return', false);
227
304
 
228
305
  case 14:
229
306
  case 'end':
230
- return _context4.stop();
307
+ return _context6.stop();
231
308
  }
232
309
  }
233
- }, _callee4, this, [[1, 10]]);
310
+ }, _callee6, this, [[1, 10]]);
234
311
  }));
235
312
 
236
- return function updateUserSecret(_x8, _x9) {
237
- return _ref4.apply(this, arguments);
313
+ return function updateUserSecret(_x15, _x16) {
314
+ return _ref6.apply(this, arguments);
238
315
  };
239
316
  }();
240
317
 
241
318
  var updateUserPassword = function () {
242
- var _ref5 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(hash, newPassword) {
319
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7(hash, newPassword) {
243
320
  var secret = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'fnAEG3Bb7AACAC0BiSQFYGBLFUtHjn3QOTKE1iBX';
244
321
  var now, client, result, expiration, password, updatePassword;
245
- return regenerator.wrap(function _callee5$(_context5) {
322
+ return regenerator.wrap(function _callee7$(_context7) {
246
323
  while (1) {
247
- switch (_context5.prev = _context5.next) {
324
+ switch (_context7.prev = _context7.next) {
248
325
  case 0:
249
- _context5.prev = 0;
326
+ _context7.prev = 0;
250
327
  now = Date.now();
251
328
  client = new faunadb.Client({ secret: secret });
252
- _context5.next = 5;
329
+ _context7.next = 5;
253
330
  return client.query(q.Get(q.Match(q.Index('SecretKey'), hash)));
254
331
 
255
332
  case 5:
256
- result = _context5.sent;
333
+ result = _context7.sent;
257
334
  expiration = result.data.secretExpiration;
258
335
 
259
336
  if (!(now > expiration)) {
260
- _context5.next = 9;
337
+ _context7.next = 9;
261
338
  break;
262
339
  }
263
340
 
@@ -265,23 +342,23 @@ var updateUserPassword = function () {
265
342
 
266
343
  case 9:
267
344
  if (!(now < expiration)) {
268
- _context5.next = 18;
345
+ _context7.next = 18;
269
346
  break;
270
347
  }
271
348
 
272
- _context5.next = 12;
349
+ _context7.next = 12;
273
350
  return encrypt(newPassword);
274
351
 
275
352
  case 12:
276
- password = _context5.sent;
277
- _context5.next = 15;
353
+ password = _context7.sent;
354
+ _context7.next = 15;
278
355
  return client.query(q.Update(q.Select(['ref'], q.Get(q.Match(q.Index('SecretKey'), hash))), { data: { Password: password, secretKey: '' } }));
279
356
 
280
357
  case 15:
281
- updatePassword = _context5.sent;
358
+ updatePassword = _context7.sent;
282
359
 
283
360
  if (updatePassword) {
284
- _context5.next = 18;
361
+ _context7.next = 18;
285
362
  break;
286
363
  }
287
364
 
@@ -289,31 +366,31 @@ var updateUserPassword = function () {
289
366
 
290
367
  case 18:
291
368
  if (!(!result || result.error)) {
292
- _context5.next = 20;
369
+ _context7.next = 20;
293
370
  break;
294
371
  }
295
372
 
296
373
  throw new Error('User not found');
297
374
 
298
375
  case 20:
299
- return _context5.abrupt('return', true);
376
+ return _context7.abrupt('return', true);
300
377
 
301
378
  case 23:
302
- _context5.prev = 23;
303
- _context5.t0 = _context5['catch'](0);
304
- return _context5.abrupt('return', { err: _context5.t0 });
379
+ _context7.prev = 23;
380
+ _context7.t0 = _context7['catch'](0);
381
+ return _context7.abrupt('return', { err: _context7.t0 });
305
382
 
306
383
  case 26:
307
384
  case 'end':
308
- return _context5.stop();
385
+ return _context7.stop();
309
386
  }
310
387
  }
311
- }, _callee5, this, [[0, 23]]);
388
+ }, _callee7, this, [[0, 23]]);
312
389
  }));
313
390
 
314
- return function updateUserPassword(_x11, _x12) {
315
- return _ref5.apply(this, arguments);
391
+ return function updateUserPassword(_x18, _x19) {
392
+ return _ref7.apply(this, arguments);
316
393
  };
317
394
  }();
318
395
 
319
- export { authenticateUser, findUserByEmail, registerUser, updateUserPassword, updateUserSecret };
396
+ export { authenticateUser, authenticateUserByForm, findUserByEmail, findUserByEmailAndForm, registerUser, updateUserPassword, updateUserSecret };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mjhls/mjh-framework",
3
- "version": "1.0.1002",
3
+ "version": "1.0.1003",
4
4
  "description": "Foundation Framework",
5
5
  "author": "mjh-framework",
6
6
  "license": "MIT",