Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. app.controller('SigninFormController', ['$scope', '$http', '$state', function($scope, $http, $state) {
  2. $scope.user = {};
  3. $scope.authError = null;
  4. $scope.login = function() {
  5. $scope.authError = null;
  6. // Try to login
  7. $http({
  8. method:'POST',
  9. url:'https://mywebsite.com/api/login',
  10. params: {
  11. 'number':$scope.user.number,
  12. 'password':$scope.user.password}
  13. })
  14. .then(function(response) {
  15. if ( response.data.success === false ) {
  16. $scope.authError = 'Email or Password not right';
  17. }
  18. else{
  19. $state.go('app.dashboard');
  20. }
  21. }, function(x) {
  22. $scope.authError = 'Login or Email no right';
  23. });
  24. }; }]);
  25.  
  26. {"success":"false","result":"wrong email or password"}
  27. {"success":"true","result":"выдается jwttoken"}
  28.  
  29. var user = {
  30. email: $scope.email,
  31. password: $scope.password
  32. };
  33.  
  34. $auth.login(user)
  35. .then(function(response) {
  36. // Redirect user here after a successful log in.
  37. })
  38. .catch(function(response) {
  39. // Handle errors here, such as displaying a notification
  40. // for invalid email and/or password.
  41. });
  42.  
  43. $location.path('url');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement