예제 #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());
 }
예제 #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);
     }
 }