當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UserDAO::initializeUserPrefs方法代碼示例

本文整理匯總了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"];
     }
 }
開發者ID:dremex,項目名稱:trackyourclimb,代碼行數:39,代碼來源:UserService.php


注:本文中的UserDAO::initializeUserPrefs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。