Example #1
0
 /**
  * 处理提交的安装表单
  *
  * @return void
  */
 public function doAction()
 {
     $installModel = new InstallModel($this);
     $errArr = array();
     $installStep = 0;
     if ($installModel->hasInstalled()) {
         $installStep = 3;
         $this->showInstallForm($installStep, $errArr);
         return;
     }
     if (!$installModel->statReady()) {
         $errArr[] = $installModel->getErrMsg();
     }
     // 检测post提交的数据
     $user = new UserModel($this);
     $postData = new DataMap($_POST);
     $username = $postData->get('username', '');
     $nickname = $postData->get('nickname', '');
     $email = $postData->get('email', '');
     if (!$user->isUsername($username)) {
         $errArr[] = $user->getErrMsg();
     }
     if (!$user->isNickname($nickname)) {
         $errArr[] = $user->getErrMsg();
     }
     if (!$user->isEmail($email)) {
         $errArr[] = $user->getErrMsg();
     }
     $pass1 = $postData->get('pass1', '');
     $pass2 = $postData->get('pass2', '');
     if ($pass1 != $pass2) {
         $errArr[] = '两次输入的密码不一致';
     }
     if (!$user->isPass($pass1)) {
         $errArr[] = $user->getErrMsg();
     }
     if (!empty($errArr)) {
         $installStep = 1;
         $this->showInstallForm($installStep, $errArr);
         return;
     }
     // 执行安装操作
     $installModel->initDb();
     // 添加管理员账号
     $uid = $user->addAccount($username, $nickname, $pass1, $email);
     if ($uid == -1) {
         $installStep = 1;
         $this->showInstallForm($installStep, array('添加用户账号失败'));
         return;
     }
     // 添加管理员权限
     $user->addSuperAdmin($uid);
     $installStep = 2;
     $this->showInstallForm($installStep, array());
 }
Example #2
0
 /**
  * 表单处理
  *
  * @return void
  */
 public function doAction()
 {
     $this->forceInstall();
     $session = new USession($this);
     $sessionData = $session->getSessionData();
     //判断用户是否已登录
     if ($session->getUid() != 0) {
         header('Location: /');
         return;
     }
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $this->showRegForm();
         return;
     }
     $postData = new DataMap($_POST);
     $user = new UserModel($this);
     $errArr = array();
     $username = $postData->get('username', '');
     $nickname = $postData->get('nickname', '');
     $email = $postData->get('email', '');
     $pass1 = $postData->get('pass1', '');
     $pass2 = $postData->get('pass2', '');
     $rcodePost = $postData->get('rcode', '');
     $rcode = $sessionData->get('rcode', '');
     $sessionData->set('rcode', '');
     if (!$user->isUsername($username)) {
         $errArr[] = $user->getErrMsg();
     }
     if (!$user->isNickname($nickname)) {
         $errArr[] = $user->getErrMsg();
     }
     if (!$user->isEmail($email)) {
         $errArr[] = $user->getErrMsg();
     }
     if ($pass1 != $pass2) {
         $errArr[] = '两次输入的密码不一致';
     }
     if (!$user->isPass($pass1)) {
         $errArr[] = $user->getErrMsg();
     }
     if ($rcode == '') {
         $errArr[] = '请打开验证码图片显示';
     }
     if (strcasecmp($rcodePost, $rcode) != 0) {
         $errArr[] = '验证码输入有误';
     }
     if (!empty($errArr)) {
         $this->showRegForm('', $errArr);
         return;
     }
     // 判断用户名、邮箱是否已经被使用
     if ($user->isUsernameExists($username)) {
         $errArr[] = '用户名' . $username . '已经被注册了';
     }
     if ($user->isEmailExists($email)) {
         $errArr[] = '邮箱' . $email . '已经被使用了';
     }
     if (!empty($errArr)) {
         $this->showRegForm('', $errArr);
         return;
     }
     // 添加账号
     $uid = $user->addAccount($username, $nickname, $pass1, $email);
     if ($uid == -1) {
         $errArr[] = '注册账号失败,请稍后再试';
         $this->showRegForm('', $errArr);
     } else {
         $this->showRegOk($uid);
     }
 }
Example #3
0
 public function doAction()
 {
     $this->forceInstall();
     $session = new USession($this);
     $sessionData = $session->getSessionData();
     //判断用户是否已登录
     if ($session->getUid() != 0) {
         header('Location: /');
         return;
     }
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $this->showLoginForm();
         return;
     }
     $postData = new DataMap($_POST);
     $user = new UserModel($this);
     $errArr = array();
     $username = $postData->get('username', '');
     $pass = $postData->get('pass', '');
     $rcodePost = $postData->get('rcode', '');
     $rcode = $sessionData->get('rcode', '');
     $sessionData->set('rcode', '');
     $urlPost = $postData->get('url', '');
     $loginType = 1;
     if ($user->isUsername($username)) {
         $loginType = 1;
     } elseif ($user->isEmail($username)) {
         $loginType = 2;
     } else {
         $errArr[] = '请输入正确的用户名或者邮箱地址';
     }
     if (!$user->isPass($pass)) {
         $errArr[] = $user->getErrMsg();
     }
     if ($rcode == '') {
         $errArr[] = '请打开验证码图片显示';
     }
     if (strcasecmp($rcodePost, $rcode) != 0) {
         $errArr[] = '验证码输入有误';
     }
     if (!empty($errArr)) {
         $this->showLoginForm('', $errArr);
         return;
     }
     // 判断用户名是否存在
     if ($loginType == 1 && !$user->isUsernameExists($username)) {
         $errArr[] = '用户名' . $username . '不存在';
     }
     if ($loginType == 2 && !$user->isEmailExists($username)) {
         $errArr[] = '邮箱' . $username . '不存在';
     }
     if (!empty($errArr)) {
         $this->showLoginForm('', $errArr);
         return;
     }
     $uid = $user->authPass($username, $pass, $loginType);
     if ($uid == -1) {
         if ($loginType == 1) {
             $errArr[] = '用户名或密码错误';
         } elseif ($loginType == 2) {
             $errArr[] = '邮箱或密码错误';
         }
         $this->showLoginForm('', $errArr);
     } else {
         $session->setUid($uid);
         $session->updateLifetime(30 * 24 * 3600);
         $url = $postData->get('url', '');
         if (empty($url)) {
             $urlHandler = $this->getApp()->getUrlHandler();
             $url = $urlHandler->createUrl('web/Index', 'index', array(), false);
         }
         header('Location: ' . $url);
     }
 }
Example #4
0
 /**
  * 返回后台提交的用户名或者邮箱信息
  *
  * @return void
  */
 public function getUserInfoAction()
 {
     $this->forceInstall();
     $session = new USession($this);
     $uid = $session->getUid();
     $urlHandler = $this->getApp()->getUrlHandler();
     if ($uid == 0) {
         $signInUrl = $urlHandler->createUrl('web/SignIn', 'index', array());
         header('Location: ' . $signInUrl);
         return;
     }
     $user = new UserModel($this);
     $isAdmin = $user->isSuperAdmin($uid);
     if (!$isAdmin) {
         $this->needAdmin();
         return;
     }
     // 判断提交的为用户名还是邮箱
     $postData = new DataMap($_POST);
     $inputText = $postData->get('input_text', '');
     if ($inputText == '') {
         $arr = array('success' => false, 'msg' => '用户名或者email不能不空');
         $this->jsonReturn($arr);
         return;
     }
     if ($user->isEmail($inputText)) {
         if ($user->isEmailExists($inputText)) {
             $t_uid = $user->getEmailUid($inputText);
             $userinfo = $user->getUidInfo($t_uid);
             // 防止密码外泄
             unset($userinfo['pass']);
             $arr = array('success' => true, 'info' => $userinfo);
             $this->jsonReturn($arr);
             return;
         } else {
             $arr = array('success' => false, 'msg' => '此email不存在');
             $this->jsonReturn($arr);
             return;
         }
     } elseif ($user->isUsername($inputText)) {
         if ($user->isUsernameExists($inputText)) {
             $t_uid = $user->getUsernameUid($inputText);
             $userinfo = $user->getUidInfo($t_uid);
             unset($userinfo['pass']);
             $arr = array('success' => true, 'info' => $userinfo);
             $this->jsonReturn($arr);
             return;
         } else {
             $arr = array('success' => false, 'msg' => '此用户名不存在');
             $this->jsonReturn($arr);
             return;
         }
     } else {
         $arr = array('success' => false, 'msg' => '请输入正确的用户名或者邮箱');
     }
     $this->jsonReturn($arr);
     return;
 }