Created
October 20, 2017 12:08
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
angular | |
.module('main') | |
.controller('AuthCtrl', AuthCtrl); | |
function AuthCtrl(crAcl, $state, AuthService, Flash, $log) { | |
var vm = this; | |
vm.login = login; | |
vm.showRegisterForm = false; | |
vm.loginForm = null; | |
vm.credentials = {}; | |
vm.user = {}; | |
function login(credentials) { | |
function success(response) { | |
function success(response) { | |
if (response.data.status !== 'empty') { | |
var currentUser = response.data.objects[0]; | |
crAcl.setRole('ROLE_ADMIN'); | |
AuthService.setCredentials(currentUser); | |
$state.go('admin.pages'); | |
} | |
else | |
Flash.create('danger', 'Incorrect username or password'); | |
} | |
function failed(response) { | |
$log.error(response); | |
} | |
if (response.data.status !== 'empty') | |
AuthService | |
.checkPassword(credentials) | |
.then(success, failed); | |
else | |
Flash.create('danger', 'Incorrect username or password'); | |
$log.info(response); | |
} | |
function failed(response) { | |
$log.error(response); | |
} | |
if (vm.loginForm.$valid) | |
AuthService | |
.checkUsername(credentials) | |
.then(success, failed); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment