Пример #1
0
 public static function getObject()
 {
     $class = get_called_class();
     $class = substr($class, strrpos($class, '\\') + 1);
     $object = Social::get($class, 'object_name');
     return $object;
 }
Пример #2
0
 public function action_login()
 {
     //if user loged in redirect home
     if (Auth::instance()->logged_in()) {
         Auth::instance()->login_redirect();
     }
     Social::include_vendor();
     $user = FALSE;
     $config = Social::get();
     if ($this->request->query('hauth_start') or $this->request->query('hauth_done')) {
         try {
             Hybrid_Endpoint::process($this->request->query());
         } catch (Exception $e) {
             Alert::set(Alert::ERROR, $e->getMessage());
             $this->redirect(Route::url('default'));
         }
     } else {
         $provider_name = $this->request->param('id');
         try {
             // initialize Hybrid_Auth with a given file
             $hybridauth = new Hybrid_Auth($config);
             // try to authenticate with the selected provider
             if ($provider_name == 'openid') {
                 $params = array('openid_identifier' => 'https://openid.stackexchange.com/');
             } else {
                 $params = NULL;
             }
             $adapter = $hybridauth->authenticate($provider_name, $params);
             if ($hybridauth->isConnectedWith($provider_name)) {
                 //var_dump($adapter->getUserProfile());
                 $user_profile = $adapter->getUserProfile();
             }
         } catch (Exception $e) {
             Alert::set(Alert::ERROR, __('Error: please try again!') . " " . $e->getMessage());
             $this->redirect(Route::url('default'));
         }
         //try to login the user with same provider and identifier
         $user = Auth::instance()->social_login($provider_name, $user_profile->identifier);
         //we couldnt login create account
         if ($user == FALSE) {
             $email = $user_profile->emailVerified != NULL ? $user_profile->emailVerified : $user_profile->email;
             $name = $user_profile->firstName != NULL ? $user_profile->firstName . ' ' . $user_profile->lastName : $user_profile->displayName;
             //if not email provided
             if (!Valid::email($email, TRUE)) {
                 Alert::set(Alert::INFO, __('We need your email address to complete'));
                 //redirect him to select the email to register
                 $this->redirect(Route::url('default', array('controller' => 'social', 'action' => 'register', 'id' => $provider_name)) . '?uid=' . $user_profile->identifier . '&name=' . $name);
             } else {
                 //register the user in DB
                 Model_User::create_social($email, $name, $provider_name, $user_profile->identifier);
                 //log him in
                 Auth::instance()->social_login($provider_name, $user_profile->identifier);
             }
         } else {
             Alert::set(Alert::SUCCESS, __('Welcome!'));
         }
         $this->redirect(Session::instance()->get_once('auth_redirect', Route::url('default')));
     }
 }
Пример #3
0
 public function action_index()
 {
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Social Authentication for login')));
     $this->template->title = __('Social Auth');
     $this->template->styles = array('css/sortable.css' => 'screen');
     $this->template->scripts['footer'][] = 'js/jquery-sortable-min.js';
     //retrieve social_auth values
     $config = Social::get();
     if ($p = $this->request->post()) {
         $confit_old = $config;
         $config_new = array();
         foreach ($p as $key => $value) {
             if ($key != 'submit') {
                 // check if its id, secret .. and build multy d. array, same as they have
                 if (strpos($key, '_id')) {
                     $config_new['providers'][str_replace('_id', '', $key)]['keys']['id'] = $value;
                 } elseif (strpos($key, '_secret')) {
                     $config_new['providers'][str_replace('_secret', '', $key)]['keys']['secret'] = $value;
                 } elseif (strpos($key, '_key')) {
                     $config_new['providers'][str_replace('_key', '', $key)]['keys']['key'] = $value;
                 } elseif ($key == 'debug_mode') {
                     $config_new[$key] = $value;
                 } else {
                     $config_new['providers'][$key]['enabled'] = $value;
                 }
             }
         }
         // two fields not included
         $config_new['base_url'] = Route::url('default', array('controller' => 'social', 'action' => 'login', 'id' => 1));
         $config_new['debug_file'] = DOCROOT . 'oc/vendor/hybridauth/logs.txt';
         $obj_social_config = new Model_Config();
         $conf = $obj_social_config->where('group_name', '=', 'social')->where('config_key', '=', 'config')->limit(1)->find();
         if ($conf->loaded()) {
             $conf->config_value = json_encode($config_new);
             try {
                 $conf->save();
                 $config = $config_new;
                 //we update the form values if we changed them
                 Alert::set(Alert::SUCCESS, __('Social Auth updated'));
             } catch (Exception $e) {
                 throw HTTP_Exception::factory(500, $e->getMessage());
             }
         }
     }
     $this->template->content = View::factory('oc-panel/pages/social_auth/index', array('config' => $config));
 }