示例#1
0
 /**
  * 系统重置密码
  * $params tel
  */
 public function resetpasswdedit_post()
 {
     $this->load->model('user_model');
     $data = $this->_post_args;
     try {
         // 手机号必须
         if (!isset($data['tel'])) {
             throw new Exception('Invalid request data', 400);
         }
         // test code
         // 判断手机号是否合法
         if (!preg_match("/1[3458]{1}\\d{9}\$/", $data['tel'])) {
             throw new Exception('不符合规范的手机号码', 400);
         }
         // 判断此手机号是否存在
         $user_ifexist = $this->user_model->getUser(array('tel' => $data['tel']));
         if (!$user_ifexist) {
             throw new Exception('手机号码不存在', 409);
             // test code
         }
         // 判断验证码 是否正确
         $usercode = $this->user_model->getUserCode(array('tel' => $data['tel'], 'type' => 2));
         if ($usercode['code'] != $data['verifycode']) {
             throw new Exception('验证码错误', 409);
             // test code
         }
         $this->load->helper('encrypt');
         $id = $this->user_model->updateUser(array('tel' => $data['tel']), array('passwd' => encrypt_md5($data['passwd'])));
     } catch (Exception $e) {
         $this->response(array('error' => $e->getMessage()), $e->getCode());
     }
     if ($id) {
         $user = $this->user_model->getUser(array('tel' => $data['tel']));
         $this->response($user, 201);
         // 201 being the HTTP response code
     } else {
         $this->response(array('error' => '操作失败'), 404);
     }
 }
示例#2
0
 /**
  * 添加/修改用户数据
  */
 public function ajaxUpdateUser()
 {
     $id = intval(true == isset($_POST['id']) ? $_POST['id'] : 0);
     $this->load->library('form');
     $this->form->setHandler('filter_strip_tags_and_clear_space|filter_replace_escape_char');
     $this->load->helper('form/userform');
     $this->load->model('user_model');
     if ($id) {
         $postData = $this->form->check(userupdateform_get_selector());
         $errors = $this->form->getLastMessage();
         if (false == empty($errors)) {
             response_to_json(5, $errors);
         }
         $data = array('username' => $postData['username']['value'], 'provice_sid' => $postData['provice_sid']['value'], 'city_sid' => $postData['city_sid']['value'], 'provice_name' => $postData['provice_name']['value'], 'city_name' => $postData['city_name']['value']);
         // 判断重名
         $usernameexist = $this->user_model->getUser(array('username' => $postData['username']['value'], 'status' => array(1, -2), 'id' => array('$ne', $id)));
         if ($usernameexist) {
             response_to_json(4, '名字已被占用!');
         }
         $affected = $this->user_model->updateUser(array('id' => $id), $data);
         $errors = $this->user_model->getLastMessage();
         $code = 0 == $affected || false == empty($errors) ? 4 : 0;
         $message = false == empty($errors) ? $errors : (0 == $affected ? '操作失败' : '操作成功');
     } else {
         $this->load->helper('encrypt');
         $postData = $this->form->check(useraddform_get_selector());
         $errors = $this->form->getLastMessage();
         if (false == empty($errors)) {
             response_to_json(5, $errors);
         }
         // 判断此手机号是否存在
         $user_ifexist = $this->user_model->getUser(array('tel' => $postData['tel']['value']));
         if ($user_ifexist) {
             response_to_json(4, '此手机号已经存在!');
         }
         $this->load->helper('encrypt');
         $data['username'] = '******' . generate_username(6);
         $data['passwd'] = encrypt_md5(create_password(9));
         $data['tel'] = $postData['tel']['value'];
         $data['usertype'] = $postData['usertype']['value'];
         $data['createtime'] = date('Y-m-d H:i:s', time());
         //判断新注册的手机号是否存在预关系
         $inventdetail = $this->user_model->getinventrel(['phone' => $postData['tel']['value']]);
         if ($inventdetail) {
             $data['ref_userid'] = $inventdetail['uid'];
         }
         $id = $this->user_model->createUser($data);
         $errors = $this->user_model->getLastMessage();
         $code = 0 == $id || false == empty($errors) ? 4 : 0;
         $message = false == empty($errors) ? $errors : (0 == $id ? '操作失败' : '操作成功');
     }
     response_to_json($code, $message);
 }