예제 #1
0
 public function __construct()
 {
     $skipLogin = ['user:login', 'user:register'];
     // 可以跳过用户验证的程序
     $route = strtolower($GLOBALS['safeGetParam']['module'] . ':' . $GLOBALS['safeGetParam']['action']);
     if (!in_array($route, $skipLogin)) {
         $inputs = ApiTools::getRequestParams();
         if (!isset($inputs['authcode'])) {
             ApiTools::error(ApiTools::CODE_ERR_LOGIN, "授权信息有误");
         }
         //用户验证等
         $inputs = ApiTools::getRequestParams();
         $authcode = $inputs['authcode'];
         $loginInfo = ApiLoginLogic::authCode($authcode);
         if (!$loginInfo) {
             ApiTools::error(ApiTools::CODE_ERR_LOGIN, "授权信息有误");
         }
         $now = time();
         $this->uid = $loginInfo['uid'];
         if ($now > $loginInfo['lose_time']) {
             ApiTools::error(ApiTools::CODE_ERR_INVALID, "授权已过期");
         }
         $this->userInfo = M('user')->where("id={$this->uid}")->find();
         if (empty($this->userInfo)) {
             ApiTools::error(ApiTools::CODE_ERR_LOGIN, "授权信息有误");
         }
     }
 }
예제 #2
0
 /**
  * 邀请
  */
 public function invite()
 {
     $inputs = ApiTools::getRequestParams();
     $save['uid'] = $this->uid;
     $save['to_uid'] = isset($inputs['fid']) ? $inputs['fid'] : '';
     $save['intro'] = isset($inputs['intro']) ? $inputs['intro'] : '';
     if (empty($save['to_uid'])) {
         ApiTools::error(ApiTools::CODE_MSG, '请选择目标用户');
     }
     if ($save['uid'] == $save['to_uid']) {
         ApiTools::error(ApiTools::CODE_MSG, '不能加自己为好友');
     }
     $isset = M('relation')->where("uid={$save['uid']} and fid={$save['to_uid']}")->find();
     if ($isset) {
         ApiTools::error(ApiTools::CODE_MSG, '好友关系已经建立');
     }
     M('invite')->add($save);
     ApiTools::success(['msg' => 'ok']);
 }
예제 #3
0
 /**
  * 查询用户详细信息
  *
  */
 public function getInfo()
 {
     $inputs = ApiTools::getRequestParams();
     //
     //
     $uid = intval($inputs['uid']);
     //$uid = $this->uid ;
     if (!$uid) {
         ApiTools::error(ApiTools::CODE_ERR_NOT_FOUND, "找不到该用户");
     }
     $info = M('user')->where('id=' . $uid)->field('id,name,avatar')->find();
     if (!empty($info)) {
         $info['avatar'] = getAvatarFullPath($info['avatar']);
         $data = array('info' => $info);
         ApiTools::success($data);
     } else {
         ApiTools::error(ApiTools::CODE_ERR_NOT_FOUND, "找不到该用户");
     }
 }