@mjhls/mjh-framework 1.0.791-auth-test-v3 → 1.0.791-auth-test-v4

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.
@@ -2825,7 +2825,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
2825
2825
 
2826
2826
  _commonjsHelpers.unwrapExports(lib);
2827
2827
 
2828
- var css = ".AuthWrapper-module_loginBox__3l-BE {\n margin-bottom: 2rem;\n width: 350px;\n max-width: 90vw;\n margin-left: auto;\n margin-right: auto;\n /* box-shadow: 2px 5px 12px rgba(0, 0, 0, 0.15); */\n background: #fff;\n z-index: 1;\n}\n.AuthWrapper-module_loginBox_title__12rGD {\n margin-bottom: 2rem;\n text-align: center;\n}\n.AuthWrapper-module_bar__1dafn {\n background: #eee;\n margin-left: unset;\n margin-right: unset;\n}\n.AuthWrapper-module_bar__1dafn:nth-child(1) {\n float: left;\n border-right: 1rem solid #fff;\n background: rgb(245, 245, 245);\n height: 10rem;\n width: 25%;\n margin-left: auto;\n margin-right: auto;\n margin-bottom: 2rem;\n}\n.AuthWrapper-module_bar__1dafn:nth-child(2n) {\n width: 97%;\n height: 1.5rem;\n margin-bottom: 0.25rem;\n}\n.AuthWrapper-module_bar__1dafn.AuthWrapper-module_bar__1dafn:nth-child(3n) {\n width: 96%;\n height: 1.5rem;\n margin-bottom: 1.5rem;\n}\n.AuthWrapper-module_bar__1dafn.AuthWrapper-module_bar__1dafn:nth-child(4n) {\n width: 72%;\n height: 1.5rem;\n margin-bottom: 0.25rem;\n}\n.AuthWrapper-module_bar__1dafn.AuthWrapper-module_bar__1dafn:nth-child(5n) {\n width: 88%;\n height: 1.5rem;\n margin-bottom: 0.25rem;\n}\n\n.AuthWrapper-module_iframe__2wDJW {\n border: none;\n width: 100%;\n height: 1900px;\n}";
2828
+ var css = ".AuthWrapper-module_loginBox__3l-BE {\n margin-bottom: 2rem;\n width: 350px;\n max-width: 90vw;\n margin-left: auto;\n margin-right: auto;\n /* box-shadow: 2px 5px 12px rgba(0, 0, 0, 0.15); */\n background: #fff;\n z-index: 1;\n}\n.AuthWrapper-module_loginBox_title__12rGD {\n margin-bottom: 2rem;\n text-align: center;\n}\n.AuthWrapper-module_bar__1dafn {\n background: #eee;\n margin-left: unset;\n margin-right: unset;\n}\n.AuthWrapper-module_bar__1dafn:nth-child(1) {\n float: left;\n border-right: 1rem solid #fff;\n background: rgb(245, 245, 245);\n height: 10rem;\n width: 25%;\n margin-left: auto;\n margin-right: auto;\n margin-bottom: 2rem;\n}\n.AuthWrapper-module_bar__1dafn:nth-child(2n) {\n width: 97%;\n height: 1.5rem;\n margin-bottom: 0.25rem;\n}\n.AuthWrapper-module_bar__1dafn.AuthWrapper-module_bar__1dafn:nth-child(3n) {\n width: 96%;\n height: 1.5rem;\n margin-bottom: 1.5rem;\n}\n.AuthWrapper-module_bar__1dafn.AuthWrapper-module_bar__1dafn:nth-child(4n) {\n width: 72%;\n height: 1.5rem;\n margin-bottom: 0.25rem;\n}\n.AuthWrapper-module_bar__1dafn.AuthWrapper-module_bar__1dafn:nth-child(5n) {\n width: 88%;\n height: 1.5rem;\n margin-bottom: 0.25rem;\n}\n\n.AuthWrapper-module_iframe__2wDJW {\n margin-top: -3rem;\n border: none;\n width: 100%;\n height: 1900px;\n}";
2829
2829
  var styles = { "loginBox": "AuthWrapper-module_loginBox__3l-BE", "loginBox_title": "AuthWrapper-module_loginBox_title__12rGD", "bar": "AuthWrapper-module_bar__1dafn", "iframe": "AuthWrapper-module_iframe__2wDJW" };
2830
2830
  styleInject_es.styleInject(css);
2831
2831
 
@@ -2850,10 +2850,15 @@ var AuthWrapper = function AuthWrapper(_ref) {
2850
2850
  email = _useState4[0],
2851
2851
  setEmail = _useState4[1];
2852
2852
 
2853
- var _useState5 = React.useState(),
2853
+ var _useState5 = React.useState(false),
2854
2854
  _useState6 = slicedToArray._slicedToArray(_useState5, 2),
2855
- password = _useState6[0],
2856
- setPassword = _useState6[1];
2855
+ showForm = _useState6[0],
2856
+ setShowForm = _useState6[1];
2857
+
2858
+ var _useState7 = React.useState(),
2859
+ _useState8 = slicedToArray._slicedToArray(_useState7, 2),
2860
+ password = _useState8[0],
2861
+ setPassword = _useState8[1];
2857
2862
 
2858
2863
  React.useEffect(function () {
2859
2864
  setCallbackUrl(window.location.href);
@@ -2874,7 +2879,7 @@ var AuthWrapper = function AuthWrapper(_ref) {
2874
2879
  callbackUrl && React__default['default'].createElement(
2875
2880
  'div',
2876
2881
  null,
2877
- React__default['default'].createElement(
2882
+ !showForm && React__default['default'].createElement(
2878
2883
  'div',
2879
2884
  { className: styles.loginBox },
2880
2885
  React__default['default'].createElement(
@@ -2915,13 +2920,33 @@ var AuthWrapper = function AuthWrapper(_ref) {
2915
2920
  ),
2916
2921
  React__default['default'].createElement(
2917
2922
  'p',
2918
- { className: 'mt-2 mb-0' },
2923
+ { style: { textAlign: 'center' }, className: 'mt-2 mb-0' },
2919
2924
  'Don\'t have an account?',
2920
2925
  ' ',
2921
- 'Please register below.'
2926
+ React__default['default'].createElement(
2927
+ 'a',
2928
+ { style: { color: 'blue', textDecoration: 'underline' }, onClick: function onClick() {
2929
+ return setShowForm(!showForm);
2930
+ } },
2931
+ 'Click Here'
2932
+ ),
2933
+ ' to register.'
2934
+ ),
2935
+ React__default['default'].createElement(
2936
+ 'p',
2937
+ { className: 'mt-1', style: { fontSize: '.8em', textAlign: 'center' } },
2938
+ React__default['default'].createElement(
2939
+ 'em',
2940
+ null,
2941
+ React__default['default'].createElement(
2942
+ 'a',
2943
+ { href: '/forgotpassword', style: { color: 'blue', textDecoration: 'underline' } },
2944
+ 'Forgot your password? '
2945
+ )
2946
+ )
2922
2947
  )
2923
2948
  ),
2924
- React__default['default'].createElement('iframe', { className: styles.iframe, src: formUrl })
2949
+ showForm && React__default['default'].createElement('iframe', { className: styles.iframe, src: formUrl })
2925
2950
  )
2926
2951
  );
2927
2952
  } else {
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var asyncToGenerator = require('./asyncToGenerator-58c289d9.js');
6
+ require('prop-types');
6
7
  var md5 = require('./md5-e1ca5797.js');
7
8
  require('./_commonjsHelpers-06173234.js');
8
9
  require('./es6.string.iterator-c2573ffd.js');
@@ -199,6 +200,125 @@ var authenticateUser = function () {
199
200
  };
200
201
  }();
201
202
 
203
+ var updateUserSecret = function () {
204
+ var _ref4 = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee4(email, hash) {
205
+ var expiration, client, result;
206
+ return asyncToGenerator.regenerator.wrap(function _callee4$(_context4) {
207
+ while (1) {
208
+ switch (_context4.prev = _context4.next) {
209
+ case 0:
210
+ expiration = new Date().getTime() + 43200000; //1day
211
+
212
+ _context4.prev = 1;
213
+
214
+ console.log(email, hash, expiration);
215
+ client = new faunadb.Client({ secret: secret });
216
+ _context4.next = 6;
217
+ return client.query(q.Update(q.Select(['ref'], q.Get(q.Match(q.Index('Email'), email))), { data: { secretKey: hash, secretExpiration: expiration } }));
218
+
219
+ case 6:
220
+ result = _context4.sent;
221
+ return _context4.abrupt('return', result ? true : false);
222
+
223
+ case 10:
224
+ _context4.prev = 10;
225
+ _context4.t0 = _context4['catch'](1);
226
+
227
+ console.log(_context4.t0);
228
+ return _context4.abrupt('return', false);
229
+
230
+ case 14:
231
+ case 'end':
232
+ return _context4.stop();
233
+ }
234
+ }
235
+ }, _callee4, this, [[1, 10]]);
236
+ }));
237
+
238
+ return function updateUserSecret(_x5, _x6) {
239
+ return _ref4.apply(this, arguments);
240
+ };
241
+ }();
242
+
243
+ var updateUserPassword = function () {
244
+ var _ref5 = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee5(hash, newPassword) {
245
+ var now, client, result, expiration, password, updatePassword;
246
+ return asyncToGenerator.regenerator.wrap(function _callee5$(_context5) {
247
+ while (1) {
248
+ switch (_context5.prev = _context5.next) {
249
+ case 0:
250
+ _context5.prev = 0;
251
+ now = Date.now();
252
+ client = new faunadb.Client({ secret: secret });
253
+ _context5.next = 5;
254
+ return client.query(q.Get(q.Match(q.Index('SecretKey'), hash)));
255
+
256
+ case 5:
257
+ result = _context5.sent;
258
+ expiration = result.data.secretExpiration;
259
+
260
+ if (!(now > expiration)) {
261
+ _context5.next = 9;
262
+ break;
263
+ }
264
+
265
+ throw new Error('eKey has expired.');
266
+
267
+ case 9:
268
+ if (!(now < expiration)) {
269
+ _context5.next = 18;
270
+ break;
271
+ }
272
+
273
+ _context5.next = 12;
274
+ return encrypt(newPassword);
275
+
276
+ case 12:
277
+ password = _context5.sent;
278
+ _context5.next = 15;
279
+ return client.query(q.Update(q.Select(['ref'], q.Get(q.Match(q.Index('SecretKey'), hash))), { data: { Password: password, secretKey: '' } }));
280
+
281
+ case 15:
282
+ updatePassword = _context5.sent;
283
+
284
+ if (updatePassword) {
285
+ _context5.next = 18;
286
+ break;
287
+ }
288
+
289
+ throw new Error('Failed to update password.');
290
+
291
+ case 18:
292
+ if (!(!result || result.error)) {
293
+ _context5.next = 20;
294
+ break;
295
+ }
296
+
297
+ throw new Error('User not found');
298
+
299
+ case 20:
300
+ return _context5.abrupt('return', true);
301
+
302
+ case 23:
303
+ _context5.prev = 23;
304
+ _context5.t0 = _context5['catch'](0);
305
+ return _context5.abrupt('return', { err: _context5.t0 });
306
+
307
+ case 26:
308
+ case 'end':
309
+ return _context5.stop();
310
+ }
311
+ }
312
+ }, _callee5, this, [[0, 23]]);
313
+ }));
314
+
315
+ return function updateUserPassword(_x7, _x8) {
316
+ return _ref5.apply(this, arguments);
317
+ };
318
+ }();
319
+
202
320
  exports.authenticateUser = authenticateUser;
203
321
  exports.findUserByEmail = findUserByEmail;
204
322
  exports.registerUser = registerUser;
323
+ exports.updateUserPassword = updateUserPassword;
324
+ exports.updateUserSecret = updateUserSecret;
@@ -2819,7 +2819,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
2819
2819
 
2820
2820
  unwrapExports(lib);
2821
2821
 
2822
- var css = ".AuthWrapper-module_loginBox__3l-BE {\n margin-bottom: 2rem;\n width: 350px;\n max-width: 90vw;\n margin-left: auto;\n margin-right: auto;\n /* box-shadow: 2px 5px 12px rgba(0, 0, 0, 0.15); */\n background: #fff;\n z-index: 1;\n}\n.AuthWrapper-module_loginBox_title__12rGD {\n margin-bottom: 2rem;\n text-align: center;\n}\n.AuthWrapper-module_bar__1dafn {\n background: #eee;\n margin-left: unset;\n margin-right: unset;\n}\n.AuthWrapper-module_bar__1dafn:nth-child(1) {\n float: left;\n border-right: 1rem solid #fff;\n background: rgb(245, 245, 245);\n height: 10rem;\n width: 25%;\n margin-left: auto;\n margin-right: auto;\n margin-bottom: 2rem;\n}\n.AuthWrapper-module_bar__1dafn:nth-child(2n) {\n width: 97%;\n height: 1.5rem;\n margin-bottom: 0.25rem;\n}\n.AuthWrapper-module_bar__1dafn.AuthWrapper-module_bar__1dafn:nth-child(3n) {\n width: 96%;\n height: 1.5rem;\n margin-bottom: 1.5rem;\n}\n.AuthWrapper-module_bar__1dafn.AuthWrapper-module_bar__1dafn:nth-child(4n) {\n width: 72%;\n height: 1.5rem;\n margin-bottom: 0.25rem;\n}\n.AuthWrapper-module_bar__1dafn.AuthWrapper-module_bar__1dafn:nth-child(5n) {\n width: 88%;\n height: 1.5rem;\n margin-bottom: 0.25rem;\n}\n\n.AuthWrapper-module_iframe__2wDJW {\n border: none;\n width: 100%;\n height: 1900px;\n}";
2822
+ var css = ".AuthWrapper-module_loginBox__3l-BE {\n margin-bottom: 2rem;\n width: 350px;\n max-width: 90vw;\n margin-left: auto;\n margin-right: auto;\n /* box-shadow: 2px 5px 12px rgba(0, 0, 0, 0.15); */\n background: #fff;\n z-index: 1;\n}\n.AuthWrapper-module_loginBox_title__12rGD {\n margin-bottom: 2rem;\n text-align: center;\n}\n.AuthWrapper-module_bar__1dafn {\n background: #eee;\n margin-left: unset;\n margin-right: unset;\n}\n.AuthWrapper-module_bar__1dafn:nth-child(1) {\n float: left;\n border-right: 1rem solid #fff;\n background: rgb(245, 245, 245);\n height: 10rem;\n width: 25%;\n margin-left: auto;\n margin-right: auto;\n margin-bottom: 2rem;\n}\n.AuthWrapper-module_bar__1dafn:nth-child(2n) {\n width: 97%;\n height: 1.5rem;\n margin-bottom: 0.25rem;\n}\n.AuthWrapper-module_bar__1dafn.AuthWrapper-module_bar__1dafn:nth-child(3n) {\n width: 96%;\n height: 1.5rem;\n margin-bottom: 1.5rem;\n}\n.AuthWrapper-module_bar__1dafn.AuthWrapper-module_bar__1dafn:nth-child(4n) {\n width: 72%;\n height: 1.5rem;\n margin-bottom: 0.25rem;\n}\n.AuthWrapper-module_bar__1dafn.AuthWrapper-module_bar__1dafn:nth-child(5n) {\n width: 88%;\n height: 1.5rem;\n margin-bottom: 0.25rem;\n}\n\n.AuthWrapper-module_iframe__2wDJW {\n margin-top: -3rem;\n border: none;\n width: 100%;\n height: 1900px;\n}";
2823
2823
  var styles = { "loginBox": "AuthWrapper-module_loginBox__3l-BE", "loginBox_title": "AuthWrapper-module_loginBox_title__12rGD", "bar": "AuthWrapper-module_bar__1dafn", "iframe": "AuthWrapper-module_iframe__2wDJW" };
2824
2824
  styleInject(css);
2825
2825
 
@@ -2844,10 +2844,15 @@ var AuthWrapper = function AuthWrapper(_ref) {
2844
2844
  email = _useState4[0],
2845
2845
  setEmail = _useState4[1];
2846
2846
 
2847
- var _useState5 = useState(),
2847
+ var _useState5 = useState(false),
2848
2848
  _useState6 = _slicedToArray(_useState5, 2),
2849
- password = _useState6[0],
2850
- setPassword = _useState6[1];
2849
+ showForm = _useState6[0],
2850
+ setShowForm = _useState6[1];
2851
+
2852
+ var _useState7 = useState(),
2853
+ _useState8 = _slicedToArray(_useState7, 2),
2854
+ password = _useState8[0],
2855
+ setPassword = _useState8[1];
2851
2856
 
2852
2857
  useEffect(function () {
2853
2858
  setCallbackUrl(window.location.href);
@@ -2868,7 +2873,7 @@ var AuthWrapper = function AuthWrapper(_ref) {
2868
2873
  callbackUrl && React.createElement(
2869
2874
  'div',
2870
2875
  null,
2871
- React.createElement(
2876
+ !showForm && React.createElement(
2872
2877
  'div',
2873
2878
  { className: styles.loginBox },
2874
2879
  React.createElement(
@@ -2909,13 +2914,33 @@ var AuthWrapper = function AuthWrapper(_ref) {
2909
2914
  ),
2910
2915
  React.createElement(
2911
2916
  'p',
2912
- { className: 'mt-2 mb-0' },
2917
+ { style: { textAlign: 'center' }, className: 'mt-2 mb-0' },
2913
2918
  'Don\'t have an account?',
2914
2919
  ' ',
2915
- 'Please register below.'
2920
+ React.createElement(
2921
+ 'a',
2922
+ { style: { color: 'blue', textDecoration: 'underline' }, onClick: function onClick() {
2923
+ return setShowForm(!showForm);
2924
+ } },
2925
+ 'Click Here'
2926
+ ),
2927
+ ' to register.'
2928
+ ),
2929
+ React.createElement(
2930
+ 'p',
2931
+ { className: 'mt-1', style: { fontSize: '.8em', textAlign: 'center' } },
2932
+ React.createElement(
2933
+ 'em',
2934
+ null,
2935
+ React.createElement(
2936
+ 'a',
2937
+ { href: '/forgotpassword', style: { color: 'blue', textDecoration: 'underline' } },
2938
+ 'Forgot your password? '
2939
+ )
2940
+ )
2916
2941
  )
2917
2942
  ),
2918
- React.createElement('iframe', { className: styles.iframe, src: formUrl })
2943
+ showForm && React.createElement('iframe', { className: styles.iframe, src: formUrl })
2919
2944
  )
2920
2945
  );
2921
2946
  } else {
@@ -1,4 +1,5 @@
1
1
  import { a as _asyncToGenerator, r as regenerator } from './asyncToGenerator-7f8f9219.js';
2
+ import 'prop-types';
2
3
  import { m as md5 } from './md5-4e42248e.js';
3
4
  import './_commonjsHelpers-0c4b6f40.js';
4
5
  import './es6.string.iterator-bc33758b.js';
@@ -195,4 +196,121 @@ var authenticateUser = function () {
195
196
  };
196
197
  }();
197
198
 
198
- export { authenticateUser, findUserByEmail, registerUser };
199
+ var updateUserSecret = function () {
200
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(email, hash) {
201
+ var expiration, client, result;
202
+ return regenerator.wrap(function _callee4$(_context4) {
203
+ while (1) {
204
+ switch (_context4.prev = _context4.next) {
205
+ case 0:
206
+ expiration = new Date().getTime() + 43200000; //1day
207
+
208
+ _context4.prev = 1;
209
+
210
+ console.log(email, hash, expiration);
211
+ client = new faunadb.Client({ secret: secret });
212
+ _context4.next = 6;
213
+ return client.query(q.Update(q.Select(['ref'], q.Get(q.Match(q.Index('Email'), email))), { data: { secretKey: hash, secretExpiration: expiration } }));
214
+
215
+ case 6:
216
+ result = _context4.sent;
217
+ return _context4.abrupt('return', result ? true : false);
218
+
219
+ case 10:
220
+ _context4.prev = 10;
221
+ _context4.t0 = _context4['catch'](1);
222
+
223
+ console.log(_context4.t0);
224
+ return _context4.abrupt('return', false);
225
+
226
+ case 14:
227
+ case 'end':
228
+ return _context4.stop();
229
+ }
230
+ }
231
+ }, _callee4, this, [[1, 10]]);
232
+ }));
233
+
234
+ return function updateUserSecret(_x5, _x6) {
235
+ return _ref4.apply(this, arguments);
236
+ };
237
+ }();
238
+
239
+ var updateUserPassword = function () {
240
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(hash, newPassword) {
241
+ var now, client, result, expiration, password, updatePassword;
242
+ return regenerator.wrap(function _callee5$(_context5) {
243
+ while (1) {
244
+ switch (_context5.prev = _context5.next) {
245
+ case 0:
246
+ _context5.prev = 0;
247
+ now = Date.now();
248
+ client = new faunadb.Client({ secret: secret });
249
+ _context5.next = 5;
250
+ return client.query(q.Get(q.Match(q.Index('SecretKey'), hash)));
251
+
252
+ case 5:
253
+ result = _context5.sent;
254
+ expiration = result.data.secretExpiration;
255
+
256
+ if (!(now > expiration)) {
257
+ _context5.next = 9;
258
+ break;
259
+ }
260
+
261
+ throw new Error('eKey has expired.');
262
+
263
+ case 9:
264
+ if (!(now < expiration)) {
265
+ _context5.next = 18;
266
+ break;
267
+ }
268
+
269
+ _context5.next = 12;
270
+ return encrypt(newPassword);
271
+
272
+ case 12:
273
+ password = _context5.sent;
274
+ _context5.next = 15;
275
+ return client.query(q.Update(q.Select(['ref'], q.Get(q.Match(q.Index('SecretKey'), hash))), { data: { Password: password, secretKey: '' } }));
276
+
277
+ case 15:
278
+ updatePassword = _context5.sent;
279
+
280
+ if (updatePassword) {
281
+ _context5.next = 18;
282
+ break;
283
+ }
284
+
285
+ throw new Error('Failed to update password.');
286
+
287
+ case 18:
288
+ if (!(!result || result.error)) {
289
+ _context5.next = 20;
290
+ break;
291
+ }
292
+
293
+ throw new Error('User not found');
294
+
295
+ case 20:
296
+ return _context5.abrupt('return', true);
297
+
298
+ case 23:
299
+ _context5.prev = 23;
300
+ _context5.t0 = _context5['catch'](0);
301
+ return _context5.abrupt('return', { err: _context5.t0 });
302
+
303
+ case 26:
304
+ case 'end':
305
+ return _context5.stop();
306
+ }
307
+ }
308
+ }, _callee5, this, [[0, 23]]);
309
+ }));
310
+
311
+ return function updateUserPassword(_x7, _x8) {
312
+ return _ref5.apply(this, arguments);
313
+ };
314
+ }();
315
+
316
+ export { authenticateUser, findUserByEmail, registerUser, updateUserPassword, updateUserSecret };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mjhls/mjh-framework",
3
- "version": "1.0.791-auth-test-v3",
3
+ "version": "1.0.791-auth-test-v4",
4
4
  "description": "Foundation Framework",
5
5
  "author": "mjh-framework",
6
6
  "license": "MIT",