Files
brewman/brewman/static/scripts/login.js
T
tanshu abc77fb5a6 Chore: Using angularjs 1.5.0 online hosted.
Refactor: Simplified MenuItem and Hierarchical Product table.
Feature: Recipe now follows temporat (Point in time) feature.
It should be fully working and records the recipe cost for a period based on the issue price and as on date.
Feature: Using Angular Material for recipe form and also or product form.
2016-03-14 15:28:17 +05:30

46 lines
1.7 KiB
JavaScript

'use strict';
var LoginController = ['$scope', '$http', '$location', '$routeParams', '$cookies', function ($scope, $http, $location, $routeParams, $cookies) {
$scope.showOTP = false;
$scope.submit = function () {
var data;
if ($scope.showOTP) {
data = {username: $scope.username, password: $scope.password, otp: $scope.otp, ClientName: $scope.name};
} else {
data = {username: $scope.username, password: $scope.password};
}
$http.
post('/api/login', data).
success(function () {
var came_from = $routeParams.came_from;
if (angular.isUndefined(came_from) || came_from === "" || came_from === "/login" || came_from === "/logout") {
came_from = "/";
}
$location.url(came_from);
}).
error(function (data, status, headers, config) {
if (status === 403 && ['Unknown Client', 'OTP not supplied', 'OTP is wrong'].indexOf(data) !== -1) {
$scope.showOTP = true;
$scope.clientID = $cookies.get('ClientID');
$scope.$apply();
}
$scope.toasts.push({Type: 'Danger', Message: data});
});
};
$scope.foUsername = true;
}];
var LogoutController = ['$scope', '$http', '$location', function ($scope, $http, $location) {
$http.
post('/logout').
success(function () {
$scope.toasts.push({Type: 'Success', Message: 'Logged out'});
$location.path('/');
}).
error(function (errorMessage) {
$scope.toasts.push({Type: 'Danger', Message: errorMessage});
});
}];