Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. //service.js
  2. authApp.factory("loginFactory", function ($http) {
  3. return{
  4. login: function(username, password) {
  5. var data = "username="+username+"&password="+password+"&submit=Login";
  6. return $http({
  7. method: 'POST',
  8. url: 'http://localhost:8080/login',
  9. data: data,
  10. headers: {
  11. 'Content-Type': 'application/x-www-form-urlencoded',
  12. }
  13. });
  14. }
  15. }
  16. });
  17.  
  18. //controller
  19. authApp.controller('LoginCtrl', ['$scope', '$location', 'loginFactory', function($scope, $location, loginFactory){
  20. $scope.authenticate = function() {
  21. loginFactory.login($scope.username, $scope.password)
  22. .then(function(response) {
  23. console.log(response.statusText);
  24. }, function errorCallBack(response) {
  25. console.log(response.statusText);
  26. });
  27. }
  28. }]);
  29.  
  30. <div ng-controller="LoginCtrl">
  31. <h2>Login</h2>
  32. <form name="form" ng-submit="authenticate()">
  33. <div>
  34. <label for="username">Username</label>
  35. <input type="text" name="username" id="username" ng-model="username"/>
  36.  
  37. <label for="password">Password</label>
  38. <input type="password" name="password" id="password" ng-model="password"/>
  39. <button type="submit">Login</button>
  40. </form>
  41. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement