@mjhls/mjh-framework 1.0.791-auth-test-v2 → 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.
@@ -2823,10 +2823,10 @@ var _skeletonTheme = _interopRequireDefault(skeletonTheme);
2823
2823
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2824
2824
  });
2825
2825
 
2826
- var Skeleton = _commonjsHelpers.unwrapExports(lib);
2826
+ _commonjsHelpers.unwrapExports(lib);
2827
2827
 
2828
- var css = ".AuthWrapper-module_loginBox__3l-BE {\n position: absolute;\n top: 0;\n left: 50%;\n margin-top: 4rem;\n border: 1px solid #eee;\n padding: 2rem 1rem;\n transform: translateX(-50%);\n width: 350px;\n max-width: 90vw;\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";
2829
- var styles = { "loginBox": "AuthWrapper-module_loginBox__3l-BE", "loginBox_title": "AuthWrapper-module_loginBox_title__12rGD", "bar": "AuthWrapper-module_bar__1dafn" };
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
+ 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
 
2832
2832
  var AuthWrapper = function AuthWrapper(_ref) {
@@ -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);
@@ -2871,73 +2876,77 @@ var AuthWrapper = function AuthWrapper(_ref) {
2871
2876
  return React__default['default'].createElement(
2872
2877
  'div',
2873
2878
  { style: { position: 'relative', minHeight: '300px', paddingTop: '2rem' } },
2874
- React__default['default'].createElement(
2875
- 'div',
2876
- { style: { display: 'flex' } },
2877
- React__default['default'].createElement(
2878
- 'div',
2879
- null,
2880
- React__default['default'].createElement(Skeleton, { reactangle: true, height: 120, width: 120 })
2881
- ),
2882
- React__default['default'].createElement(
2883
- 'div',
2884
- { style: { maxWidth: '76%', minWidth: '76%', marginLeft: '2rem' } },
2885
- React__default['default'].createElement(Skeleton, { count: 4 })
2886
- )
2887
- ),
2888
- React__default['default'].createElement('br', null),
2889
- React__default['default'].createElement(Skeleton, { count: 8 }),
2890
2879
  callbackUrl && React__default['default'].createElement(
2891
2880
  'div',
2892
- { className: styles.loginBox },
2893
- React__default['default'].createElement(
2881
+ null,
2882
+ !showForm && React__default['default'].createElement(
2894
2883
  'div',
2895
- { className: styles.loginBox_title },
2884
+ { className: styles.loginBox },
2896
2885
  React__default['default'].createElement(
2897
- 'b',
2898
- null,
2899
- 'Log in to view.'
2900
- )
2901
- ),
2902
- React__default['default'].createElement(
2903
- reactBootstrap.Form,
2904
- { onSubmit: function onSubmit(e) {
2905
- return e.preventDefault();
2906
- } },
2886
+ 'div',
2887
+ { className: styles.loginBox_title },
2888
+ React__default['default'].createElement(
2889
+ 'b',
2890
+ null,
2891
+ 'Please log in to view this content.'
2892
+ )
2893
+ ),
2907
2894
  React__default['default'].createElement(
2908
- reactBootstrap.Form.Group,
2909
- { controlId: 'email' },
2910
- React__default['default'].createElement(reactBootstrap.Form.Control, { type: 'email', onChange: function onChange(e) {
2911
- return setEmail(e.target.value);
2912
- }, placeholder: 'Email' })
2895
+ reactBootstrap.Form,
2896
+ { onSubmit: function onSubmit(e) {
2897
+ return e.preventDefault();
2898
+ } },
2899
+ React__default['default'].createElement(
2900
+ reactBootstrap.Form.Group,
2901
+ { controlId: 'email' },
2902
+ React__default['default'].createElement(reactBootstrap.Form.Control, { type: 'email', onChange: function onChange(e) {
2903
+ return setEmail(e.target.value);
2904
+ }, placeholder: 'Email' })
2905
+ ),
2906
+ React__default['default'].createElement(
2907
+ reactBootstrap.Form.Group,
2908
+ { controlId: 'password' },
2909
+ React__default['default'].createElement(reactBootstrap.Form.Control, { type: 'password', onChange: function onChange(e) {
2910
+ return setPassword(e.target.value);
2911
+ }, placeholder: 'Password' })
2912
+ ),
2913
+ React__default['default'].createElement(
2914
+ 'button',
2915
+ { className: 'btn btn-primary btn-block', onClick: function onClick() {
2916
+ return client.signIn('credentials', { email: email, password: password, callbackUrl: callbackUrl });
2917
+ } },
2918
+ 'Sign in'
2919
+ )
2913
2920
  ),
2914
2921
  React__default['default'].createElement(
2915
- reactBootstrap.Form.Group,
2916
- { controlId: 'password' },
2917
- React__default['default'].createElement(reactBootstrap.Form.Control, { type: 'password', onChange: function onChange(e) {
2918
- return setPassword(e.target.value);
2919
- }, placeholder: 'Password' })
2922
+ 'p',
2923
+ { style: { textAlign: 'center' }, className: 'mt-2 mb-0' },
2924
+ 'Don\'t have an account?',
2925
+ ' ',
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.'
2920
2934
  ),
2921
2935
  React__default['default'].createElement(
2922
- 'button',
2923
- { className: 'btn btn-primary btn-block', onClick: function onClick() {
2924
- return client.signIn('credentials', { email: email, password: password, callbackUrl: callbackUrl });
2925
- } },
2926
- 'Sign in'
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
+ )
2927
2947
  )
2928
2948
  ),
2929
- React__default['default'].createElement(
2930
- 'p',
2931
- { className: 'mt-2 mb-0' },
2932
- 'Don\'t have an account?',
2933
- ' ',
2934
- React__default['default'].createElement(
2935
- 'a',
2936
- { style: { color: 'blue', textDecoration: 'underline' }, href: formUrl, target: '_blank', rel: 'noopener' },
2937
- 'Register here'
2938
- ),
2939
- '.'
2940
- )
2949
+ showForm && React__default['default'].createElement('iframe', { className: styles.iframe, src: formUrl })
2941
2950
  )
2942
2951
  );
2943
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');
@@ -177,23 +178,21 @@ var authenticateUser = function () {
177
178
 
178
179
  case 8:
179
180
  isAuth = _context3.sent;
180
-
181
- console.log(isAuth, password, hashedPassword);
182
181
  return _context3.abrupt('return', isAuth ? { email: email } : false);
183
182
 
184
- case 13:
185
- _context3.prev = 13;
183
+ case 12:
184
+ _context3.prev = 12;
186
185
  _context3.t0 = _context3['catch'](0);
187
186
 
188
187
  console.log(_context3.t0);
189
188
  return _context3.abrupt('return', false);
190
189
 
191
- case 17:
190
+ case 16:
192
191
  case 'end':
193
192
  return _context3.stop();
194
193
  }
195
194
  }
196
- }, _callee3, this, [[0, 13]]);
195
+ }, _callee3, this, [[0, 12]]);
197
196
  }));
198
197
 
199
198
  return function authenticateUser(_x3, _x4) {
@@ -201,6 +200,125 @@ var authenticateUser = function () {
201
200
  };
202
201
  }();
203
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
+
204
320
  exports.authenticateUser = authenticateUser;
205
321
  exports.findUserByEmail = findUserByEmail;
206
322
  exports.registerUser = registerUser;
323
+ exports.updateUserPassword = updateUserPassword;
324
+ exports.updateUserSecret = updateUserSecret;
@@ -2817,10 +2817,10 @@ var _skeletonTheme = _interopRequireDefault(skeletonTheme);
2817
2817
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2818
2818
  });
2819
2819
 
2820
- var Skeleton = unwrapExports(lib);
2820
+ unwrapExports(lib);
2821
2821
 
2822
- var css = ".AuthWrapper-module_loginBox__3l-BE {\n position: absolute;\n top: 0;\n left: 50%;\n margin-top: 4rem;\n border: 1px solid #eee;\n padding: 2rem 1rem;\n transform: translateX(-50%);\n width: 350px;\n max-width: 90vw;\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";
2823
- var styles = { "loginBox": "AuthWrapper-module_loginBox__3l-BE", "loginBox_title": "AuthWrapper-module_loginBox_title__12rGD", "bar": "AuthWrapper-module_bar__1dafn" };
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
+ 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
 
2826
2826
  var AuthWrapper = function AuthWrapper(_ref) {
@@ -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);
@@ -2865,73 +2870,77 @@ var AuthWrapper = function AuthWrapper(_ref) {
2865
2870
  return React.createElement(
2866
2871
  'div',
2867
2872
  { style: { position: 'relative', minHeight: '300px', paddingTop: '2rem' } },
2868
- React.createElement(
2869
- 'div',
2870
- { style: { display: 'flex' } },
2871
- React.createElement(
2872
- 'div',
2873
- null,
2874
- React.createElement(Skeleton, { reactangle: true, height: 120, width: 120 })
2875
- ),
2876
- React.createElement(
2877
- 'div',
2878
- { style: { maxWidth: '76%', minWidth: '76%', marginLeft: '2rem' } },
2879
- React.createElement(Skeleton, { count: 4 })
2880
- )
2881
- ),
2882
- React.createElement('br', null),
2883
- React.createElement(Skeleton, { count: 8 }),
2884
2873
  callbackUrl && React.createElement(
2885
2874
  'div',
2886
- { className: styles.loginBox },
2887
- React.createElement(
2875
+ null,
2876
+ !showForm && React.createElement(
2888
2877
  'div',
2889
- { className: styles.loginBox_title },
2878
+ { className: styles.loginBox },
2890
2879
  React.createElement(
2891
- 'b',
2892
- null,
2893
- 'Log in to view.'
2894
- )
2895
- ),
2896
- React.createElement(
2897
- Form,
2898
- { onSubmit: function onSubmit(e) {
2899
- return e.preventDefault();
2900
- } },
2880
+ 'div',
2881
+ { className: styles.loginBox_title },
2882
+ React.createElement(
2883
+ 'b',
2884
+ null,
2885
+ 'Please log in to view this content.'
2886
+ )
2887
+ ),
2901
2888
  React.createElement(
2902
- Form.Group,
2903
- { controlId: 'email' },
2904
- React.createElement(Form.Control, { type: 'email', onChange: function onChange(e) {
2905
- return setEmail(e.target.value);
2906
- }, placeholder: 'Email' })
2889
+ Form,
2890
+ { onSubmit: function onSubmit(e) {
2891
+ return e.preventDefault();
2892
+ } },
2893
+ React.createElement(
2894
+ Form.Group,
2895
+ { controlId: 'email' },
2896
+ React.createElement(Form.Control, { type: 'email', onChange: function onChange(e) {
2897
+ return setEmail(e.target.value);
2898
+ }, placeholder: 'Email' })
2899
+ ),
2900
+ React.createElement(
2901
+ Form.Group,
2902
+ { controlId: 'password' },
2903
+ React.createElement(Form.Control, { type: 'password', onChange: function onChange(e) {
2904
+ return setPassword(e.target.value);
2905
+ }, placeholder: 'Password' })
2906
+ ),
2907
+ React.createElement(
2908
+ 'button',
2909
+ { className: 'btn btn-primary btn-block', onClick: function onClick() {
2910
+ return client.signIn('credentials', { email: email, password: password, callbackUrl: callbackUrl });
2911
+ } },
2912
+ 'Sign in'
2913
+ )
2907
2914
  ),
2908
2915
  React.createElement(
2909
- Form.Group,
2910
- { controlId: 'password' },
2911
- React.createElement(Form.Control, { type: 'password', onChange: function onChange(e) {
2912
- return setPassword(e.target.value);
2913
- }, placeholder: 'Password' })
2916
+ 'p',
2917
+ { style: { textAlign: 'center' }, className: 'mt-2 mb-0' },
2918
+ 'Don\'t have an account?',
2919
+ ' ',
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.'
2914
2928
  ),
2915
2929
  React.createElement(
2916
- 'button',
2917
- { className: 'btn btn-primary btn-block', onClick: function onClick() {
2918
- return client.signIn('credentials', { email: email, password: password, callbackUrl: callbackUrl });
2919
- } },
2920
- 'Sign in'
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
+ )
2921
2941
  )
2922
2942
  ),
2923
- React.createElement(
2924
- 'p',
2925
- { className: 'mt-2 mb-0' },
2926
- 'Don\'t have an account?',
2927
- ' ',
2928
- React.createElement(
2929
- 'a',
2930
- { style: { color: 'blue', textDecoration: 'underline' }, href: formUrl, target: '_blank', rel: 'noopener' },
2931
- 'Register here'
2932
- ),
2933
- '.'
2934
- )
2943
+ showForm && React.createElement('iframe', { className: styles.iframe, src: formUrl })
2935
2944
  )
2936
2945
  );
2937
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';
@@ -173,23 +174,21 @@ var authenticateUser = function () {
173
174
 
174
175
  case 8:
175
176
  isAuth = _context3.sent;
176
-
177
- console.log(isAuth, password, hashedPassword);
178
177
  return _context3.abrupt('return', isAuth ? { email: email } : false);
179
178
 
180
- case 13:
181
- _context3.prev = 13;
179
+ case 12:
180
+ _context3.prev = 12;
182
181
  _context3.t0 = _context3['catch'](0);
183
182
 
184
183
  console.log(_context3.t0);
185
184
  return _context3.abrupt('return', false);
186
185
 
187
- case 17:
186
+ case 16:
188
187
  case 'end':
189
188
  return _context3.stop();
190
189
  }
191
190
  }
192
- }, _callee3, this, [[0, 13]]);
191
+ }, _callee3, this, [[0, 12]]);
193
192
  }));
194
193
 
195
194
  return function authenticateUser(_x3, _x4) {
@@ -197,4 +196,121 @@ var authenticateUser = function () {
197
196
  };
198
197
  }();
199
198
 
200
- 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-v2",
3
+ "version": "1.0.791-auth-test-v4",
4
4
  "description": "Foundation Framework",
5
5
  "author": "mjh-framework",
6
6
  "license": "MIT",