Skip to content

Instantly share code, notes, and snippets.

@kutsaniuk
Created October 20, 2017 12:08
Show Gist options
  • Save kutsaniuk/5b284fd9d3e9179a357d22fe16c45c52 to your computer and use it in GitHub Desktop.
Save kutsaniuk/5b284fd9d3e9179a357d22fe16c45c52 to your computer and use it in GitHub Desktop.
(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