Example #1
0
 public function login()
 {
     $auth = Auth::instance();
     $request = Request::current();
     // If user already signed-in / don't show the widget on user controller.
     if ($auth->logged_in() or $request->controller() === 'user') {
         return;
     }
     Assets::css('user', 'media/css/user.css', array('weight' => 2));
     // Create form action
     $destination = isset($_GET['destination']) ? $_GET['destination'] : Request::initial()->uri();
     $params = array('action' => 'login');
     $action = Route::get('user')->uri($params) . URL::query(array('destination' => $destination));
     return View::factory('widget/login')->set('register', Config::get('auth.register'))->set('use_username', Config::get('auth.username'))->set('providers', array_filter(Auth::providers()))->set('action', $action)->set('post', ORM::factory('user'))->render();
 }
Example #2
0
 /**
  * The before() method is called before controller action.
  *
  * @throws Http_Exception_404 If the provider is disabled
  *
  * @uses  Auth::logged_in
  * @uses  Route::get
  * @uses  Route::uri
  * @uses  Config::load
  * @uses  Session::get
  */
 public function before()
 {
     parent::before();
     // Disable sidebars on user pages
     $this->_sidebars = FALSE;
     // Load the session
     $this->session = Session::instance();
     // Set the provider controller
     $this->provider = strtolower($this->request->param('provider'));
     $providers = Auth::providers();
     // Throw exception if the provider is disabled
     if (!array_key_exists($this->provider, array_filter($providers))) {
         throw new Http_Exception_404('Unsupported provider', NULL);
     }
     $this->route = $this->request->route();
     // Load the client config
     $this->provider_config = Config::load("oauth2.providers.{$this->provider}");
     $this->client = OAuth2_Client::factory($this->provider, $this->provider_config['id'], $this->provider_config['secret']);
     if ($token = $this->session->get($this->key('access'))) {
         // Make the access token available
         $this->token = $token;
     }
 }
Example #3
0
 /**
  * Themed list of providers to print
  *  
  * @todo move to HTML class
  * @return string html to display
  */
 public static function providers()
 {
     if (!Auth::instance()->logged_in()) {
         $providers = array_filter(Auth::providers());
         return View::factory('oauth/providers')->set('providers', $providers);
     }
 }
Example #4
0
</div>

<div class="col-sm-6">
	<div class="panel panel-default window-shadow">
		<div class="panel-heading">
			<h3 class="panel-title">
				<?php 
_e('Already have an account? Choose how you would like to sign in');
?>
			</h3>
		</div>
		<div class="panel-body">
			<div class="form-group oauth-buttons">
				<?php 
_e('You can sign in from any of the following services:');
$providers = Auth::providers();
echo HTML::anchor(Route::get('user')->uri(array('action' => 'login')), '<i class="fa fa-home"></i> ' . $site_name, array('class' => 'btn btn-default', 'title' => __('Login with :provider', array(':provider' => $site_name)), 'rel' => 'tooltip', 'data-placement' => 'right'));
foreach ($providers as $name => $provider) {
    echo HTML::anchor($provider['url'], '<i class="fa fa-' . $provider['icon'] . '"></i>' . ucfirst($name), array('class' => 'btn btn-default', 'title' => __('Login with :provider', array(':provider' => $name)), 'rel' => 'tooltip', 'data-placement' => 'right'));
}
?>
			</div>
			<p class="help-signin">
				<?php 
_e("If you don't use any of these services, you can create an account.");
?>
				<?php 
_e('Fast, safe & secure way!');
?>
			</p>
		</div>
Example #5
0
 /**
  * Sign In
  *
  * @uses  Request::redirect
  * @uses  Request::post
  * @uses  Route::get
  * @uses  Message::success
  * @uses  Log::add
  */
 public function action_login()
 {
     // If user already signed-in
     if ($this->_auth->logged_in()) {
         // redirect to the user account
         $this->request->redirect(Route::get('user')->uri(array('action' => 'profile')), 200);
     }
     $this->title = __('Sign In');
     $user = ORM::factory('user');
     // Disable sidebars on login page
     $this->_sidebars = FALSE;
     // Create form action
     $destination = isset($_GET['destination']) ? $_GET['destination'] : Request::initial()->uri();
     $params = array('action' => 'login');
     $action = Route::get('user')->uri($params) . URL::query(array('destination' => $destination));
     $view = View::factory('user/login')->set('register', Config::get('auth.register'))->set('use_username', Config::get('auth.username'))->set('providers', array_filter(Auth::providers()))->set('post', $user)->set('action', $action)->bind('errors', $this->_errors);
     if ($this->valid_post('login')) {
         try {
             // Check Auth
             $user->login($this->request->post());
             // If the post data validates using the rules setup in the user model
             Message::success(__('Welcome, %title!', array('%title' => $user->nick)));
             Log::info('User :name logged in.', array(':name' => $user->name));
             // redirect to the user account
             $this->request->redirect(isset($_GET['destination']) ? $_GET['destination'] : '', 200);
         } catch (Validation_Exception $e) {
             $this->_errors = $e->array->errors('login', TRUE);
         }
     }
     $this->response->body($view);
 }