Advertisement
Guest User

Untitled

a guest
Mar 26th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. angular.module('fairMuseApp')
  2. .controller('LoginCtrl', function(authenticationService, $location, $scope) {
  3. var self = this;
  4. var user, email, password, authenticationService, response, wrongCredentials, location;
  5. location = $location
  6. self.email = "";
  7. self.password = "";
  8. self.wrongCredentials = false;
  9.  
  10. self.sendForm = function(email, password) {
  11. self.user = {email: self.email,
  12. password: self.password}
  13. var promise = authenticationService.login(self.user);
  14. promise.then(success, error);
  15. };
  16.  
  17. var success = function(response){
  18. localStorage.setItem('auth_token', response.data.auth_token);
  19. console.log(localStorage)
  20. location.path('/songs')
  21. };
  22.  
  23. var error = function(hi) {
  24. self.wrongCredentials = true;
  25. };
  26. });
  27.  
  28. <div ng-include="'views/navbar.html'"></div>
  29. <div ng-controller='LoginCtrl as login' class='alert alert-danger' ng-show="login.wrongCredentials">
  30. Wrong Credentials
  31. </div>
  32. <form name="login_form" ng-submit="login.sendForm(email, password)">
  33. <label for="email">Email</label>
  34. <input type="email" name="email" ng-model="login.email">
  35. <label for="password">Password</label>
  36. <input type="password" name="password" ng-model="login.password">
  37. <button type="submit">Log in</button>
  38. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement