sso.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. (function ($ang) {
  2. 'use strict';
  3. $ang.module('ylmis').controller("ssoCtrl", ['$scope', '$rootScope', '$state', '$http', '$loading', '$alert', '$interval', '$window', 'AuthUser', '$location',
  4. function ($scope, $rootScope, $state, $http, $loading, $alert, $interval, $window, AuthUser, $location) {
  5. $scope.errorMsg = '';
  6. var token = $location.search().loginToken.replace(/%2B/g,'+');
  7. var tm = $location.search().tm;
  8. var path = $location.search().re;
  9. if (token && token != "" && tm && tm != "") {
  10. $loading.show();
  11. $http.post('/api/systemsetting/Account/SSOGetToken', { token: token, tm: tm }).then(function (req) {
  12. $loading.hide();
  13. if (req.data.IsSuccess) {
  14. AuthUser.setUser(req.data.Data);
  15. $rootScope.refreshTokenInterval = $interval(function () {
  16. $http({
  17. method: 'post',
  18. url: '../../api/systemsetting/Account/RefreshToken',
  19. data: {}
  20. }).then(function (req) {
  21. if (req.data.IsSuccess) {
  22. $window.localStorage["token"] = req.data.Data.Token;
  23. } else {
  24. $alert({
  25. title: '错误',
  26. content: req.data.Data.Message + ",请重新登录",
  27. placement: 'centre',
  28. type: 'danger',
  29. show: true,
  30. duration: 3
  31. }).then(function () {
  32. $window.location.href = "/app/main/index.html#!/login";
  33. })
  34. }
  35. });
  36. }, 60000);
  37. if (path && path != "") {
  38. $location.url(path);
  39. } else {
  40. $state.go("homeTabs");
  41. }
  42. } else {
  43. $scope.errorMsg = req.data.Message;
  44. $alert({
  45. title: '错误',
  46. content: $scope.errorMsg,
  47. placement: 'centre',
  48. type: 'danger',
  49. show: true,
  50. duration: 3,
  51. onHide: function () {
  52. $window.location.href = "/app/main/index.html#!/login";
  53. }
  54. });
  55. }
  56. }, function (reason) {
  57. $loading.hide();
  58. });
  59. }
  60. }]);
  61. })(angular, this, CryptoJS);