UserModel::register PHP Method

register() public method

Register a new user.
public register ( array $FormPostValues, array $Options = [] ) : boolean | integer | string
$FormPostValues array
$Options array
return boolean | integer | string
    public function register($FormPostValues, $Options = [])
    {
        $FormPostValues['LastIPAddress'] = ipEncode(Gdn::request()->ipAddress());
        // Check for banning first.
        $Valid = BanModel::checkUser($FormPostValues, null, true);
        if (!$Valid) {
            $this->Validation->addValidationResult('UserID', 'Sorry, permission denied.');
        }
        // Throw an event to allow plugins to block the registration.
        unset($this->EventArguments['User']);
        $this->EventArguments['RegisteringUser'] =& $FormPostValues;
        $this->EventArguments['Valid'] =& $Valid;
        $this->fireEvent('BeforeRegister');
        if (!$Valid) {
            return false;
            // plugin blocked registration
        }
        if (array_key_exists('Gender', $FormPostValues)) {
            $FormPostValues['Gender'] = self::fixGender($FormPostValues['Gender']);
        }
        $Method = strtolower(val('Method', $Options, c('Garden.Registration.Method')));
        switch ($Method) {
            case 'basic':
            case 'captcha':
                // deprecated
                $UserID = $this->insertForBasic($FormPostValues, val('CheckCaptcha', $Options, true), $Options);
                break;
            case 'approval':
                $UserID = $this->insertForApproval($FormPostValues, $Options);
                break;
            case 'invitation':
                $UserID = $this->insertForInvite($FormPostValues, $Options);
                break;
            case 'closed':
                $UserID = false;
                $this->Validation->addValidationResult('Registration', 'Registration is closed.');
                break;
            default:
                $UserID = $this->insertForBasic($FormPostValues, val('CheckCaptcha', $Options, false), $Options);
                break;
        }
        if ($UserID) {
            $this->EventArguments['UserID'] = $UserID;
            $this->fireEvent('AfterRegister');
        }
        return $UserID;
    }

Usage Example

 public static function completeRegister()
 {
     require_once 'User.model.php';
     $data = array();
     if (isset($_POST['createAccount'])) {
         $username = $_POST['username'];
         $password = $_POST['password'];
         $name = $_POST['name'];
         $membership = $_POST['membership'];
         $state = $_POST['state'];
         $email = $_POST['email'];
         $adress = $_POST['adress'];
         $zip_code = $_POST['zip_code'];
         $phone = $_POST['phone'];
         $city = $_POST['city'];
         try {
             $result = UserModel::register($username, $password, $name, $membership, $state, $email, $adress, $zip_code, $phone, $city);
             $data['template'] = 'registerSuccess.html';
         } catch (Exception $e) {
             $data['template'] = 'error.html';
             $data['error'] = $e->getMessage();
         }
     } else {
         $data['redirect'] = '?/User/register';
     }
     return $data;
 }
All Usage Examples Of UserModel::register
UserModel