Example #1
0
 /**
  * Registro de usuario a traves de Oauth (libreria HybridOauth, openid, facebook, twitter, etc).
  */
 public function oauth()
 {
     require_once OAUTH_LIBS;
     $errors = array();
     if (isset($_GET["provider"]) && $_GET["provider"]) {
         $oauth = new \SocialAuth($_GET["provider"]);
         if (!$oauth->authenticate()) {
             //si falla: error, si no siempre se redirige al proveedor
             Message::Error(Text::get($oauth->last_error));
         }
     }
     //return from provider authentication
     if (isset($_GET["return"]) && $_GET["return"]) {
         //check twitter activation
         $oauth = new \SocialAuth($_GET["return"]);
         if ($oauth->login()) {
             //si ok: redireccion de login!
             //Message::Info("USER INFO:\n".print_r($oauth->user_data,1));
             //si es posible, login en goteo (redirecciona a user/dashboard o a user/confirm)
             //y fuerza que pueda logear en caso de que no esté activo
             if (!$oauth->goteoLogin()) {
                 //si falla: error o formulario de confirmación
                 if ($oauth->last_error == 'oauth-goteo-user-not-exists') {
                     return new View('view/user/confirm.html.php', array('oauth' => $oauth));
                 } elseif ($oauth->last_error == 'oauth-goteo-user-password-exists') {
                     Message::Error(Text::get($oauth->last_error));
                     return new View('view/user/confirm_account.html.php', array('oauth' => $oauth, 'user' => Model\User::get($oauth->user_data['username'])));
                 } else {
                     Message::Error(Text::get($oauth->last_error));
                 }
             }
         } else {
             //si falla: error
             Message::Error(Text::get($oauth->last_error));
         }
     }
     return new View('view/user/login.html.php', array('errors' => $errors));
 }