public function signupHandler() { $username = Util::fetch_post('username'); $password = Util::fetch_post('password'); $realname = Util::fetch_post('realname'); if ($username == null || $password == null || $realname == null) { $this->error(2); } $userTable = new UserTable(); if ($userTable->is_exist($username)) { $this->errorMsg('该用户已存在'); } // 插入数据 $userTable->insert($username, $password, $realname); $result = $userTable->select($username, $password); $userExtraTable = new UserExtraTable(); $userExtraTable->insert($result['user_id']); SQLUtil::login($username, $password); Util::go(URL . 'manager/'); }
$password = $formdata['password']; $password2 = $formdata['password2']; // create a UserTable object and use it to retrieve // the users $connection = dbconnection::getConnection(); $userTable = new UserTable($connection); $user = $userTable->getUserByUsername($username); // since password fields match, see if the username // has already been registered - if it is then throw // and exception if ($user != null) { $errors['username'] = "******"; } } if (!empty($errors)) { throw new Exception(); } // since the username is not aleady registered, create // a new User object, add it to the database using the // UserTable object, and store it in the session array $user = new User(null, $username, $password, "user"); $id = $userTable->insert($user); $user->setId($id); $_SESSION['user'] = $user; //once logged in redirect to home header('Location: index.php'); } catch (Exception $ex) { // if an exception occurs then extract message, redisplay registration form $errorMessage = $ex->getMessage(); require 'registerform.php'; }