Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- class LoginController {
- constructor(Auth, $state) {
- this.user = {};
- this.errors = {};
- this.submitted = false;
- this.Auth = Auth;
- this.$state = $state;
- this.currentUser = {};
- }
- login(form) {
- this.submitted = true;
- if (form.$valid) {
- this.Auth.login({
- email: this.user.email,
- password: this.user.password
- })
- .then(() => {
- this.currentUser = this.Auth.getCurrentUser;
- if (this.currentUser.role === "employee") {
- this.$state.go('employeeMain');
- }
- else if(this.currentUser.role === "employer") {
- this.$state.go('employerMain');
- }
- else if (this.currentUser.role === "admin") {
- this.$state.go('adminMain');
- };
- // Logged in, redirect to home
- // this.$state.go('main');
- })
- .catch(err => {
- this.errors.other = err.message;
- });
- }
- }
- }
- angular.module('aApp')
- .controller('LoginController', LoginController);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement