/** * Invitation-only registration. Requires code. * * Events: RegistrationSuccessful * * @access private * @since 2.0.0 */ private function RegisterInvitation($InvitationCode) { Gdn::UserModel()->AddPasswordStrength($this); if ($this->Form->IsPostBack() === TRUE) { $this->InvitationCode = $this->Form->GetValue('InvitationCode'); // Add validation rules that are not enforced by the model $this->UserModel->DefineSchema(); $this->UserModel->Validation->ApplyRule('Name', 'Username', $this->UsernameError); $this->UserModel->Validation->ApplyRule('TermsOfService', 'Required', T('You must agree to the terms of service.')); $this->UserModel->Validation->ApplyRule('Password', 'Required'); $this->UserModel->Validation->ApplyRule('Password', 'Strength'); $this->UserModel->Validation->ApplyRule('Password', 'Match'); // $this->UserModel->Validation->ApplyRule('DateOfBirth', 'MinimumAge'); $this->FireEvent('RegisterValidation'); try { $Values = $this->Form->FormValues(); $Values = $this->UserModel->FilterForm($Values, TRUE); unset($Values['Roles']); $AuthUserID = $this->UserModel->Register($Values); if (!$AuthUserID) { $this->Form->SetValidationResults($this->UserModel->ValidationResults()); } else { // The user has been created successfully, so sign in now. Gdn::Session()->Start($AuthUserID); if ($this->Form->GetFormValue('RememberMe')) { Gdn::Authenticator()->SetIdentity($AuthUserID, TRUE); } $this->FireEvent('RegistrationSuccessful'); // ... and redirect them appropriately $Route = $this->RedirectTo(); if ($this->_DeliveryType != DELIVERY_TYPE_ALL) { $this->RedirectUrl = Url($Route); } else { if ($Route !== FALSE) { Redirect($Route); } } } } catch (Exception $Ex) { $this->Form->AddError($Ex); } } else { $this->InvitationCode = $InvitationCode; } $this->Render(); }
/** * Continue social login callback once credentials validated. */ protected function social_login_user_add($user_data, $avatar) { $NewUser = array('Name' => $user_data['user_login'], 'Password' => md5(microtime()), 'Email' => $user_data['user_email'], 'ShowEmail' => '0'); if ($avatar == '1' && !empty($user_data['user_thumbnail'])) { $NewUser['Photo'] = $user_data['user_thumbnail']; } $user_id = FALSE; $UserModel = new UserModel(); $user_id = $UserModel->Register($NewUser, array('CheckCaptcha' => FALSE)); if ($user_id === FALSE) { // TODO other validation rules may apply in vanilla... $error_message = 'NO_USER'; trigger_error('NO_USER', E_USER_ERROR); return array($error_message, FALSE); } // Link the user to this social network. $this->link_tokens_to_user_id($user_id, $user_data['user_token'], $user_data['identity_token'], $user_data['identity_provider']); return array(NULL, $user_id); }
/** * Invitation-only registration. Requires code. * * @param int $InvitationCode * @since 2.0.0 */ public function RegisterInvitation($InvitationCode = 0) { $this->Form->SetModel($this->UserModel); // Define gender dropdown options $this->GenderOptions = array('u' => T('Unspecified'), 'm' => T('Male'), 'f' => T('Female')); if (!$this->Form->IsPostBack()) { $this->Form->SetValue('InvitationCode', $InvitationCode); } $InvitationModel = new InvitationModel(); // Look for the invitation. $Invitation = $InvitationModel->GetWhere(array('Code' => $this->Form->GetValue('InvitationCode')))->FirstRow(DATASET_TYPE_ARRAY); if (!$Invitation) { $this->Form->AddError('Invitation not found.', 'Code'); } else { if ($Expires = GetValue('DateExpires', $Invitation)) { $Expires = Gdn_Format::ToTimestamp($Expires); if ($Expires <= time()) { } } } $this->Form->AddHidden('ClientHour', date('Y-m-d H:00')); // Use the server's current hour as a default $this->Form->AddHidden('Target', $this->Target()); Gdn::UserModel()->AddPasswordStrength($this); if ($this->Form->IsPostBack() === TRUE) { $this->InvitationCode = $this->Form->GetValue('InvitationCode'); // Add validation rules that are not enforced by the model $this->UserModel->DefineSchema(); $this->UserModel->Validation->ApplyRule('Name', 'Username', $this->UsernameError); $this->UserModel->Validation->ApplyRule('TermsOfService', 'Required', T('You must agree to the terms of service.')); $this->UserModel->Validation->ApplyRule('Password', 'Required'); $this->UserModel->Validation->ApplyRule('Password', 'Strength'); $this->UserModel->Validation->ApplyRule('Password', 'Match'); // $this->UserModel->Validation->ApplyRule('DateOfBirth', 'MinimumAge'); $this->FireEvent('RegisterValidation'); try { $Values = $this->Form->FormValues(); unset($Values['Roles']); $AuthUserID = $this->UserModel->Register($Values, array('Method' => 'Invitation')); if (!$AuthUserID) { $this->Form->SetValidationResults($this->UserModel->ValidationResults()); } else { // The user has been created successfully, so sign in now. Gdn::Session()->Start($AuthUserID); if ($this->Form->GetFormValue('RememberMe')) { Gdn::Authenticator()->SetIdentity($AuthUserID, TRUE); } $this->FireEvent('RegistrationSuccessful'); // ... and redirect them appropriately $Route = $this->RedirectTo(); if ($this->_DeliveryType != DELIVERY_TYPE_ALL) { $this->RedirectUrl = Url($Route); } else { if ($Route !== FALSE) { Redirect($Route); } } } } catch (Exception $Ex) { $this->Form->AddError($Ex); } } else { // Set some form defaults. if ($Name = GetValue('Name', $Invitation)) { $this->Form->SetValue('Name', $Name); } $this->InvitationCode = $InvitationCode; } // Make sure that the hour offset for new users gets defined when their account is created $this->AddJsFile('entry.js'); $this->Render(); }
// First case if the email user enter an existing email, register fails if (UserModel::Exists("email", $email)) { $msg = ["Failed to register, email already exists, please use a different email", 0]; } else { // ************************************************* this block is google's recaptcha ************************************************************************* //*********************************************** THIS IS FROM GOOGLE RECAPTCHA API *********************************************************************** $secret = "6LejtgYTAAAAAMlSC70hXViKkntfBVU2PBdICylx"; // this is a secret code for reCaptcha connection $ip = gethostbyname($_SERVER['SERVER_NAME']); // this is how you grab end user's ip $captcha = $_POST['g-recaptcha-response']; $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$captcha}&remoteip={$ip}"); $captchaResult = json_decode($response, true); //****************************************************************************************************************************************************************************** if ($captchaResult['success']) { $id = UserModel::Register($email, $password); // Call to Register function in UserModel, returns true if register is a success if ($id) { //***************** SEND ACTIVATION EMAIL ******************************** $userQuery = QueryFactory::Build("select"); $userQuery->Select("email", "created")->From("users")->Where(["id", "=", $id])->Limit(); $res = DatabaseManager::Query($userQuery); $res = $res->Result(); // get result from table $link = sha1($id . $res["email"] . $res["created"]); // get the hash value for the link to send out Mailer::Send("{$email}", "Activation Email", "Please click on the link below to activate your account, http://{$server}/activation.php?id={$id}&link={$link}"); $msg = ["Registration successful, please check your email for account activation", 1]; unset($_POST); } } else {
} else { if (isset($_GET['delete']) && isset($_POST['id'])) { $id = (int) Validator::instance()->Sanitize("int", $_POST['id']); if (is_int($id)) { $delete = QueryFactory::Build("delete")->From("users")->Where(["id", "=", $id]); $res = DatabaseManager::Query($delete); if ($res->RowCount() > 0) { $msg = ["User successfully deleted", 1]; } else { $msg = ["Error deleting user or user does not exist", 0]; } } } else { if (isset($_GET['adduser']) && isset($_POST)) { $activated = $_POST['activated'] === "1" ? 1 : 0; UserModel::Register($_POST['email'], $_POST['pass'], $activated, $_POST['accesslevel']); } } } $select = QueryFactory::Build("select")->Select('id', 'email', 'pLevel', 'created', 'activated')->From("users")->Where(['id', '!=', $user->id, "AND"], ['pLevel', '<=', $user->AccessLevel]); $res = DatabaseManager::Query($select); if ($res->RowCount() < 1) { $res = false; } else { if ($res->RowCount() < 2) { $res = [$res->Result()]; } else { $res = $res->Result(); } } if ($res) {