Skip to content

Instantly share code, notes, and snippets.

@got5
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save got5/68f54941af77bdd21b11 to your computer and use it in GitHub Desktop.
Save got5/68f54941af77bdd21b11 to your computer and use it in GitHub Desktop.
Slide78 TP4
(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";
});
};
}]);
})();
<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> &raquo;
<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