Exemplo n.º 1
0
 /**
  * 用户登陆
  * @method POST
  */
 public function login()
 {
     $post = $this->get_data();
     $mobile = trim($post['mobile']);
     $zone_code = $post['zone_code'] ? trim($post['zone_code']) : ($post['zonecode'] ? trim($post['zonecode']) : '86');
     $zone_code = str_replace('+', '', $zone_code);
     $password = trim($post['password']);
     if (empty($mobile)) {
         $this->send_response(400, NULL, '40001:手机号为空');
     }
     if (!international::check_is_valid($zone_code, $mobile)) {
         $this->send_response(400, NULL, '40002:手机号码格式不对');
     }
     if ($password == "") {
         $this->send_response(400, NULL, '40003:密码为空');
     }
     $user = $this->model->get_user_by_mobile($zone_code, $mobile);
     if (!$user) {
         $this->send_response(400, NULL, Kohana::lang('user.mobile_not_register'));
     }
     if (!password_verify($password, $user['password'])) {
         $this->send_response(400, NULL, Kohana::lang('user.username_password_not_match'));
     }
     $token = $this->model->create_token(3600, TRUE, array('zone_code' => $user['zone_code'], 'mobile' => $user['mobile'], 'id' => (int) $user['id']));
     $this->send_response(200, array('id' => (int) $user['uid'], 'name' => $user['username'], 'avatar' => sns::getavatar($user['uid']), 'access_token' => $token['access_token'], 'refresh_token' => $token['refresh_token'], 'expires_in' => $token['expires_in']));
 }
Exemplo n.º 2
0
 /**
  * 检查用户是否合法的回调方法
  * @param  $type   活动类型值
  */
 public function _check_user_validation($post)
 {
     $array = $post->as_array();
     foreach ($array['user'] as $k => $v) {
         if (empty($v['name'])) {
             $post->add_error('user_name_empty', 'user_name_empty');
         }
         if (empty($v['mobile'])) {
             $post->add_error('user_mobile_empty', 'user_mobile_empty');
         }
         if (!international::check_is_valid('86', $v['mobile'])) {
             $post->add_error('user_mobile_format', 'user_mobile_format');
         }
     }
 }
Exemplo n.º 3
0
 public function token()
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     $data = $this->get_data();
     $zone_code = isset($data['zone_code']) ? $data['zone_code'] : '';
     $mobile = isset($data['mobile']) ? $data['mobile'] : '';
     $code = isset($data['code']) ? $data['code'] : '';
     if (!international::check_is_valid($zone_code, $mobile)) {
         $this->send_response(400, NULL, Kohana::lang('authorization.mobile_invalid'));
     }
     $username = $this->model->get_full_mobile($zone_code, $mobile);
     if (!$this->is_test_mobile($mobile)) {
         if (!$this->model->check_verify_code($username, $code)) {
             $this->send_response(400, NULL, Kohana::lang('authorization.code_invalid'));
         }
     }
     $user = $this->model->get_user_by_mobile($zone_code, $mobile);
     if ($user) {
         $id = $user['id'];
     } else {
         $regip = $this->get_ip();
         $id = $this->model->create_user($zone_code, $mobile, '', $regip);
     }
     $token = $this->model->create_token(3600, TRUE, array('zone_code' => $zone_code, 'mobile' => $mobile, 'id' => (int) $id));
     if ($user) {
         $token['name'] = $user['username'];
         $token['avatar'] = sns::getavatar($user['id']);
     }
     $this->send_response(200, $token);
 }