Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2016
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. (function () {
  2. 'use strict';
  3.  
  4. angular
  5. .module('app')
  6. .controller('LoginController', LoginController);
  7.  
  8. LoginController.$inject = ['$scope', '$window', 'AuthenticationService', 'FlashService', '$http'];
  9. function LoginController($scope, $window, AuthenticationService, FlashService, $http) {
  10. var vm = this;
  11. AuthenticationService.Login = function(username, password, callback) {
  12. $http.post("/login", { username: username, password: password }).success(function(data) {
  13. var response = {};
  14. if(data.response === "success") {
  15. response.success = true;
  16. } else {
  17. response.success = false;
  18. response.message = "Invalid login or password.";
  19. }
  20. callback(response);
  21. });
  22. };
  23.  
  24. (function initController() {
  25. // reset login status
  26. AuthenticationService.ClearCredentials();
  27. })();
  28.  
  29. function login() {
  30. vm.dataLoading = true;
  31. var username = $("#username").val();
  32. var password = $("#password").val();
  33. AuthenticationService.Login(username, password, function (response) {
  34. if (response.success) {
  35. AuthenticationService.SetCredentials(username, password);
  36. AuthenticationService.currentUsername = username;
  37. $window.location.assign('/#');
  38. } else {
  39. FlashService.Error(response.message);
  40. vm.dataLoading = false;
  41. }
  42. });
  43. };
  44.  
  45. $scope.login = login;
  46. }
  47.  
  48. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement