/** * 重置密码验证 * 包括邮件重置密码和短信重置密码都在这里统一验证 * @param HttpRequest $request */ public function password(HttpRequest $request) { $email = $request->getParameter('email', 'trim'); $authcode = $request->getParameter('authcode', 'trim'); $mobile = $request->getParameter('mobile', 'trim'); $password = $request->getParameter('password', 'trim'); $repass = $request->getParameter('repass', 'trim'); $userid = $request->getParameter('userid', 'intval'); if ($email != '') { $__authcode = getEmailCode($email, 7200); } else { if ($mobile != '') { $__authcode = getMobileCode($mobile, 600); } } if ($__authcode != $authcode) { AjaxResult::ajaxResult('error', '授权码错误'); } if ($password != $repass) { AjaxResult::ajaxResult('error', '两次输入密码不一致'); } $userService = Beans::get('user.user.service'); if ($userService->set('password', md5(md5($password)), $userid)) { AjaxResult::ajaxSuccessResult(); } else { AjaxResult::ajaxFailtureResult(); } }
/** * 重新绑定手机 * @param HttpRequest $request */ public function bindMobile(HttpRequest $request) { $mobile = $request->getParameter('mobile', 'trim'); $password = $request->getParameter('password', 'trim'); $authcode = $request->getParameter('authcode', 'trim'); //验证登录密码 $userService = Beans::get('user.user.service'); $conditions = array('username' => $this->loginUser['username'], 'password' => md5(md5($password))); if ($userService->count($conditions) == 0) { AjaxResult::ajaxResult('error', '登录密码错误!'); } //验证授权码 $__authcode = getMobileCode($mobile, 600); if ($__authcode != $authcode) { AjaxResult::ajaxResult('error', '授权码错误!'); } $mediaService = Beans::get('media.media.service'); $data = array('mobile' => $mobile); if ($mediaService->update($data, $this->loginUser['id'])) { $this->updateLoginMedia($data); AjaxResult::ajaxSuccessResult(); } else { AjaxResult::ajaxFailtureResult(); } }
/** * 手机用户注册 * @param HttpRequest $request */ public function mobileReg(HttpRequest $request) { $authcode = $request->getParameter('authcode', 'trim'); $data = $request->getParameter('data'); $repass = $request->getParameter('repass', 'trim'); if ($authcode == '') { AjaxResult::ajaxResult('error', '请输入手机授权码!'); } if ($repass != trim($data['password'])) { AjaxResult::ajaxResult('error', '两次输入密码不一致!'); } if (strlen($data['password']) > 20 || strlen($data['password']) < 6) { AjaxResult::ajaxResult('error', '密码的长度必须在6-20位之间!'); } //获取手机发送的授权码 $__authcode = getMobileCode($data['mobile']); if ($__authcode != $authcode) { AjaxResult::ajaxResult('error', '手机授权码错误!'); } $userService = Beans::get('user.user.service'); //验证手机号码 if ($userService->checkField('mobile', trim($data['mobile']))) { AjaxResult::ajaxResult('error', "手机号码{$data['mobile']}已被注册,请更换手机号!"); } //验证用户名 if ($userService->checkField('username', trim($data['username']))) { AjaxResult::ajaxResult('error', '用户名已经存在,请更换用户名!'); } //初始化信息 $data['password'] = md5(md5($data['password'])); $data['nickname'] = $data['username']; $data['add_time'] = time(); $data['update_time'] = time(); $data['group_id'] = 1; //手机验证通过 $data['mobile_check'] = 1; $data['ischeck'] = 1; $success = $userService->register($data); if ($success) { AjaxResult::ajaxResult('ok', url('/user_login_index')); } else { AjaxResult::ajaxResult('error', '注册失败'); } }