Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function () {
- 'use strict';
- angular
- .module('app')
- .controller('LoginController', LoginController);
- LoginController.$inject = ['$scope', '$window', 'AuthenticationService', 'FlashService', '$http'];
- function LoginController($scope, $window, AuthenticationService, FlashService, $http) {
- var vm = this;
- AuthenticationService.Login = function(username, password, callback) {
- $http.post("/login", { username: username, password: password }).success(function(data) {
- var response = {};
- if(data.response === "success") {
- response.success = true;
- } else {
- response.success = false;
- response.message = "Invalid login or password.";
- }
- callback(response);
- });
- };
- (function initController() {
- // reset login status
- AuthenticationService.ClearCredentials();
- })();
- function login() {
- vm.dataLoading = true;
- var username = $("#username").val();
- var password = $("#password").val();
- AuthenticationService.Login(username, password, function (response) {
- if (response.success) {
- AuthenticationService.SetCredentials(username, password);
- AuthenticationService.currentUsername = username;
- $window.location.assign('/#');
- } else {
- FlashService.Error(response.message);
- vm.dataLoading = false;
- }
- });
- };
- $scope.login = login;
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement