Ei kuvausta

login.js 1.0KB

1234567891011121314151617181920212223242526272829303132
  1. angular.module('MyApp')
  2. .controller('LoginCtrl', function($scope, $location, $auth, toastr) {
  3. $scope.login = function() {
  4. $auth.login($scope.user)
  5. .then(function() {
  6. toastr.success('You have successfully signed in!');
  7. $location.path('/');
  8. })
  9. .catch(function(error) {
  10. toastr.error(error.data.message, error.status);
  11. });
  12. };
  13. $scope.authenticate = function(provider) {
  14. $auth.authenticate(provider)
  15. .then(function() {
  16. toastr.success('You have successfully signed in with ' + provider + '!');
  17. $location.path('/');
  18. })
  19. .catch(function(error) {
  20. if (error.error) {
  21. // Popup error - invalid redirect_uri, pressed cancel button, etc.
  22. toastr.error(error.error);
  23. } else if (error.data) {
  24. // HTTP response error from server
  25. toastr.error(error.data.message, error.status);
  26. } else {
  27. toastr.error(error);
  28. }
  29. });
  30. };
  31. });