本文整理汇总了PHP中UserDAO::initializeUserPrefs方法的典型用法代码示例。如果您正苦于以下问题:PHP UserDAO::initializeUserPrefs方法的具体用法?PHP UserDAO::initializeUserPrefs怎么用?PHP UserDAO::initializeUserPrefs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserDAO
的用法示例。
在下文中一共展示了UserDAO::initializeUserPrefs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerUser
public function registerUser($username, $password, $email)
{
/*
* Perform validation and create all required entries for new user in database
*
* Input: $password is in plaintext
* Ouput: ["result" => true, "userid" => {userid}, "passhash" => {passhash}] if successful
* ["result" => false, "error" => {error message}] if not successful
*/
// Perform check that username/email is not already taken
// and password is valid (not empty)
$userDAO = new UserDAO();
if ($userDAO->checkUsernameExists($username)) {
return ["result" => false, "error" => "Username is already in use."];
}
if ($userDAO->checkEmailExists($email)) {
return ["result" => false, "error" => "Email is already in use."];
}
if (empty($password)) {
return ["result" => false, "error" => "Password should be non-empty"];
}
$password_encrypted = password_hash($password, PASSWORD_DEFAULT);
//return newly-created userID (null if unsuccessful)
$userid = $userDAO->addUser($username, $password_encrypted, $email);
//initialize empty row in userdata, userprefs, and userrecords table
$userdataSuccess = $userDAO->initializeUserData($userid);
$userprefsSuccess = $userDAO->initializeUserPrefs($userid);
$userrecordsSuccess = $userDAO->initializeUserRecords($userid);
//add email to MailChimp list
$MailChimp = initialize_mailchimp();
mailchimp_subscribe($_POST['email'], $MailChimp);
//check if user added successfully
$add_member = !is_null($userid) && $userdataSuccess && $userprefsSuccess && $userrecordsSuccess;
if ($add_member) {
return ["result" => true, "userid" => $userid, "passhash" => $password_encrypted];
} else {
return ["result" => false, "error" => "Database error: Could not successfully create user"];
}
}