/**
* Created by zx- on 9.10.2015.
*/
'use strict';
/**
* Login directive
* triggers events:
*
* auth:login-success
* auth:login-error
*
* https://github.com/lynndylanhurley/ng-token-auth#authsubmitlogin
*/
/**
* @ngdoc directive
* @name suxessDirectives.directive:loginDirective
* @restrict E
*
* @description
* Directive for basic user user with authentification.
*
* @requires $auth
*@example
<example module="suxessDirectives">
<file name="script.js">
angular.module('suxessDirectives', ['loginDirective']);
function Ctrl($scope) {
$scope.userIsLogged. = true;
}
</file>
<file name="index.html">
<div ng-controller="Ctrl">
<user-directive ng-hide="userIsLogged"></user-directive>
</div>
</file>
</example>
*
*
*
*/
suxessDirectives.directive('userLoginDirective',[
'$auth',
'$state',
function( $auth, $state ){
return {
restrict: 'E',
templateUrl: 'angular-app/templates/directives/user/user-login-directive.html',
controller: function ( $auth ) {
this.form = {};
this.submitLogin = function () {
console.log(this.form);
$auth.submitLogin( this.form )
.then( function( resp ) {
console.log( resp );
$state.go('project');
SUXESS.showMessage.success('Login Successful');
})
.catch( function( resp ) {
console.log( resp );
SUXESS.showMessage.error('Username or Password is Invalid');
});
};
},
controllerAs: 'login'
};
}]);