예제 #1
0
 // if the password fields do not match
 // then throw an exception
 if (!empty($formdata['password']) && !empty($formdata['password2']) && $formdata['password'] != $formdata['password2']) {
     $errors['password'] = "******";
 }
 if (empty($errors)) {
     // since none of the form fields were empty,
     // store the form data in variables
     $username = $formdata['username'];
     $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);