Last active
August 29, 2015 14:11
-
-
Save got5/68f54941af77bdd21b11 to your computer and use it in GitHub Desktop.
Slide78 TP4
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('app') | |
.controller('LoginController', ['$scope' , '$http', '$log', '$cookieStore', '$location', function ($scope, $http, $log, $cookieStore, $location) { | |
$scope.errorMsg = null; | |
$scope.logUser = function () { | |
$http.post('/api/login', {login: $scope.login, password: $scope.password}) | |
.success(function (user) { | |
$log.info('Authentication successed !'); | |
/** | |
* Use cookies to store user | |
*/ | |
$cookieStore.put('user', user); | |
/** | |
* Redirection | |
*/ | |
$location.path('/'); | |
}) | |
.error(function (reason) { | |
$log.error('unable to log ' + reason); | |
$scope.errorMsg = "Bad Login and/or password"; | |
}); | |
}; | |
}]); | |
})(); |
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
<div> | |
<div class="k-error-messages" ng-if="errorMsg"> | |
<h3>{{errorMsg}}</h3> | |
</div> | |
<form class="k-login" ng-submit="logUser()"> | |
<fieldset> | |
<legend>Sign in</legend> | |
<p> | |
<label for="login">User identifier</label> | |
<input id="login" type="text" ng-model="login"/> | |
</p> | |
<p> | |
<label for="password">Password</label> | |
<input id="password" type="password" ng-model="password" /> | |
<span class="lost-password"> | |
<a href="#">Forgot your password?</a> | |
</span> | |
</p> | |
<p> | |
<button type="submit" class="btn">Login</button> | |
</p> | |
</fieldset> | |
<p class="to-register"> | |
<strong>Not registered yet ?</strong> » | |
<a href="#">Register now</a> | |
</p> | |
</form> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment