123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace Tool\MayouTool\BaseAuth;
- use Tool\MayouTool\Bean\BaseAuth\AddUserParamBean;
- use Tool\MayouTool\Exception\AuthException;
- use Tool\MayouTool\HttpCurl;
- class AdminAuth
- {
- /**
- * 登录
- * @param string $userName 用户名
- * @param string $userPassword 密码
- */
- public static function login($userName, $userPassword,$userProjectId)
- {
- $url = BASE_AUTH_URL."user/login";
- $params = [
- "user_name"=>$userName,
- "user_password"=>$userPassword,
- "user_project_id"=>$userProjectId
- ];
- $queryParam = array_merge($_POST,$_GET);
- if(isset($queryParam["traceId"]) && $queryParam["traceId"]){
- $params["traceId"] = $queryParam["traceId"];
- }
- $res = HttpCurl::postCurl($url,$params,[],false);
- if($res["status"]){
- return $res["data"];
- }
- throw new AuthException($res["msg"],$res["code"]);
- }
- /**
- * 检测用户是否拥有此权限
- * @param string $path
- */
- public static function checkUserAuth($path,$token)
- {
- $url = BASE_AUTH_URL."checkNodeAuth";
- $headers = [
- "token"=>$token,
- "path"=>$path
- ];
- $queryParam = array_merge($_POST,$_GET);
- if(isset($queryParam["traceId"]) && $queryParam["traceId"]){
- $params["traceId"] = $queryParam["traceId"];
- }
- $res = HttpCurl::postCurl($url,[],$headers,false);
- if($res["status"]){
- return $res["data"];
- }
- throw new AuthException($res["msg"],$res["code"]);
- }
- /**
- * 获取该用户的所有权限(返回树状权限结构)
- */
- public static function getAuth($token)
- {
- $url = BASE_AUTH_URL."userGetInfo";
- $headers = [
- "token"=>$token
- ];
- $queryParam = array_merge($_POST,$_GET);
- $params = [];
- if(isset($queryParam["traceId"]) && $queryParam["traceId"]){
- $params["traceId"] = $queryParam["traceId"];
- }
- $res = HttpCurl::getCurl($url,$params,$headers);
- if($res["status"]){
- return $res["data"];
- }
- throw new AuthException($res["msg"],$res["code"]);
- }
- /**
- * 修改用户密码
- * @param $oldPassword 原始密码
- * @param $newPassword 新密码
- * @param $token 秘要
- */
- public static function modifyPassword($oldPassword, $newPassword, $token)
- {
- $url = BASE_AUTH_URL."user/set_me_password";
- $headers = [
- "token"=>$token
- ];
- $params = [
- "old_password"=>$oldPassword,
- "new_password"=>$newPassword
- ];
- $queryParam = array_merge($_POST,$_GET);
- if(isset($queryParam["traceId"]) && $queryParam["traceId"]){
- $params["traceId"] = $queryParam["traceId"];
- }
- $res = HttpCurl::postCurl($url,$params,$headers,false);
- if($res["status"]){
- return $res["data"];
- }
- throw new AuthException($res["msg"],$res["code"]);
- }
- }
|