(function () { 'use strict'; angular.module('MyApp') // extending from previously created angular module in the First Part .controller('LoginController',function ($scope,$location,$window, LoginService) { $scope.IsLogedIn = false; $scope.Message = ''; $scope.Submitted = false; $scope.IsFormValid = false; $scope.User = { UserName: '', Password: '' }; //Check is Form Valid or Not // Here f1 is our form Name $scope.$watch('f1.$valid', function (newVal) { $scope.IsFormValid = newVal; }); $scope.Login = function () { $scope.Submitted = true; if ($scope.IsFormValid) { LoginService.GetUser($scope.User).then(function (d) { debugger; if (d.data.AccessToken != null) { $scope.IsLogedIn = true; $scope.Message = "Successfully login done. Welcome "; $window.location.href = "/Home/index"; } else { $scope.Message = "Invalid UserName or Password"; } }); } }; }) .factory('LoginService', function ($http,$q,$window) { var fac = {}; debugger; fac.GetUser = function (d) { return $http({ url: 'api/users/login', method: 'POST', data: JSON.stringify(d), headers: { 'content-type': 'application/json' } }); }; return fac; }); })();
<label for="login">Username</label> <input type="text" data-ng-model="User.UserName" name="login" placeholder="Username or email" ng-class="Submitted?'ng-dirty':''" required autofocus /> Username required
<label for="password">Password</label> <input type="password" data-ng-model="User.Password" name="password" placeholder="Password" class="showpassword" ng-class="Submitted?'ng-dirty':''" required autofocus /> Password required
<input type="checkbox" name="remember" id="remember"><label for="remember">Remember Password</label> <input type="submit" value="Login" class="login-btn">
Forgot Password? New user? Register
Log in with Facebook Log in with Twitter
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)