Created
October 20, 2017 12:08
-
-
Save kutsaniuk/5b284fd9d3e9179a357d22fe16c45c52 to your computer and use it in GitHub Desktop.
This file contains 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