当前位置: 首页>>代码示例>>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;未经允许,请勿转载。