public function post($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('POST')); $input = array(); $input['user_name'] = $validator->required('用户名不能为空')->minLength(2, '用户名最短为2个字符')->validate('user_name'); $input['password'] = $validator->required('密码不能为空')->minLength(6, '密码最短为6个非空字符')->validate('password'); $input['email'] = $validator->validate('email'); $input['mobile_phone'] = $validator->digits('手机号格式不对')->validate('mobile_phone'); $p_captcha = $validator->required('验证码不能为空')->validate('captcha'); // 手机输入,输入法经常无故添加空格,我们需要去除所有的空额,防止出错 $p_captcha = Utils::filterAlnumStr($p_captcha); // 需要跳转回去的地址 $returnUrl = $validator->validate('returnUrl'); if (!$this->validate($validator)) { goto out_fail; } // 检查验证码是否有效 $captchaController = new \Controller\Image\Captcha(); if (!$captchaController->validateCaptcha($p_captcha)) { $this->addFlashMessage('验证码错误[' . $p_captcha . '][' . $captchaController->getCaptcha() . ']'); goto out_fail; } $userService = new UserService(); // 检查用户是否已经注册 $isUserExist = $userService->isUserExist($input['user_name'], $input['email']); if ($isUserExist) { $this->addFlashMessage($isUserExist . '已经存在'); goto out_fail; } // 注册用户 $user = $userService->registerUser($input); if (!$user) { $this->addFlashMessage('用户注册失败,请稍后刷新页面重试'); goto out_fail; } // 记录用户的登陆信息 $userInfo = $user->toArray(); unset($userInfo['password']); // 不要记录密码 AuthHelper::saveAuthUser($userInfo, 'normal'); $this->addFlashMessage("注册成功"); if ($returnUrl) { header('Location:' . $returnUrl); return; } else { // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页 RouteHelper::jumpBack($this, '/', true); } return; // 这里正常返回 out_fail: // 失败,从这里出口 $smarty->assign('captchaUrl', RouteHelper::makeUrl('/Image/Captcha', array('hash' => time()))); $smarty->display('user_register.tpl', 'User|Register|post'); }
public function post($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('POST')); $input = array(); $input['user_name'] = $validator->required('用户名不能为空')->validate('user_name'); $input['password'] = $validator->required('密码不能为空')->validate('password'); $p_captcha = $validator->required('验证码不能为空')->validate('captcha'); if (!$this->validate($validator)) { goto out_fail; } // 检查验证码是否有效 $captchaController = new \Controller\Image\Captcha(); if (!$captchaController->validateCaptcha($p_captcha)) { $this->addFlashMessage("验证码错误"); goto out_fail; } $adminService = new AdminUserService(); // 验证用户登陆 $admin = $adminService->doAuthAdmin($input['user_name'], $input['user_name'], $input['password']); if (!$admin) { $this->addFlashMessage("登陆失败,用户名、密码错误"); goto out_fail; } // 记录用户的登陆信息 $adminUserInfo = $admin->toArray(); unset($adminUserInfo['password']); // 不要记录密码 // 取得用户的角色权限 $adminUserInfo['role_action_list'] = ''; if ($adminUserInfo['role_id'] > 0) { $metaRoleService = new MetaRoleService(); $role = $metaRoleService->loadRoleById($adminUserInfo['role_id']); if (!$role->isEmpty()) { // 赋值角色权限 $adminUserInfo['role_action_list'] = $role['meta_data']; } } AuthHelper::saveAuthUser($adminUserInfo); try { // 记录用户登录日志 AdminLog::logAdminOperate('user.login', '用户登录', 'IP:' . $f3->get('IP')); } catch (\Exception $e) { // do nothing } $this->addFlashMessage("登陆成功"); // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页 RouteHelper::jumpBack($this, '/', true); return; // 这里正常返回 out_fail: // 失败从这里入口 $smarty->display('user_login.tpl', 'User|Login|post'); }
public function post($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('POST')); $input = array(); $input['user_name'] = $validator->required('用户名不能为空')->minLength(2, '用户名最短为2个字符')->validate('user_name'); $input['password'] = $validator->required('密码不能为空')->minLength(6, '密码最短为6个非空字符')->validate('password'); $input['email'] = $validator->validate('email'); $input['mobile_phone'] = $validator->digits('手机号格式不对')->validate('mobile_phone'); $p_captcha = $validator->required('验证码不能为空')->validate('captcha'); if (!$this->validate($validator)) { goto out_fail; } // 检查验证码是否有效 $captchaController = new \Controller\Image\Captcha(); if (!$captchaController->validateCaptcha($p_captcha)) { $this->addFlashMessage("验证码错误"); goto out_fail; } $userService = new UserService(); // 检查用户是否已经注册 $isUserExist = $userService->isUserExist($input['user_name'], $input['email']); if ($isUserExist) { $this->addFlashMessage($isUserExist . '已经存在'); goto out_fail; } // 注册用户 $user = $userService->registerUser($input); if (!$user) { $this->addFlashMessage('用户注册失败,请稍后刷新页面重试'); goto out_fail; } // 记录用户的登陆信息 $userInfo = $user->toArray(); unset($userInfo['password']); // 不要记录密码 AuthHelper::saveAuthUser($userInfo, 'normal'); // 设置用户名在网页显示 ClientData::saveClientData(Login::$clientDataIsUserLoginKey, true); ClientData::saveClientData(Login::$clientDataUserNameDisplayKey, $user->user_name); $this->addFlashMessage("注册成功"); // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页 RouteHelper::jumpBack($this, '/', true); return; // 这里正常返回 out_fail: // 失败,从这里出口 $smarty->display('user_login.tpl', 'User|Register|post'); }
public function post($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('POST')); $input = array(); $input['user_name'] = $validator->required('用户名不能为空')->validate('user_name'); $input['password'] = $validator->required('密码不能为空')->validate('password'); $p_captcha = $validator->required('验证码不能为空')->validate('captcha'); // 手机输入,输入法经常无故添加空格,我们需要去除所有的空额,防止出错 $p_captcha = Utils::filterAlnumStr($p_captcha); // 需要跳转回去的地址 $returnUrl = $validator->validate('returnUrl'); if (!$this->validate($validator)) { goto out_fail; } // 检查验证码是否有效 $captchaController = new \Controller\Image\Captcha(); if (!$captchaController->validateCaptcha($p_captcha)) { $this->addFlashMessage('验证码错误[' . $p_captcha . '][' . $captchaController->getCaptcha() . ']'); goto out_fail; } $userService = new UserService(); // 验证用户登陆 $user = $userService->doAuthUser($input['user_name'], $input['user_name'], $input['password']); if (!$user) { $this->addFlashMessage("登陆失败,用户名、密码错误"); goto out_fail; } // 记录用户的登陆信息 $userInfo = $user->toArray(); unset($userInfo['password']); // 不要记录密码 AuthHelper::saveAuthUser($userInfo, 'normal'); $this->addFlashMessage("登陆成功"); if ($returnUrl) { header('Location:' . $returnUrl); return; } else { // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页 RouteHelper::jumpBack($this, '/', true); } return; // 这里正常返回 out_fail: // 失败从这里出口 $smarty->assign('captchaUrl', RouteHelper::makeUrl('/Image/Captcha', array('hash' => time()))); $smarty->display('user_login.tpl', 'User|Login|post'); }
public function post($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('POST')); $input = array(); $input['user_name'] = $validator->required('用户名不能为空')->validate('user_name'); $input['password'] = $validator->required('密码不能为空')->validate('password'); $p_captcha = $validator->required('验证码不能为空')->validate('captcha'); if (!$this->validate($validator)) { goto out_fail; } // 检查验证码是否有效 $captchaController = new \Controller\Image\Captcha(); if (!$captchaController->validateCaptcha($p_captcha)) { $this->addFlashMessage("验证码错误"); goto out_fail; } $userService = new UserService(); // 验证用户登陆 $user = $userService->doAuthUser($input['user_name'], $input['user_name'], $input['password']); if (!$user) { $this->addFlashMessage("登陆失败,用户名、密码错误"); goto out_fail; } // 记录用户的登陆信息 $userInfo = $user->toArray(); unset($userInfo['password']); // 不要记录密码 AuthHelper::saveAuthUser($userInfo, 'normal'); // 设置用户名在网页显示 ClientData::saveClientData(Login::$clientDataIsUserLoginKey, true); ClientData::saveClientData(Login::$clientDataUserNameDisplayKey, $user->user_name); $this->addFlashMessage("登陆成功"); // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页 RouteHelper::jumpBack($this, '/', true); return; // 这里正常返回 out_fail: // 失败从这里入口 $smarty->display('user_login.tpl', 'User|Login|post'); }