public function Controller_Validate($Sender) { $form_values = array('user_email' => $Sender->Form->GetValue('user_email'), 'user_login' => $Sender->Form->GetValue('user_login'), 'val_id' => $Sender->Form->GetValue('val_id')); $oasl = new SocialLogin(); $oa_profile = $oasl->get_validation_data($form_values['val_id']); if ($oa_profile === FALSE) { SafeRedirect(Url(Gdn::Router()->GetDestination('DefaultController'), TRUE)); } $to_validate = array_merge($form_values, $oa_profile); if ($Sender->Form->IsPostBack() == TRUE) { // Verify new user submitted data: // TODO explore vanilla validation: as in $Valid = Gdn_Validation::ValidateRule ($to_validate ['user_email'], 'Email', 'function:ValidateEmail'); $valid = TRUE; if (empty($to_validate['user_login'])) { $to_validate['user_login'] = $to_validate['identity_provider'] . 'User'; $valid = FALSE; } if ($oasl->get_user_id_by_username($to_validate['user_login']) !== FALSE) { $i = 1; $user_login_tmp = $to_validate['user_login'] . $i; while ($oasl->get_user_id_by_username($user_login_tmp) !== FALSE) { $user_login_tmp = $to_validate['user_login'] . $i++; } $to_validate['user_login'] = $user_login_tmp; $valid = FALSE; } if (empty($to_validate['user_email'])) { $Sender->Form->AddError('OA_SOCIAL_LOGIN_VALIDATION_FORM_EMAIL_NONE_EXPLAIN', 'user_email'); $valid = FALSE; } if ($oasl->get_user_id_by_email($to_validate['user_email']) !== FALSE) { $to_validate['user_email'] = ''; $Sender->Form->AddError('OA_SOCIAL_LOGIN_VALIDATION_FORM_EMAIL_EXISTS_EXPLAIN', 'user_email'); $valid = FALSE; } if ($valid) { $avatar = C(self::CONFIG_PREFIX . 'AvatarsEnable', 1); $redirect = C(self::CONFIG_PREFIX . 'Redirect', ''); $to_validate['redirect'] = empty($redirect) ? Url($to_validate['redirect'], TRUE) : $redirect; $oasl->delete_validation_data($to_validate['val_id']); $oasl->social_login_resume_handle_callback($to_validate, $avatar); } } $Sender = $this->set_validation_fields($Sender, $to_validate); $Sender->Render($this->GetView('oa_social_login_validate.php')); }