当前位置: 首页>>代码示例>>PHP>>正文


PHP Provider::factory方法代码示例

本文整理汇总了PHP中Provider::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Provider::factory方法的具体用法?PHP Provider::factory怎么用?PHP Provider::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Provider的用法示例。


在下文中一共展示了Provider::factory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: action_provider_return

 /**
  * Allow the user to login and register using a 3rd party provider.
  */
 function action_provider_return()
 {
     $provider_name = $this->request->param('provider');
     $provider = Provider::factory($provider_name);
     if (!is_object($provider)) {
         Message::add('error', 'Provider is not enabled; please select another provider or log in normally.');
         $this->redirect('user/login');
         return;
     }
     // verify the request
     if ($provider->verify()) {
         // check for previously connected user
         $uid = $provider->user_id();
         $user_identity = ORM::factory('User_Identity')->where('provider', '=', $provider_name)->and_where('identity', '=', $uid)->find();
         if ($user_identity->loaded()) {
             $user = $user_identity->user;
             if ($user->loaded() && $user->id == $user_identity->user_id && is_numeric($user->id)) {
                 // found, log user in
                 Auth::instance()->force_login($user);
                 // redirect to the user account
                 $this->redirect('user/profile');
                 return;
             }
         }
         // create new account
         if (!Auth::instance()->logged_in()) {
             // Instantiate a new user
             $user = ORM::factory('User');
             // fill in values
             // generate long random password (maximum that passes validation is 42 characters)
             $password = $user->generate_password(42);
             $values = array('username' => $user->generate_username(str_replace(' ', '.', $provider->name())), 'password' => $password, 'password_confirm' => $password);
             if (Valid::email($provider->email(), TRUE)) {
                 $values['email'] = $provider->email();
             }
             try {
                 // If the post data validates using the rules setup in the user model
                 $user->create_user($values, array('username', 'password', 'email'));
                 // Add the login role to the user (add a row to the db)
                 $login_role = new Model_Role(array('name' => 'login'));
                 $user->add('roles', $login_role);
                 // create user identity after we have the user id
                 $user_identity = ORM::factory('User_Identity');
                 $user_identity->user_id = $user->id;
                 $user_identity->provider = $provider_name;
                 $user_identity->identity = $provider->user_id();
                 $user_identity->save();
                 // sign the user in
                 Auth::instance()->login($values['username'], $password);
                 // redirect to the user account
                 $this->redirect('user/profile');
             } catch (ORM_Validation_Exception $e) {
                 if ($provider_name == 'twitter') {
                     Message::add('error', 'The Twitter API does not support retrieving your email address; you will have to enter it manually.');
                 } else {
                     Message::add('error', 'We have successfully retrieved some of the data from your other account, but we were unable to get all the required fields. Please complete form below to register an account.');
                 }
                 // in case the data for some reason fails, the user will still see something sensible:
                 // the normal registration form.
                 $view = View::factory('user/register');
                 $errors = $e->errors('register');
                 // Move external errors to main array, for post helper compatibility
                 $errors = array_merge($errors, isset($errors['_external']) ? $errors['_external'] : array());
                 $view->set('errors', $errors);
                 // Pass on the old form values
                 $values['password'] = $values['password_confirm'] = '';
                 $view->set('defaults', $values);
                 if (Kohana::$config->load('useradmin')->captcha) {
                     // FIXME: Is this the best place to include and use recaptcha?
                     include Kohana::find_file('vendor', 'recaptcha/recaptchalib');
                     $recaptcha_config = Kohana::$config->load('recaptcha');
                     $recaptcha_error = null;
                     $view->set('captcha_enabled', true);
                     $view->set('recaptcha_html', recaptcha_get_html($recaptcha_config['publickey'], $recaptcha_error));
                 }
                 $this->template->content = $view;
             }
         } else {
             Message::add('error', 'You are logged in, but the email received from the provider does not match the email associated with your account.');
             $this->redirect('user/profile');
         }
     } else {
         Message::add('error', 'Retrieving information from the provider failed. Please register below.');
         $this->redirect('user/register');
     }
 }
开发者ID:Aranjedeath,项目名称:EnsofobiWebdd,代码行数:89,代码来源:User.php

示例2: action_provider_return

 /**
  * Allow the user to login and register using a 3rd party provider.
  */
 function action_provider_return()
 {
     $provider_name = $this->request->param('provider');
     $provider = Provider::factory($provider_name);
     if (!is_object($provider)) {
         Message::add('error', __('provider.not.enabled.select.different.or.login'));
         $this->request->redirect('user/login');
         return;
     }
     // verify the request
     if ($provider->verify()) {
         // check for previously connected user
         $uid = $provider->user_id();
         $user_identity = ORM::factory('user_identity')->where('provider', '=', $provider_name)->and_where('identity', '=', $uid)->find();
         if ($user_identity->loaded()) {
             $user = $user_identity->user;
             if ($user->loaded() && $user->id == $user_identity->user_id && is_numeric($user->id)) {
                 // found, log user in
                 Auth::instance()->force_login($user);
                 // redirect to the user account
                 $this->request->redirect(Session::instance()->get_once('returnUrl', 'user/profile'));
                 return;
             }
         }
         // If register is disabled, don't create new account
         if (!Kohana::$config->load('useradmin.register_enabled')) {
             $this->request->redirect('user/login');
         }
         // create new account
         if (!Auth::instance()->logged_in()) {
             /** @var $user Useradmin_Model_User */
             $user = ORM::factory('user');
             // fill in values
             // generate long random password (maximum that passes validation is 42 characters)
             $password = $user->generate_password(42);
             $values = array('username' => $user->generate_username(str_replace(' ', '.', $provider->name())), 'password' => $password, 'password_confirm' => $password);
             if (Valid::email($provider->email(), TRUE)) {
                 $values['email'] = $provider->email();
             }
             try {
                 // If the post data validates using the rules setup in the user model
                 $user->create_user($values, $this->user_model_fields);
                 // Add the login role to the user (add a row to the db)
                 $login_role = new Model_Role(array('name' => 'login'));
                 $user->add('roles', $login_role);
                 // create user identity after we have the user id
                 $user_identity = ORM::factory('user_identity');
                 $user_identity->user_id = $user->id;
                 $user_identity->provider = $provider_name;
                 $user_identity->identity = $provider->user_id();
                 $user_identity->save();
                 // sign the user in
                 Auth::instance()->login($values['username'], $password);
                 // redirect to the user account
                 $this->request->redirect(Session::instance()->get_once('returnUrl', 'user/profile'));
             } catch (ORM_Validation_Exception $e) {
                 /*
                  * Redirect back to the front page in case they
                  * try to create another account with a separate provider
                  */
                 Message::add('error', 'A matching account already exists with another provider. Please select another login or registration method.');
                 $this->request->redirect('user/login');
                 if ($provider_name == 'twitter') {
                     Message::add('error', __('twitter.no.email.retrive.support'));
                 } else {
                     Message::add('error', 'please.complete.data.from.other.account');
                 }
                 // in case the data for some reason fails, the user will still see something sensible:
                 // the normal registration form.
                 $view = View::factory('user/register');
                 $errors = $e->errors('register');
                 // Move external errors to main array, for post helper compatibility
                 $errors = array_merge($errors, isset($errors['_external']) ? $errors['_external'] : array());
                 $view->set('errors', $errors);
                 // Pass on the old form values
                 $values['password'] = $values['password_confirm'] = '';
                 $view->set('defaults', $values);
                 if (Kohana::$config->load('useradmin')->captcha) {
                     // FIXME: Is this the best place to include and use recaptcha?
                     include Kohana::find_file('vendor', 'recaptcha/recaptchalib');
                     $recaptcha_config = Kohana::$config->load('recaptcha');
                     $recaptcha_error = null;
                     $view->set('captcha_enabled', true);
                     $view->set('recaptcha_html', recaptcha_get_html($recaptcha_config['publickey'], $recaptcha_error));
                 }
                 $this->template->content = $view;
             }
         } else {
             Message::add('error', __('logged.in.but.account.emails.do.not.match'));
             $this->request->redirect('user/profile');
         }
     } else {
         Message::add('error', __('retrieving.info.from.provider.failed.register.below'));
         $this->request->redirect('user/register');
     }
 }
开发者ID:rafsoaken,项目名称:useradmin,代码行数:99,代码来源:user.php


注:本文中的Provider::factory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。