public function Handshake() { $this->AddJsFile('entry.js'); $this->Form->SetModel($this->UserModel); $this->Form->AddHidden('ClientHour', date('G', time())); // Use the server's current hour as a default $this->Form->AddHidden('Target', GetIncomingValue('Target', '/')); $Target = GetIncomingValue('Target', '/'); if ($this->Form->IsPostBack() === TRUE) { $FormValues = $this->Form->FormValues(); if (ArrayValue('NewAccount', $FormValues)) { // Try and synchronize the user with the new username/email. $FormValues['Name'] = $FormValues['NewName']; $FormValues['Email'] = $FormValues['NewEmail']; $UserID = $this->UserModel->Synchronize($FormValues['UniqueID'], $FormValues); $this->Form->SetValidationResults($this->UserModel->ValidationResults()); } else { // Try and sign the user in. $Password = new Gdn_PasswordAuthenticator(); $UserID = $Password->Authenticate(array('Email' => ArrayValue('SignInEmail', $FormValues, ''), 'Password' => ArrayValue('SignInPassword', $FormValues, ''))); if ($UserID < 0) { $this->Form->AddError('ErrorPermission'); } else { if ($UserID == 0) { $this->Form->AddError('ErrorCredentials'); } } if ($UserID) { $Data = $FormValues; $Data['UserID'] = $UserID; $Data['Email'] = ArrayValue('SignInEmail', $FormValues, ''); $this->UserModel->Synchronize(ArrayValue('UniqueID', $FormValues, ''), $Data); } } if ($UserID) { $Authenticator = Gdn::Authenticator(); // The user has been created successfully, so sign in now $AuthUserID = $Authenticator->Authenticate(array('UserID' => $UserID)); /// ... and redirect them appropriately $Route = $this->RedirectTo(); if ($this->_DeliveryType != DELIVERY_TYPE_ALL) { $this->RedirectUrl = Url($Route); } else { if ($Route !== FALSE) { Redirect($Route); } } } else { // Add the hidden inputs back into the form. foreach ($FormValues as $Key => $Value) { if (in_array($Key, array('UniqueID', 'DateOfBirth', 'HourOffset', 'Gender', 'Name', 'Email'))) { $this->Form->AddHidden($Key, $Value); } } } } else { // Clear out the authentication and try and get the authentication again. $Authenticator = Gdn::Authenticator(); $Authenticator->SetIdentity(NULL); $Id = $Authenticator->GetIdentity(TRUE); if ($Id > 0) { // The user is signed in so we can just go back to the homepage. Redirect($Target); } /* if ($Authenticator->State() == Gdn_HandshakeAuthenticator::SignedOut) { // Clear out the authentication so it will fetch when we come back here. $Authenticator->SetIdentity(NULL); // Once signed in, we need to come back here to make sure there was no problem with the handshake. $Target = Url('/entry/handshake/?Target='.urlencode($Target), TRUE); // echo $Target; // Redirect to the external server to sign in. $SignInUrl = $Authenticator->RemoteSignInUrl($Target); Redirect($SignInUrl); } */ // There was a handshake error so we need to allow the user to fix the problems. $HandshakeData = $Authenticator->GetHandshakeData(); // Check to see if there is a problem with the handshake. // $this->UserModel->ValidateUniqueFields($HandshakeData['Name'], $HandshakeData['Email']); // $ValidationResults = $this->UserModel->ValidationResults(); // $this->Form->SetValidationResults($ValidationResults); $Name = ArrayValue('Name', $HandshakeData); $Email = ArrayValue('Email', $HandshakeData); // Set the defaults for a new user. $this->Form->SetFormValue('NewName', $Name); $this->Form->SetFormValue('NewEmail', $Email); // Set the default for the login. $this->Form->SetFormValue('SignInEmail', $Email); $this->Form->SetFormValue('Handshake', 'NEW'); // Add the handshake data as hidden fields. foreach ($HandshakeData as $Key => $Value) { $this->Form->AddHidden($Key, $Value); } } $this->SetData('Name', ArrayValue('Name', $this->Form->HiddenInputs)); $this->SetData('Email', ArrayValue('Email', $this->Form->HiddenInputs)); $this->Render(); }
public function InsertUserTable() { // Delete the current user table. $this->Query('truncate table :_User'); // Load the new user table. $UserTableInfo =& $this->Data['Tables']['User']; $this->_InsertTable('User', array('HashMethod' => $this->GetPasswordHashMethod())); $UserTableInfo['Inserted'] = TRUE; // Set the admin user flag. $AdminEmail = GetValue('OverwriteEmail', $this->Data); $this->Query('update :_User set Admin = 1 where Email = :Email', array(':Email' => $AdminEmail)); // Authenticate the admin user as the current user. $Auth = new Gdn_PasswordAuthenticator(); $Auth->Authenticate(array('Email' => GetValue('OverwriteEmail', $this->Data), 'Password' => GetValue('OverwritePassword', $this->Data))); Gdn::Session()->Start($Auth); return TRUE; }