Guest User

Untitled

a guest
Jan 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { Accounts } from 'meteor/accounts-base';
  3. import { Meteor } from 'meteor/meteor';
  4.  
  5. @Injectable()
  6. export class AuthProvider {
  7.  
  8. constructor() {
  9. console.log('Hello AuthProvider Provider');
  10. }
  11.  
  12. /**
  13. *
  14. * Method to login using email and password.
  15. *
  16. * @param {string} email: Email of the user trying to login.
  17. * @param {string} password: Password of the user to login.
  18. *
  19. */
  20. login(email: string, password: string): Promise<void> {
  21.  
  22. return new Promise<void>((resolve, reject) => {
  23.  
  24. Meteor.loginWithPassword(email, password, (e: Error) => {
  25.  
  26. if (e) return reject(e);
  27.  
  28. resolve();
  29.  
  30. });
  31. });
  32. }
  33.  
  34. /**
  35. *
  36. * Method to register new user
  37. *
  38. * @param {string} email: Email of the user trying to login.
  39. * @param {string} password: Password of the user to login.
  40. * @param {string} username: Username of the user.
  41. * @param {string} name: Name of the user,
  42. *
  43. */
  44. register(email: string, password: string, username: string, name: string): Promise<void> {
  45.  
  46. let userData = {
  47. username: username,
  48. email: email,
  49. password: password,
  50. profile: {
  51. name: name
  52. }
  53. };
  54. return new Promise<void>((resolve, reject) => {
  55.  
  56. Accounts.createUser(userData, (e: Error) => {
  57.  
  58. if (e) return reject(e);
  59.  
  60. resolve();
  61.  
  62. });
  63. });
  64. }
  65.  
  66.  
  67.  
  68. }
Add Comment
Please, Sign In to add comment