AdminAuth.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace Tool\MayouTool\BaseAuth;
  3. use Tool\MayouTool\Bean\BaseAuth\AddUserParamBean;
  4. use Tool\MayouTool\Exception\AuthException;
  5. use Tool\MayouTool\HttpCurl;
  6. class AdminAuth
  7. {
  8. /**
  9. * 登录
  10. * @param string $userName 用户名
  11. * @param string $userPassword 密码
  12. */
  13. public static function login($userName, $userPassword,$userProjectId)
  14. {
  15. $url = BASE_AUTH_URL."user/login";
  16. $params = [
  17. "user_name"=>$userName,
  18. "user_password"=>$userPassword,
  19. "user_project_id"=>$userProjectId
  20. ];
  21. $queryParam = array_merge($_POST,$_GET);
  22. if(isset($queryParam["traceId"]) && $queryParam["traceId"]){
  23. $params["traceId"] = $queryParam["traceId"];
  24. }
  25. $res = HttpCurl::postCurl($url,$params,[],false);
  26. if($res["status"]){
  27. return $res["data"];
  28. }
  29. throw new AuthException($res["msg"],$res["code"]);
  30. }
  31. /**
  32. * 检测用户是否拥有此权限
  33. * @param string $path
  34. */
  35. public static function checkUserAuth($path,$token)
  36. {
  37. $url = BASE_AUTH_URL."checkNodeAuth";
  38. $headers = [
  39. "token"=>$token,
  40. "path"=>$path
  41. ];
  42. $queryParam = array_merge($_POST,$_GET);
  43. if(isset($queryParam["traceId"]) && $queryParam["traceId"]){
  44. $params["traceId"] = $queryParam["traceId"];
  45. }
  46. $res = HttpCurl::postCurl($url,[],$headers,false);
  47. if($res["status"]){
  48. return $res["data"];
  49. }
  50. throw new AuthException($res["msg"],$res["code"]);
  51. }
  52. /**
  53. * 获取该用户的所有权限(返回树状权限结构)
  54. */
  55. public static function getAuth($token)
  56. {
  57. $url = BASE_AUTH_URL."userGetInfo";
  58. $headers = [
  59. "token"=>$token
  60. ];
  61. $queryParam = array_merge($_POST,$_GET);
  62. $params = [];
  63. if(isset($queryParam["traceId"]) && $queryParam["traceId"]){
  64. $params["traceId"] = $queryParam["traceId"];
  65. }
  66. $res = HttpCurl::getCurl($url,$params,$headers);
  67. if($res["status"]){
  68. return $res["data"];
  69. }
  70. throw new AuthException($res["msg"],$res["code"]);
  71. }
  72. /**
  73. * 修改用户密码
  74. * @param $oldPassword 原始密码
  75. * @param $newPassword 新密码
  76. * @param $token 秘要
  77. */
  78. public static function modifyPassword($oldPassword, $newPassword, $token)
  79. {
  80. $url = BASE_AUTH_URL."user/set_me_password";
  81. $headers = [
  82. "token"=>$token
  83. ];
  84. $params = [
  85. "old_password"=>$oldPassword,
  86. "new_password"=>$newPassword
  87. ];
  88. $queryParam = array_merge($_POST,$_GET);
  89. if(isset($queryParam["traceId"]) && $queryParam["traceId"]){
  90. $params["traceId"] = $queryParam["traceId"];
  91. }
  92. $res = HttpCurl::postCurl($url,$params,$headers,false);
  93. if($res["status"]){
  94. return $res["data"];
  95. }
  96. throw new AuthException($res["msg"],$res["code"]);
  97. }
  98. }