Guest User

Untitled

a guest
Apr 27th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. // /imports/api/methods/twoFactorAuth.js
  2.  
  3. import SimpleSchema from 'simpl-schema';
  4.  
  5. export const TwoFactorToken = {
  6. type: SimpleSchema.Integer, min: 0, max: 999999, optional: true,
  7. };
  8.  
  9. export const tokenIsValid = (token: string, secret: string) => {
  10. if (!authenticator.check(token, secret)) {
  11. throw new Meteor.Error('twoFactor.invalid-token');
  12. }
  13. };
  14.  
  15. export const enableTwoFactor = new ValidatedMethod({
  16. name: 'twoFactor.enableTwoFactor',
  17. validate: new SimpleSchema({
  18. token: TwoFactorToken,
  19. }).validator(),
  20. run({ token }) {
  21. userIsLoggedIn(this.userId);
  22. if (this.isSimulation) return;
  23.  
  24. tokenIsValid(token, Meteor.user().services.twoFactorSecret);
  25. Meteor.users.update(this.userId, { $set: { twoFactorEnabled: true } });
  26. },
  27. });
Add Comment
Please, Sign In to add comment