예제 #1
0
 public function executeNew(sfWebRequest $request)
 {
     if ($request->getMethod() != "POST") {
         return;
     }
     $this->username = $request->getPostParameter("username");
     if (!$this->username) {
         return $this->setErrorMsg("Username is a required field!");
     }
     $this->user = UserDAO::getUser($this->username);
     if ($this->user) {
         return $this->setErrorMsg("That username is already in use!");
     }
     $this->password1 = $request->getPostParameter("password1");
     $this->password2 = $request->getPostParameter("password2");
     if (!$this->password1 || !$this->password2) {
         return $this->setErrorMsg("Password is a required field");
     }
     if ($this->password1 != $this->password2) {
         return $this->setErrorMsg("Password and password confirm must match!");
     }
     $this->email = $request->getPostParameter("email");
     $this->user = UserDAO::createUser($this->username, $this->password1, $this->email);
     $this->login($this->user);
     $this->redirect("dashboard/index");
 }
 public function checkNewUser($username, $name, $surname, $email, $password)
 {
     switch (FALSE) {
         case check_valid_input($username, 6):
             throw new InvalidInputException("false Username Input = input needs to be minimum 6 long, only numbers, letters, capital letters and # @ . - or _");
         case check_valid_input($name, 1):
         case check_no_numbers($name):
             throw new InvalidInputException("false name Input = input needs to be minimum 1 long, only letters, capital letters and # @ . - or _");
         case check_valid_input($surname, 1):
         case check_no_numbers($surname):
             throw new InvalidInputException("false surname Input = input needs to be minimum 1 long, only letters, capital letters and # @ . - or _");
         case check_valid_input($email, 6):
         case check_at($email):
             throw new InvalidInputException("false email Input = input needs to be minimum 6 long, only numbers, letters, capital letters and # @ . - or _");
         case check_password($password):
             throw new InvalidInputException("false password Input = input needs to be minimum 6 long, only numbers, letters, capital letters and # @ . - or _");
     }
     $hashedpwd = passwordEncrypt($username, $password);
     $userDAO = new UserDAO();
     $userDAO->createUser($username, $name, $surname, $email, $hashedpwd);
 }
        var_dump($resultSet);
        $lijst = array();
        foreach ($resultSet as $rij) {
            $u = new User($rij["gebruikersnaam"], $rij["wachtwoord"]);
            array_push($lijst, $u);
        }
        var_dump($lijst);
        $dbh = null;
        return $lijst;
    }
}
$userDAO = new UserDAO();
$users = $userDAO->getAll();
var_dump($users);
$userDOA = new UserDAO();
$newUser = $userDAO->createUser("liesenborghs", "testpwd");
var_dump($newUser);
//class UserService {
//
//    public function storeUser($username, $password) {
//        $userDAO = new UserDAO();
//        $userDAO->createUser($username, $password);
//    }
//
//    public function checkUser($username, $password) {
//        $count = 0;
//        $userDAO = new UserDAO();
//        $userDAO->getAll();
//
//        foreach ($userDAO as $user) {
//            if ($user->getUsername() == $username && $user->getPassword() == $password) {
 public function storeUser($username, $password)
 {
     $userDAO = new UserDAO();
     $userDAO->createUser($username, $password);
 }
 public function storeUser($username, $password)
 {
     $userDAO = new UserDAO();
     $newUser = $userDAO->createUser($username, $password);
     return $newUser;
 }
예제 #6
0
        if ($passwd != $passwd2) {
            $warnings[] = "Passwords don't match";
        }
        if (!isValidPassword($passwd)) {
            $warnings[] = "Not a valid password (longer than " . MIN_PASSWORD_LENGTH . " characters required)";
        }
        if (!isValidUsername($username)) {
            $warnings[] = "Not a valid username (longer than " . MIN_USERNAME_LENGTH . " characters required)";
        }
        // No warnings means everything is in order, and we can create the user
        if (count($warnings) == 0) {
            $dao = new UserDAO();
            if ($dao->userExists($username)) {
                $warnings[] = "Username already taken";
            } else {
                $passwd = pw_encode($passwd);
                if (!$dao->createUser($username, $passwd)) {
                    $warnings[] = "Failed to insert to database";
                } else {
                    // Registration was successful, redirect the user to
                    // the login screen
                    $session->set('register_flag', true);
                    header("Location: login.php");
                    exit;
                }
            }
        }
    }
}
// Include the HTML template:
require __DIR__ . '/../templates/register.php';