Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. 'use strict';
  2.  
  3. class LoginController {
  4. constructor(Auth, $state) {
  5. this.user = {};
  6. this.errors = {};
  7. this.submitted = false;
  8.  
  9. this.Auth = Auth;
  10. this.$state = $state;
  11. this.currentUser = {};
  12.  
  13.  
  14. }
  15.  
  16. login(form) {
  17. this.submitted = true;
  18.  
  19. if (form.$valid) {
  20. this.Auth.login({
  21. email: this.user.email,
  22. password: this.user.password
  23. })
  24. .then(() => {
  25.  
  26. this.currentUser = this.Auth.getCurrentUser;
  27.  
  28.  
  29.  
  30. if (this.currentUser.role === "employee") {
  31. this.$state.go('employeeMain');
  32. }
  33.  
  34. else if(this.currentUser.role === "employer") {
  35. this.$state.go('employerMain');
  36.  
  37. }
  38.  
  39. else if (this.currentUser.role === "admin") {
  40. this.$state.go('adminMain');
  41. };
  42.  
  43. // Logged in, redirect to home
  44. // this.$state.go('main');
  45. })
  46. .catch(err => {
  47. this.errors.other = err.message;
  48. });
  49. }
  50. }
  51.  
  52. }
  53.  
  54. angular.module('aApp')
  55. .controller('LoginController', LoginController);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement