Advertisement
Guest User

Untitled

a guest
Jan 19th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. angular
  2. .module('security.authorisation')
  3. .factory('AuthorisationService', [
  4. '$http',
  5. 'security.endpoints',
  6. 'toastr',
  7. AuthorisationService
  8. ]);
  9.  
  10.  
  11. function AuthorisationService($http, Endpoints, toastr) {
  12. var authService = {};
  13. var _getAuthServiceModel = {
  14. user: {
  15. email: '',
  16. password: '',
  17. grant_type: 'password'
  18. }
  19.  
  20. };
  21.  
  22. // Initialisation.
  23. function init() {
  24. authService.initModel = _getAuthServiceModel;
  25. }
  26.  
  27.  
  28. // Login function.
  29. authService.login = function (user, success, error) {
  30. var login_url = Endpoints.getUrl("login");
  31. $http.post(login_url)
  32.  
  33. .success(function (data) {
  34.  
  35. }).then(function (temp) {
  36. console.log("suc");
  37. }, function (err) {
  38. console.log("err");
  39. });
  40. //toaster.pop('success', "title", "text");
  41. };
  42.  
  43. init(); // Runs on during creation on factory.
  44.  
  45.  
  46. return authService;
  47. }
  48.  
  49. (function () {
  50. 'use strict';
  51.  
  52. angular
  53. .module('public.login')
  54. .controller('LoginController', [
  55. '$scope',
  56. 'AuthorisationService',
  57. LoginController
  58. ]);
  59.  
  60. function LoginController($scope, AuthorisationService) {
  61.  
  62.  
  63. $scope.submit = function submit() {
  64.  
  65. $scope.app = AuthorisationService.initModel;
  66. AuthorisationService.login($scope.app)
  67.  
  68. .then(function (greeting) {
  69. alert('Success: ' + greeting);
  70. }, function (reason) {
  71. alert('Failed: ' + reason);
  72. });
  73.  
  74.  
  75. }
  76.  
  77. }
  78. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement