Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(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