@mjhls/mjh-framework 1.0.1005 → 1.0.1006

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.1005
1
+ # mjh-framework v. 1.0.1006
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
 
@@ -318,27 +318,67 @@ var updateUserSecret = function () {
318
318
  return _ref6.apply(this, arguments);
319
319
  };
320
320
  }();
321
+ var updateUserSecretByForm = function () {
322
+ var _ref7 = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee7(email, hash, form) {
323
+ var secret = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'fnAEG3Bb7AACAC0BiSQFYGBLFUtHjn3QOTKE1iBX';
324
+ var expiration, client, result;
325
+ return asyncToGenerator.regenerator.wrap(function _callee7$(_context7) {
326
+ while (1) {
327
+ switch (_context7.prev = _context7.next) {
328
+ case 0:
329
+ expiration = new Date().getTime() + 43200000; //1day
330
+
331
+ _context7.prev = 1;
332
+
333
+ console.log(email, hash, expiration);
334
+ client = new faunadb.Client({ secret: secret });
335
+ _context7.next = 6;
336
+ return client.query(q.Update(q.Select(['ref'], q.Get(q.Match(q.Index('Email_and_FormName'), [email, form]))), { data: { secretKey: hash, secretExpiration: expiration } }));
337
+
338
+ case 6:
339
+ result = _context7.sent;
340
+ return _context7.abrupt('return', result ? true : false);
341
+
342
+ case 10:
343
+ _context7.prev = 10;
344
+ _context7.t0 = _context7['catch'](1);
345
+
346
+ console.log(_context7.t0);
347
+ return _context7.abrupt('return', false);
348
+
349
+ case 14:
350
+ case 'end':
351
+ return _context7.stop();
352
+ }
353
+ }
354
+ }, _callee7, this, [[1, 10]]);
355
+ }));
356
+
357
+ return function updateUserSecretByForm(_x18, _x19, _x20) {
358
+ return _ref7.apply(this, arguments);
359
+ };
360
+ }();
321
361
 
322
362
  var updateUserPassword = function () {
323
- var _ref7 = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee7(hash, newPassword) {
363
+ var _ref8 = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee8(hash, newPassword) {
324
364
  var secret = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'fnAEG3Bb7AACAC0BiSQFYGBLFUtHjn3QOTKE1iBX';
325
365
  var now, client, result, expiration, password, updatePassword;
326
- return asyncToGenerator.regenerator.wrap(function _callee7$(_context7) {
366
+ return asyncToGenerator.regenerator.wrap(function _callee8$(_context8) {
327
367
  while (1) {
328
- switch (_context7.prev = _context7.next) {
368
+ switch (_context8.prev = _context8.next) {
329
369
  case 0:
330
- _context7.prev = 0;
370
+ _context8.prev = 0;
331
371
  now = Date.now();
332
372
  client = new faunadb.Client({ secret: secret });
333
- _context7.next = 5;
373
+ _context8.next = 5;
334
374
  return client.query(q.Get(q.Match(q.Index('SecretKey'), hash)));
335
375
 
336
376
  case 5:
337
- result = _context7.sent;
377
+ result = _context8.sent;
338
378
  expiration = result.data.secretExpiration;
339
379
 
340
380
  if (!(now > expiration)) {
341
- _context7.next = 9;
381
+ _context8.next = 9;
342
382
  break;
343
383
  }
344
384
 
@@ -346,23 +386,23 @@ var updateUserPassword = function () {
346
386
 
347
387
  case 9:
348
388
  if (!(now < expiration)) {
349
- _context7.next = 18;
389
+ _context8.next = 18;
350
390
  break;
351
391
  }
352
392
 
353
- _context7.next = 12;
393
+ _context8.next = 12;
354
394
  return encrypt(newPassword);
355
395
 
356
396
  case 12:
357
- password = _context7.sent;
358
- _context7.next = 15;
397
+ password = _context8.sent;
398
+ _context8.next = 15;
359
399
  return client.query(q.Update(q.Select(['ref'], q.Get(q.Match(q.Index('SecretKey'), hash))), { data: { Password: password, secretKey: '' } }));
360
400
 
361
401
  case 15:
362
- updatePassword = _context7.sent;
402
+ updatePassword = _context8.sent;
363
403
 
364
404
  if (updatePassword) {
365
- _context7.next = 18;
405
+ _context8.next = 18;
366
406
  break;
367
407
  }
368
408
 
@@ -370,30 +410,30 @@ var updateUserPassword = function () {
370
410
 
371
411
  case 18:
372
412
  if (!(!result || result.error)) {
373
- _context7.next = 20;
413
+ _context8.next = 20;
374
414
  break;
375
415
  }
376
416
 
377
417
  throw new Error('User not found');
378
418
 
379
419
  case 20:
380
- return _context7.abrupt('return', true);
420
+ return _context8.abrupt('return', true);
381
421
 
382
422
  case 23:
383
- _context7.prev = 23;
384
- _context7.t0 = _context7['catch'](0);
385
- return _context7.abrupt('return', { err: _context7.t0 });
423
+ _context8.prev = 23;
424
+ _context8.t0 = _context8['catch'](0);
425
+ return _context8.abrupt('return', { err: _context8.t0 });
386
426
 
387
427
  case 26:
388
428
  case 'end':
389
- return _context7.stop();
429
+ return _context8.stop();
390
430
  }
391
431
  }
392
- }, _callee7, this, [[0, 23]]);
432
+ }, _callee8, this, [[0, 23]]);
393
433
  }));
394
434
 
395
- return function updateUserPassword(_x18, _x19) {
396
- return _ref7.apply(this, arguments);
435
+ return function updateUserPassword(_x22, _x23) {
436
+ return _ref8.apply(this, arguments);
397
437
  };
398
438
  }();
399
439
 
@@ -404,3 +444,4 @@ exports.findUserByEmailAndForm = findUserByEmailAndForm;
404
444
  exports.registerUser = registerUser;
405
445
  exports.updateUserPassword = updateUserPassword;
406
446
  exports.updateUserSecret = updateUserSecret;
447
+ exports.updateUserSecretByForm = updateUserSecretByForm;
@@ -314,27 +314,67 @@ var updateUserSecret = function () {
314
314
  return _ref6.apply(this, arguments);
315
315
  };
316
316
  }();
317
+ var updateUserSecretByForm = function () {
318
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7(email, hash, form) {
319
+ var secret = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'fnAEG3Bb7AACAC0BiSQFYGBLFUtHjn3QOTKE1iBX';
320
+ var expiration, client, result;
321
+ return regenerator.wrap(function _callee7$(_context7) {
322
+ while (1) {
323
+ switch (_context7.prev = _context7.next) {
324
+ case 0:
325
+ expiration = new Date().getTime() + 43200000; //1day
326
+
327
+ _context7.prev = 1;
328
+
329
+ console.log(email, hash, expiration);
330
+ client = new faunadb.Client({ secret: secret });
331
+ _context7.next = 6;
332
+ return client.query(q.Update(q.Select(['ref'], q.Get(q.Match(q.Index('Email_and_FormName'), [email, form]))), { data: { secretKey: hash, secretExpiration: expiration } }));
333
+
334
+ case 6:
335
+ result = _context7.sent;
336
+ return _context7.abrupt('return', result ? true : false);
337
+
338
+ case 10:
339
+ _context7.prev = 10;
340
+ _context7.t0 = _context7['catch'](1);
341
+
342
+ console.log(_context7.t0);
343
+ return _context7.abrupt('return', false);
344
+
345
+ case 14:
346
+ case 'end':
347
+ return _context7.stop();
348
+ }
349
+ }
350
+ }, _callee7, this, [[1, 10]]);
351
+ }));
352
+
353
+ return function updateUserSecretByForm(_x18, _x19, _x20) {
354
+ return _ref7.apply(this, arguments);
355
+ };
356
+ }();
317
357
 
318
358
  var updateUserPassword = function () {
319
- var _ref7 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7(hash, newPassword) {
359
+ var _ref8 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee8(hash, newPassword) {
320
360
  var secret = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'fnAEG3Bb7AACAC0BiSQFYGBLFUtHjn3QOTKE1iBX';
321
361
  var now, client, result, expiration, password, updatePassword;
322
- return regenerator.wrap(function _callee7$(_context7) {
362
+ return regenerator.wrap(function _callee8$(_context8) {
323
363
  while (1) {
324
- switch (_context7.prev = _context7.next) {
364
+ switch (_context8.prev = _context8.next) {
325
365
  case 0:
326
- _context7.prev = 0;
366
+ _context8.prev = 0;
327
367
  now = Date.now();
328
368
  client = new faunadb.Client({ secret: secret });
329
- _context7.next = 5;
369
+ _context8.next = 5;
330
370
  return client.query(q.Get(q.Match(q.Index('SecretKey'), hash)));
331
371
 
332
372
  case 5:
333
- result = _context7.sent;
373
+ result = _context8.sent;
334
374
  expiration = result.data.secretExpiration;
335
375
 
336
376
  if (!(now > expiration)) {
337
- _context7.next = 9;
377
+ _context8.next = 9;
338
378
  break;
339
379
  }
340
380
 
@@ -342,23 +382,23 @@ var updateUserPassword = function () {
342
382
 
343
383
  case 9:
344
384
  if (!(now < expiration)) {
345
- _context7.next = 18;
385
+ _context8.next = 18;
346
386
  break;
347
387
  }
348
388
 
349
- _context7.next = 12;
389
+ _context8.next = 12;
350
390
  return encrypt(newPassword);
351
391
 
352
392
  case 12:
353
- password = _context7.sent;
354
- _context7.next = 15;
393
+ password = _context8.sent;
394
+ _context8.next = 15;
355
395
  return client.query(q.Update(q.Select(['ref'], q.Get(q.Match(q.Index('SecretKey'), hash))), { data: { Password: password, secretKey: '' } }));
356
396
 
357
397
  case 15:
358
- updatePassword = _context7.sent;
398
+ updatePassword = _context8.sent;
359
399
 
360
400
  if (updatePassword) {
361
- _context7.next = 18;
401
+ _context8.next = 18;
362
402
  break;
363
403
  }
364
404
 
@@ -366,31 +406,31 @@ var updateUserPassword = function () {
366
406
 
367
407
  case 18:
368
408
  if (!(!result || result.error)) {
369
- _context7.next = 20;
409
+ _context8.next = 20;
370
410
  break;
371
411
  }
372
412
 
373
413
  throw new Error('User not found');
374
414
 
375
415
  case 20:
376
- return _context7.abrupt('return', true);
416
+ return _context8.abrupt('return', true);
377
417
 
378
418
  case 23:
379
- _context7.prev = 23;
380
- _context7.t0 = _context7['catch'](0);
381
- return _context7.abrupt('return', { err: _context7.t0 });
419
+ _context8.prev = 23;
420
+ _context8.t0 = _context8['catch'](0);
421
+ return _context8.abrupt('return', { err: _context8.t0 });
382
422
 
383
423
  case 26:
384
424
  case 'end':
385
- return _context7.stop();
425
+ return _context8.stop();
386
426
  }
387
427
  }
388
- }, _callee7, this, [[0, 23]]);
428
+ }, _callee8, this, [[0, 23]]);
389
429
  }));
390
430
 
391
- return function updateUserPassword(_x18, _x19) {
392
- return _ref7.apply(this, arguments);
431
+ return function updateUserPassword(_x22, _x23) {
432
+ return _ref8.apply(this, arguments);
393
433
  };
394
434
  }();
395
435
 
396
- export { authenticateUser, authenticateUserByForm, findUserByEmail, findUserByEmailAndForm, registerUser, updateUserPassword, updateUserSecret };
436
+ export { authenticateUser, authenticateUserByForm, findUserByEmail, findUserByEmailAndForm, registerUser, updateUserPassword, updateUserSecret, updateUserSecretByForm };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mjhls/mjh-framework",
3
- "version": "1.0.1005",
3
+ "version": "1.0.1006",
4
4
  "description": "Foundation Framework",
5
5
  "author": "mjh-framework",
6
6
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "peerDependencies": {
28
28
  "disqus-react": "^1.0.11",
29
- "next": "^9.0.0",
29
+ "next": "^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0",
30
30
  "prop-types": "^15.5.4",
31
31
  "react": "^15.0.0 || ^16.0.0",
32
32
  "react-bootstrap": "^1.0.0-beta.14",