/** * 修改手机号 * */ public function postChangePhone() { $retCode = SUCCESS; $retMsg = ""; do { $user = Auth::user(); $userPhone = Input::get('user_phone'); $authCode = Input::get('user_auth_code'); if (!preg_match('/^1\\d{10}$/i', $userPhone)) { $retCode = -10033; $retMsg = Lang::get('errormessages.-10033'); $context = array("errorCode" => $retCode, "userID" => $user->wy_user_id, "userPhone" => $userPhone); break; } if ($userPhone == $user->wy_phone) { $retCode = -10034; $retMsg = Lang::get('errormessages.-10034'); $context = array("errorCode" => $retCode, "userID" => $user->wy_user_id, "userPhone" => $userPhone, "oldUserPhone" => $user->wy_phone); break; } $userTemp = User::where('wy_phone', $userPhone)->first(array('wy_phone')); if (!empty($userTemp)) { $retCode = -10035; $retMsg = Lang::get('errormessages.-10035'); $context = array("errorCode" => $retCode, "userID" => $user->wy_user_id, "userPhone" => $userPhone); break; } $registCode = RegistCode::find($userPhone); if (empty($registCode)) { $retCode = -10038; $retMsg = Lang::get('errormessages.-10038'); $context = array("errorCode" => $retCode, "userID" => $user->wy_user_id, "userPhone" => $userPhone); break; } else { $updateTime = strtotime($registCode->update_time); $nowTime = strtotime(Carbon::now()); $breakTime = ceil(($nowTime - $updateTime) / AUTHCODE_MIN); if ($breakTime < AUTHCODE_TIME) { if (0 != strcmp($authCode, $registCode->code)) { $retCode = -10036; $retMsg = Lang::get('errormessages.-10036'); $context = array("errorCode" => $retCode, "userID" => $user->wy_user_id, "authCode" => $authCode, "registCode" => $registCode->code); break; } } else { $retCode = -10037; $retMsg = Lang::get('errormessages.-10037'); $context = array("errorCode" => $retCode, "userID" => $user->wy_user_id, "authCode" => $authCode, "registCode" => $registCode->code, "breakTime" => $breakTime); break; } } $user->wy_phone = $userPhone; if ($user->save()) { return View::make('admin.manage.user.user_changephonefinish')->withSuccess(Lang::get('messages.10022')); } else { $retCode = -15009; $retMsg = Lang::get('errormessages.-15009'); $context = array("errorCode" => $retCode, "userID" => $user->wy_user_id, "userPhone" => $userPhone); break; } } while (false); if (isset($context)) { Log::error($retMsg, $context); } else { Log::error($retMsg); } $sendMsgArray = array("ret_code" => $retCode, "msg" => $retMsg); return Response::json($sendMsgArray); }
/** * 处理忘记密码 * * @return [Response] [成功与否界面] */ public function postForgotPassword() { $retCode = SUCCESS; $retMsg = ""; do { // 获取表单数据 $data = Input::all(); // 建立验证规则 $rules = array('user_pwd' => 'confirmed|max:16|alpha_dash'); $validator = Validator::make($data, $rules); if ($validator->fails()) { $retCode = -10012; foreach ($validator->messages()->all() as $message) { $retMsg .= $message; } $context = array("errorCode" => $retCode, "data" => $data); break; } $userPhone = Session::get('userPhone'); $user = User::where('wy_phone', $userPhone)->first(); if (empty($user)) { $retCode = -10013; $retMsg = Lang::get('errormessages.-10013'); $context = array("errorCode" => $retCode, "userPhone" => $userPhone); break; } $userPwd = Input::get('user_pwd'); if (Hash::check($userPwd, $user->wy_pwd)) { $retCode = -10014; $retMsg = Lang::get('errormessages.-10014'); break; } $authCode = Session::get('authCode'); $registCode = RegistCode::find($userPhone); if (empty($registCode)) { $retCode = -10015; $retMsg = Lang::get('errormessages.-10015'); $context = array("errorCode" => $retCode, "userPhone" => $userPhone); break; } else { $updateTime = strtotime($registCode->update_time); $nowTime = strtotime(Carbon::now()); $breakTime = ceil(($nowTime - $updateTime) / AUTHCODE_MIN); if ($breakTime < AUTHCODE_TIME) { if (0 != strcmp($authCode, $registCode->code)) { $retCode = -10016; $retMsg = Lang::get('errormessages.-10016'); $context = array("errorCode" => $retCode, "authCode" => $authCode, "registCode" => $registCode->code); break; } } else { $retCode = -10017; $retMsg = Lang::get('errormessages.-10017'); $context = array("errorCode" => $retCode, "authCode" => $authCode, "registCode" => $registCode->code, "breakTime" => $breakTime); break; } } $user->wy_pwd = Hash::make($userPwd); if ($user->save()) { Session::flush(); return View::make('admin.auth.forgotpassword_finish')->withSuccess(Lang::get('messages.10017')); } else { $retCode = -15003; $retMsg = Lang::get('errormessages.-15003'); break; } } while (false); if (isset($context)) { Log::error($retMsg, $context); } else { Log::error($retMsg); } $sendMsgArray = array("ret_code" => $retCode, "msg" => $retMsg); return Response::json($sendMsgArray); }