本文整理汇总了PHP中Auth_OpenID_SRegResponse::fromSuccessResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP Auth_OpenID_SRegResponse::fromSuccessResponse方法的具体用法?PHP Auth_OpenID_SRegResponse::fromSuccessResponse怎么用?PHP Auth_OpenID_SRegResponse::fromSuccessResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Auth_OpenID_SRegResponse
的用法示例。
在下文中一共展示了Auth_OpenID_SRegResponse::fromSuccessResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: check
function check()
{
$this->config->load('openid');
$request_to = site_url($this->config->item('openid_request_to'));
$this->openid->set_request_to($request_to);
$response = $this->openid->getResponse();
switch ($response->status) {
case Auth_OpenID_CANCEL:
$data['msg'] = $this->lang->line('openid_cancel');
break;
case Auth_OpenID_FAILURE:
$data['error'] = $this->_set_message('openid_failure', $response->message);
break;
case Auth_OpenID_SUCCESS:
$openid = $response->getDisplayIdentifier();
$esc_identity = htmlspecialchars($openid, ENT_QUOTES);
$data['success'] = $this->_set_message('openid_success', array($esc_identity, $esc_identity), array('%s', '%t'));
if ($response->endpoint->canonicalID) {
$data['success'] .= $this->_set_message('openid_canonical', $response->endpoint->canonicalID);
}
$sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
$sreg = $sreg_resp->contents();
foreach ($sreg as $key => $value) {
$data['success'] .= $this->_set_message('openid_content', array($key, $value), array('%s', '%t'));
}
$pape_resp = Auth_OpenID_PAPE_Response::fromSuccessResponse($response);
if ($pape_resp) {
if ($pape_resp->auth_policies) {
$data['success'] .= $this->lang->line('openid_pape_policies_affected');
foreach ($pape_resp->auth_policies as $uri) {
$data['success'] .= "<li><tt>{$uri}</tt></li>";
}
$data['success'] .= "</ul>";
} else {
$data['success'] .= $this->lang->line('openid_pape_not_affected');
}
if (isset($pape_resp->auth_age) && $pape_resp->auth_age) {
$data['success'] .= $this->_set_message('openid_auth_age', $pape_resp->auth_age);
}
if ($pape_resp->nist_auth_level) {
$data['success'] .= $this->_set_message('openid_nist_level', $pape_resp->nist_auth_level);
}
} else {
$data['success'] .= $this->lang->line('openid_pape_noresponse');
}
break;
}
$data['pape_policy_uris'] = array(PAPE_AUTH_MULTI_FACTOR_PHYSICAL, PAPE_AUTH_MULTI_FACTOR, PAPE_AUTH_PHISHING_RESISTANT);
// echo "nickname: $nickname";
// echo "esc_identity: $esc_identity";
$this->load->view('view_openid', $data);
}
示例2: perform
/**
* login_finish action implementation.
*
* @access public
* @return string forward name.
*/
public function perform()
{
// if login do?
$identity = $this->af->get('openid_identity');
if ($this->af->get('janrain_nonce')) {
require_once 'Auth/OpenID.php';
require_once "Auth/OpenID/Consumer.php";
require_once "Auth/OpenID/FileStore.php";
require_once "Auth/OpenID/SReg.php";
require_once "Auth/OpenID/PAPE.php";
$store_path = $this->backend->getController()->getDirectory('tmp') . "/openid_filestore";
$consumer = new Auth_OpenID_Consumer(new Auth_OpenID_FileStore($store_path));
$response = $consumer->complete($this->config->get('url') . "login_finish");
if ($response->status == Auth_OpenID_CANCEL) {
// This means the authentication was cancelled.
$this->ae->add(null, "認証がキャンセルされました.Pastitを利用するには認証してください.");
return 'login';
} else {
if ($response->status == Auth_OpenID_FAILURE) {
// Authentication failed; display the error message.
$this->ae->add(null, "認証に失敗しました.(" . $response->message . ")");
return 'login';
} else {
if ($response->status == Auth_OpenID_SUCCESS) {
$openid_success_url = $response->getDisplayIdentifier();
$sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
$sreg = $sreg_resp->contents();
$nickname = isset($sreg['nickname']) ? $sreg['nickname'] : "";
$this->session->set("identity", $identity);
$this->session->set("openid_success_url", $openid_success_url);
}
}
}
}
$um = $this->backend->getManager('user');
if ($user = $um->getUserByIdentity($identity)) {
$this->session->set('user', $user);
return array('redirect', '/');
} else {
if (!Ethna::isError($id = $um->create($identity, $nickname))) {
$user = $um->getUser($id);
$this->session->set('user', $user);
return array('redirect', 'setting');
} else {
$this->ae->addObject('name', $id);
return 'error500';
}
}
return 'login';
}
示例3: openid_check
function openid_check($ci, $callback_url, &$data)
{
if (!isset($data)) {
$data = array();
}
$ci->lang->load('openid');
$ci->config->load('openid');
$ci->openid->set_request_to($callback_url);
$response = $ci->openid->getResponse();
switch ($response->status) {
case Auth_OpenID_CANCEL:
push_message($ci->lang->line('openid_cancel'), 'error', $ci);
break;
case Auth_OpenID_FAILURE:
push_message(set_message('openid_failure', $response->message), 'error', $ci);
break;
case Auth_OpenID_SUCCESS:
$openid = $response->getDisplayIdentifier();
$esc_identity = htmlspecialchars($openid, ENT_QUOTES);
$data['openid_identifier'] = $openid;
$sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
$sreg = $sreg_resp->contents();
$ax_resp = new Auth_OpenID_AX_FetchResponse();
$ax = $ax_resp->fromSuccessResponse($response);
if (isset($sreg['email'])) {
$data['email'] = $sreg['email'];
}
if ($ax) {
if (isset($ax->data['http://axschema.org/contact/email'])) {
$data['email'] = $ax->getSingle('http://axschema.org/contact/email');
}
if (isset($ax->data['http://axschema.org/namePerson/first'])) {
$first_name = $ax->getSingle('http://axschema.org/namePerson/first');
} else {
$first_name = "Sample";
}
if (isset($ax->data['http://axschema.org/namePerson/last'])) {
$last_name = $ax->getSingle('http://axschema.org/namePerson/last');
} else {
$last_name = "Avatar";
}
if ($first_name != null && $last_name != null) {
$data['username'] = "{$first_name} {$last_name}";
}
}
return true;
}
return false;
}
示例4: run
function run()
{
$consumer = getConsumer();
// Complete the authentication process using the server's
// response.
$return_to = getReturnTo();
$response = $consumer->complete($return_to);
// Check the response status.
if ($response->status == Auth_OpenID_CANCEL) {
// This means the authentication was cancelled.
$msg = '验证被取消。';
//showmessage('cancel_openid_auth');
} else {
if ($response->status == Auth_OpenID_FAILURE) {
// Authentication failed; display the error message.
$msg = "OpenID 认证失败: " . $response->message;
} else {
if ($response->status == Auth_OpenID_SUCCESS) {
// This means the authentication succeeded; extract the
// identity URL and Simple Registration data (if it was
// returned).
// 将openid记录到session里,在session超时时间内,由以后的逻辑绑定到已注册的uid上。
$_SESSION['openid_identifier'] = $response->getDisplayIdentifier();
$_SESSION['openid_binding'] = time();
//标记可以绑定了,但在发现是可直接登录用户时在要unset
if ($response->endpoint->canonicalID) {
$_SESSION['xri_canonicalid'] = $response->endpoint->canonicalID;
}
$sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
$_SESSION['openid_sreg'] = $sreg_resp->contents();
//NOTE:记录SREG到会话
// echo var_dump($_SESSION['openid_identifier'])."--_SESSION['openid_identifier']<br>";
// echo var_dump($_SESSION['openid_binding'])."--_SESSION['openid_binding']<br>";
_OpenID_Action();
//添加动作
}
}
}
displayError($msg);
}
示例5: fetchData
/**
*
* @return bool
* @param string $a_username
* @param string $a_password
* @param bool $isChallengeResponse[optional]
*/
public function fetchData($a_username, $a_password, $isChallengeResponse = false)
{
global $ilLog;
$ilLog->write(__METHOD__ . ': Fetch Data called');
$response = $this->settings->getConsumer()->complete($this->settings->getReturnLocation());
switch ($response->status) {
case Auth_OpenID_CANCEL:
die("Auth cancelled");
case Auth_OpenID_FAILURE:
die("Auth failed with message: " . $response->message);
case Auth_OpenID_SUCCESS:
$openid = $response->getDisplayIdentifier();
$esc_identity = htmlentities($openid);
$ilLog->write(__METHOD__ . ': Auth success with identity ' . $esc_identity);
if ($response->endpoint->canonicalID) {
$escaped_canonicalID = htmlentities($response->endpoint->canonicalID);
$ilLog->write(__METHOD__ . ': Auth success with canonical id: ' . $esc_identity);
}
include_once 'Auth/OpenID/SReg.php';
// Check if simple registration is supported
if (Auth_OpenID_supportsSReg($response->endpoint)) {
$sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response, true);
$this->response_data = $sreg_resp->contents();
$ilLog->write(__METHOD__ . ' auth data: ' . print_r($this->response_data, true));
return true;
} else {
// Try to fetch response values
foreach ($response->message->args->keys as $key => $mapping) {
if ($mapping[1] == 'sreg.nickname') {
$this->response_data['nickname'] = $response->message->args->values[$key];
}
if ($mapping[1] == 'sreg.email') {
$this->response_data['email'] = $response->message->args->values[$key];
}
}
}
return true;
}
return false;
}
示例6: escape
function escape($thing)
{
return htmlentities($thing);
}
$return_to = getReturnTo();
$response = $consumer->complete($return_to);
// Check the response status.
if ($response->status == Auth_OpenID_CANCEL) {
// This means the authentication was cancelled.
$msg = 'Verification cancelled.';
} else {
if ($response->status == Auth_OpenID_FAILURE) {
// Authentication failed; display the error message.
$msg = "OpenID authentication failed: " . $response->message;
} else {
if ($response->status == Auth_OpenID_SUCCESS) {
// This means the authentication succeeded; extract the
// identity URL and Simple Registration data (if it was
// returned).
$openid = $response->getDisplayIdentifier();
$esc_identity = escape($openid);
$msg = sprintf('You have successfully verified ' . '<a href="%s">%s</a> as your identity.', $esc_identity, $esc_identity);
$sreg = Auth_OpenID_SRegResponse::fromSuccessResponse($response)->contents();
$_SESSION['openid'] = $openid;
$_SESSION['username'] = @$sreg['username'];
$_SESSION['faction'] = @$sreg['faction'];
}
}
}
$_SESSION['msg'] = $msg;
header("Location: index.php");
示例7: htmlspecialchars
// identity URL and Simple Registration data (if it was
// returned).
$openid = $response->getDisplayIdentifier();
$esc_identity = htmlspecialchars($openid);
$people = $POD->getPeople(array('openid' => $esc_identity));
if (!$POD->isAuthenticated()) {
if ($people->count() == 1) {
// successful login
$POD->changeActor(array('id' => $people->getNext()->get('id')));
$days = 15;
setcookie('pp_auth', $POD->currentUser()->get('authSecret'), time() + 86400 * $days, "/");
header("Location: " . $POD->siteRoot(false));
exit;
} else {
if ($people->count() == 0) {
$sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
$sreg = $sreg_resp->contents();
$open_id_info['openid'] = $openid;
$open_id_info['email'] = @$sreg['email'];
$open_id_info['fullname'] = @$sreg['fullname'];
$open_id_info['nickname'] = @$sreg['nickname'];
$open_id_info['zip'] = @$sreg['postcode'];
}
}
} else {
if ($people->count() == 0) {
// a valid id was passed in by a user who was already authenticated, and there is nobody else with this id, so that means we
// were adding it to an account
$POD->currentUser()->addMeta('openid', $esc_identity);
$POD->addMessage('Your OpenID was added!');
} else {
示例8: get_user_data_sreg
/**
* Retrieve user data from OpenID Simple Registration.
*
* @see get_user_data
*/
function get_user_data_sreg($identity_url, &$data)
{
$sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($this->response);
$sreg = $sreg_resp->contents();
$this->core->log->debug(var_export($sreg, true));
if (!$sreg) {
return false;
}
if (array_key_exists('email', $sreg) && $sreg['email']) {
$data['user_email'] = $sreg['email'];
}
if (array_key_exists('nickname', $sreg) && $sreg['nickname']) {
$data['nickname'] = $sreg['nickname'];
$data['user_nicename'] = $sreg['nickname'];
$data['display_name'] = $sreg['nickname'];
}
if (array_key_exists('fullname', $sreg) && $sreg['fullname']) {
$namechunks = explode(' ', $sreg['fullname'], 2);
if (isset($namechunks[0])) {
$data['first_name'] = $namechunks[0];
}
if (isset($namechunks[1])) {
$data['last_name'] = $namechunks[1];
}
$data['display_name'] = $sreg['fullname'];
}
return true;
}
示例9: tryLogin
function tryLogin()
{
$consumer = oid_consumer();
$response = $consumer->complete(common_local_url('finishopenidlogin'));
if ($response->status == Auth_OpenID_CANCEL) {
// TRANS: Status message in case the response from the OpenID provider is that the logon attempt was cancelled.
$this->message(_m('OpenID authentication cancelled.'));
return;
} else {
if ($response->status == Auth_OpenID_FAILURE) {
// TRANS: OpenID authentication failed; display the error message. %s is the error message.
$this->message(sprintf(_m('OpenID authentication failed: %s'), $response->message));
} else {
if ($response->status == Auth_OpenID_SUCCESS) {
// This means the authentication succeeded; extract the
// identity URL and Simple Registration data (if it was
// returned).
$display = $response->getDisplayIdentifier();
$canonical = $response->endpoint->canonicalID ? $response->endpoint->canonicalID : $response->getDisplayIdentifier();
oid_assert_allowed($display);
oid_assert_allowed($canonical);
$sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
if ($sreg_resp) {
$sreg = $sreg_resp->contents();
}
// Launchpad teams extension
if (!oid_check_teams($response)) {
$this->message(_m('OpenID authentication aborted: you are not allowed to login to this site.'));
return;
}
$user = oid_get_user($canonical);
if ($user) {
oid_set_last($display);
# XXX: commented out at @edd's request until better
# control over how data flows from OpenID provider.
# oid_update_user($user, $sreg);
common_set_user($user);
common_real_login(true);
if (isset($_SESSION['openid_rememberme']) && $_SESSION['openid_rememberme']) {
common_rememberme($user);
}
unset($_SESSION['openid_rememberme']);
$this->goHome($user->nickname);
} else {
$this->saveValues($display, $canonical, $sreg);
$this->showForm(null, $this->bestNewNickname($display, $sreg));
}
}
}
}
}
示例10: finish_auth
/**
* Finish up authentication.
*
* @access public
* @return string
*/
public function finish_auth()
{
$msg = $error = $success = '';
$consumer = $this->_get_consumer();
// Complete the authentication process using the server's response.
$response = $consumer->complete($this->_get_self());
// Check the response status.
if ($response->status == Auth_OpenID_CANCEL) {
$data = $this->_throw_error(OPENID_RETURN_CANCEL);
} else {
if ($response->status == Auth_OpenID_FAILURE) {
$data = $this->_throw_error(OPENID_RETURN_FAILURE, $response->message);
} else {
if ($response->status == Auth_OpenID_SUCCESS) {
// if AX
$ax_resp = Auth_OpenID_AX_FetchResponse::fromSuccessResponse($response);
if ($response->endpoint->used_yadis && $ax_resp) {
$data = $ax_resp->data;
$new_data = array();
foreach ($data as $i => $item) {
if (array_key_exists($i, $this->ax_aliases)) {
$new_data[$this->ax_aliases[$i]] = $item;
} else {
$new_data[$i] = $item;
}
}
$data = $new_data;
} else {
$sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
$data = $sreg_resp->contents();
}
}
}
}
// if handling a popup request
if ($this->ci->session->userdata('_openid_popup')) {
$this->ci->session->unset_userdata('_openid_popup');
// store the data in a session
$this->ci->session->set_userdata('_openid_data', $data);
// close the popup
include OPENID_DIRECTORY . 'EasyOpenID_close.php';
die;
} else {
return $data;
}
}
示例11: tryLogin
/**
* Try to log in using OpenID
*
* Check the OpenID for validity; potentially store it.
*
* @return void
*/
function tryLogin()
{
$consumer = oid_consumer();
$response = $consumer->complete(common_local_url('finishaddopenid'));
if ($response->status == Auth_OpenID_CANCEL) {
// TRANS: Status message in case the response from the OpenID provider is that the logon attempt was cancelled.
$this->message(_m('OpenID authentication cancelled.'));
return;
} else {
if ($response->status == Auth_OpenID_FAILURE) {
// TRANS: OpenID authentication failed; display the error message.
// TRANS: %s is the error message.
$this->message(sprintf(_m('OpenID authentication failed: %s.'), $response->message));
} else {
if ($response->status == Auth_OpenID_SUCCESS) {
$display = $response->getDisplayIdentifier();
$canonical = $response->endpoint && $response->endpoint->canonicalID ? $response->endpoint->canonicalID : $display;
$sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
if ($sreg_resp) {
$sreg = $sreg_resp->contents();
}
// Launchpad teams extension
if (!oid_check_teams($response)) {
// TRANS: OpenID authentication error.
$this->message(_m('OpenID authentication aborted: You are not allowed to login to this site.'));
return;
}
$cur = common_current_user();
$other = oid_get_user($canonical);
if ($other) {
if ($other->id == $cur->id) {
// TRANS: Message in case a user tries to add an OpenID that is already connected to them.
$this->message(_m('You already have this OpenID!'));
} else {
// TRANS: Message in case a user tries to add an OpenID that is already used by another user.
$this->message(_m('Someone else already has this OpenID.'));
}
return;
}
// start a transaction
$cur->query('BEGIN');
$result = oid_link_user($cur->id, $canonical, $display);
if (!$result) {
// TRANS: Message in case the OpenID object cannot be connected to the user.
$this->message(_m('Error connecting user.'));
return;
}
if (Event::handle('StartOpenIDUpdateUser', array($cur, $canonical, &$sreg))) {
if ($sreg) {
if (!oid_update_user($cur, $sreg)) {
// TRANS: Message in case the user or the user profile cannot be saved in StatusNet.
$this->message(_m('Error updating profile.'));
return;
}
}
}
Event::handle('EndOpenIDUpdateUser', array($cur, $canonical, $sreg));
// success!
$cur->query('COMMIT');
oid_set_last($display);
common_redirect(common_local_url('openidsettings'), 303);
}
}
}
}
示例12: translate
/**
* Translates the response from the open id library to our internal tools, taking care of checking whether the user
* account needs to be created, etc...
*/
private function translate($response)
{
$openid = $response->getDisplayIdentifier();
$sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
$sreg = $sreg_resp->contents();
$val = Loader::helper('validation/strings');
$ui = UserInfo::getByOpenID($openid);
// There are a number of cases here.
// Case 1: There is NO user on the site here that matches this open ID.
if (!is_object($ui)) {
// Ok, no user. Now, did an email address come BACK with this request from the openid server?
if ($val->email($sreg['email'])) {
// if so, does it belong to an existing user on the site ?
$ui = UserInfo::getByEmail($sreg['email']);
if (is_object($ui)) {
$this->response->code = OpenIDAuth::E_REGISTRATION_EMAIL_EXISTS;
$this->response->user = $ui->getUserID();
$this->response->openid = $openid;
} else {
// best possible case, really: we are a new user with an email address that is not mapped to
// an existing account. We register the new account here, and pass back information to the calling page
// saying that we've done so
$ui = $this->registerUser($openid, $sreg['email']);
$this->response->code = OpenIDAuth::S_USER_CREATED;
$this->response->message = $ui->getUserID();
}
} else {
$this->response->code = OpenIDAuth::E_REGISTRATION_EMAIL_INCOMPLETE;
$this->response->message = $openid;
}
} else {
// Ok, there IS a user on the site who matches the open ID. That means we're all good
$this->response->code = OpenIDAuth::S_USER_AUTHENTICATED;
$this->response->message = $ui->getUserID();
$this->response->openid = $openid;
}
}
示例13: finish
/**
* Called when returning from the authentication server
* Find the user with the given openid, if any or displays the "Choose name"
* form
*/
function finish() {
global $wgOut, $wgUser, $wgOpenIDUseEmailAsNickname;
wfSuppressWarnings();
$consumer = $this->getConsumer();
$response = $consumer->complete( $this->scriptUrl( 'Finish' ) );
wfRestoreWarnings();
if ( is_null( $response ) ) {
wfDebug( "OpenID: aborting in auth because no response was recieved\n" );
$wgOut->showErrorPage( 'openiderror', 'openiderrortext' );
return;
}
switch ( $response->status ) {
case Auth_OpenID_CANCEL:
// This means the authentication was cancelled.
$wgOut->showErrorPage( 'openidcancel', 'openidcanceltext' );
break;
case Auth_OpenID_FAILURE:
wfDebug( "OpenID: error message '" . $response->message . "'\n" );
$wgOut->showErrorPage( 'openidfailure', 'openidfailuretext',
array( ( $response->message ) ? $response->message : '' ) );
break;
case Auth_OpenID_SUCCESS:
// This means the authentication succeeded.
wfSuppressWarnings();
$openid = $response->identity_url;
if ( !$this->canLogin( $openid ) ) {
$wgOut->showErrorPage( 'openidpermission', 'openidpermissiontext' );
return;
}
$sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse( $response );
$sreg = $sreg_resp->contents();
$ax_resp = Auth_OpenID_AX_FetchResponse::fromSuccessResponse( $response );
$ax = $ax_resp->data;
wfRestoreWarnings();
if ( is_null( $openid ) ) {
wfDebug( "OpenID: aborting in auth success because identity URL is missing\n" );
$wgOut->showErrorPage( 'openiderror', 'openiderrortext' );
return;
}
$user = self::getUserFromUrl( $openid );
if ( $user instanceof User ) {
$this->updateUser( $user, $sreg, $ax ); # update from server
$wgUser = $user;
$this->displaySuccessLogin( $openid );
} else {
// if we are hardcoding nickname, and a valid e-mail address was returned, create a user with this name
if ( $wgOpenIDUseEmailAsNickname ) {
$name = $this->getNameFromEmail( $openid, $sreg, $ax );
if ( !empty( $name ) && $this->userNameOk( $name ) ) {
$wgUser = $this->createUser( $openid, $sreg, $ax, $name );
$this->displaySuccessLogin( $openid );
return;
}
}
$this->saveValues( $openid, $sreg, $ax );
$this->chooseNameForm( $openid, $sreg, $ax );
return;
}
}
}
示例14: index
function index()
{
// Enable SSL?
maintain_ssl($this->config->item("ssl_enabled"));
// Retrieve sign in user
if ($this->authentication->is_signed_in()) {
$data['account'] = $this->Account_model->get_by_id($this->session->userdata('account_id'));
}
//$data['account_details'] = $this->account_details_model->get_by_account_id($this->session->userdata('account_id'));
// Get OpenID store object
$store = new Auth_OpenID_FileStore($this->config->item("openid_file_store_path"));
// Get OpenID consumer object
$consumer = new Auth_OpenID_Consumer($store);
if ($this->input->get('janrain_nonce')) {
// Complete authentication process using server response
$response = $consumer->complete(site_url('account/connect_openid'));
// Check the response status
if ($response->status == Auth_OpenID_SUCCESS) {
// Check if user has connect the openid to a3m
if ($user = $this->Account_openid_model->get_by_openid($response->getDisplayIdentifier())) {
// Check if user is not signed in on a3m
if (!$this->authentication->is_signed_in()) {
// Run sign in routine
$this->authentication->sign_in($user->account_id);
}
$user->account_id === $this->session->userdata('account_id') ? $this->session->set_flashdata('linked_error', sprintf(lang('linked_linked_with_this_account'), lang('connect_openid'))) : $this->session->set_flashdata('linked_error', sprintf(lang('linked_linked_with_another_account'), lang('connect_openid')));
redirect('account/account_linked');
} else {
// Check if user is signed in on a3m
if (!$this->authentication->is_signed_in()) {
$openid_all = array();
// Extract Simple Registration data
if ($sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response)) {
$sreg = $sreg_resp->contents();
if (isset($sreg['nickname'])) {
$username = $sreg['nickname'];
}
if (isset($sreg['email'])) {
$email = $sreg['email'];
}
if (isset($sreg['fullname'])) {
$openid_all['fullname'] = $sreg['fullname'];
}
if (isset($sreg['gender'])) {
$openid_all['gender'] = $sreg['gender'];
}
if (isset($sreg['dob'])) {
$openid_all['dateofbirth'] = $sreg['dob'];
}
if (isset($sreg['postcode'])) {
$openid_all['postalcode'] = $sreg['postcode'];
}
if (isset($sreg['country'])) {
$openid_all['country'] = $sreg['country'];
}
if (isset($sreg['language'])) {
$openid_all['language'] = $sreg['language'];
}
if (isset($sreg['timezone'])) {
$openid_all['timezone'] = $sreg['timezone'];
}
}
// Store user's twitter data in session
$this->session->set_userdata('connect_create', array(array('provider' => 'openid', 'provider_id' => $response->getDisplayIdentifier(), 'username' => isset($username) ? $username : NULL, 'email' => isset($email) ? $email : NULL), $openid_all));
// Create a3m account
redirect('account/connect_create');
} else {
// Connect openid to a3m
$this->Account_openid_model->insert($response->getDisplayIdentifier(), $this->session->userdata('account_id'));
$this->session->set_flashdata('linked_info', sprintf(lang('linked_linked_with_your_account'), lang('connect_openid')));
redirect('account/account_linked');
}
}
} else {
$this->authentication->is_signed_in() ? redirect('account/account_linked') : redirect('account/sign_up');
}
}
$this->load->library('form_validation');
// Setup form validation
$this->form_validation->set_error_delimiters('<span class="field_error">', '</span>');
$this->form_validation->set_rules(array(array('field' => 'connect_openid_url', 'label' => 'lang:connect_openid_url', 'rules' => 'trim|required')));
// Run form validation
if ($this->form_validation->run()) {
// Get OpenID store object
$store = new Auth_OpenID_FileStore($this->config->item("openid_file_store_path"));
// Get OpenID consumer object
$consumer = new Auth_OpenID_Consumer($store);
// Begin OpenID authentication process
if (!($auth_request = $consumer->begin($this->input->post('connect_openid_url')))) {
$data['connect_openid_error'] = sprintf(lang('connect_invalid_openid'), lang('connect_openid'));
} else {
// Create sreg_request (Simple Registration)
if ($sreg_request = Auth_OpenID_SRegRequest::build(array('nickname', 'email', 'fullname', 'gender', 'dob', 'postcode', 'country', 'language', 'timezone'))) {
$auth_request->addExtension($sreg_request);
}
// Redirect to authorizate URL
header("Location: " . $auth_request->redirectURL(base_url(), site_url('account/connect_openid')));
}
}
$this->load->view('account/connect_openid', isset($data) ? $data : NULL);
//.........这里部分代码省略.........
示例15: run
function run()
{
$session =& CRM_Core_Session::singleton();
$config =& CRM_Core_Config::singleton();
$consumer = getConsumer();
// Complete the authentication process using the server's
// response.
$return_to = getReturnTo();
$response = $consumer->complete($return_to);
// Check the response status.
if ($response->status == Auth_OpenID_CANCEL) {
// This means the authentication was cancelled.
$msg = 'Verification cancelled.';
$session->set('msg', $msg);
$session->set('goahead', "no");
} else {
if ($response->status == Auth_OpenID_FAILURE) {
// Authentication failed; display the error message.
$msg = "OpenID authentication failed: " . $response->message;
$session->set('msg', $msg);
$session->set('goahead', "no");
} else {
if ($response->status == Auth_OpenID_SUCCESS) {
// This means the authentication succeeded; extract the
// identity URL and Simple Registration data (if it was
// returned).
$openid = array();
$openid['display_id'] = $response->getDisplayIdentifier();
$openid['claimed_id'] = $response->identity_url;
$openid['endpoint_url'] = $response->endpoint->server_url;
#$openid = $response->getDisplayIdentifier();
//$esc_identity = escape($openid);
$session->set('openid', $openid);
$session->set('goahead', "yes");
$sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
$sreg = $sreg_resp->contents();
$sreg['email'] = empty($sreg['email']) ? '' : $sreg['email'];
if ($session->get('new_install') == true) {
// update group clause
require_once 'CRM/Core/Transaction.php';
require_once 'CRM/Contact/BAO/Group.php';
$groupDAO =& new CRM_Contact_DAO_Group();
$groupDAO->find();
while ($groupDAO->fetch()) {
if (!isset($transaction)) {
$transaction = new CRM_Core_Transaction();
}
$group =& new CRM_Contact_BAO_Group();
$group->id = $groupDAO->id;
$group->find(true);
$group->buildClause();
$group->save();
}
if (isset($transaction)) {
$transaction->commit();
}
// Redirect to new user registration form
$urlVar = $config->userFrameworkURLVar;
$config->reset();
header("Location: index.php?{$urlVar}=civicrm/standalone/register&reset=1&configReset=1");
exit;
} else {
require_once 'CRM/Standalone/User.php';
$user = new CRM_Standalone_User($openid, $sreg['email']);
require_once 'CRM/Utils/System/Standalone.php';
$allow_login = CRM_Utils_System_Standalone::getAllowedToLogin($user);
if (!$allow_login && (!defined('CIVICRM_ALLOW_ALL') || !CIVICRM_ALLOW_ALL)) {
$session->set('msg', 'You are not allowed to login. Login failed. Contact your Administrator.');
$session->set('goahead', "no");
} else {
CRM_Utils_System_Standalone::getUserID($user);
if (!$session->get('userID')) {
$session->set('msg', 'You are not authorized to login.');
$session->set('goahead', "no");
}
}
header("Location: index.php");
exit(0);
}
}
}
}
displayError("Unknown status returned.");
}