auth.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use strict';
  2. var auth = angular.module('authApp', ['ngCookies','authctrl']);
  3. angular.module('authctrl', ['authsvc']);
  4. angular.module('authsvc', []);
  5. angular.module('authctrl').controller('authcontroller', function($scope, $cookieStore, identitysvc){
  6. $scope.identity = function(nickname){
  7. identitysvc.identity(nickname).then(function(response){
  8. var valueJson = JSON.stringify(response);
  9. var valueObject = JSON.parse(valueJson);
  10. // console.log(valueObject);
  11. var status = valueObject.status;
  12. if (status == "200") {
  13. var user=valueObject.data.user;
  14. if(angular.isUndefined(user.id)){
  15. }else{
  16. var id=user.id;
  17. window.sessionStorage.setItem("userId",id);
  18. window.sessionStorage.setItem("userNameToken",user.name);
  19. $cookieStore.put("userObm", user);
  20. $cookieStore.put("menuObm", valueObject.data.menu);
  21. $cookieStore.put("session", valueObject.data.sessionId);
  22. $scope.username = user.name;
  23. }
  24. }
  25. });
  26. }
  27. });
  28. auth.value('server',{
  29. host:'192.168.3.233',
  30. getUrl: function(data){
  31. return 'http://' + this.host + ':9002/services/auth/sso/';
  32. }
  33. });
  34. angular.module('authsvc')
  35. .factory('identitysvc', function ($rootScope, $http, $q, $timeout, server) {
  36. return {
  37. identity: function(nickname){
  38. server.getUrl('user')+nickname;
  39. return $http.get(server.getUrl('user')+nickname);
  40. }
  41. };
  42. });