fuelphp authentication 1

fuelphp authentication

'always_load' => array(
    'packages' => array(
        'auth',
    ),
),

Here is what the above code is Doing:
1. It’s telling FuelPHP to load the Auth package by default.
2. It’s telling FuelPHP to load the Auth package before the application loads.
3. It’s telling FuelPHP to load the Auth package before the application loads, even if the application doesn’t use it.

Now, let’s create a controller that will handle the login process.

Create a new file in fuel/app/classes/controller/auth.php and add the following code:

add(’email’, ‘Email or Username’)
->add_rule(‘required’);
$val->add(‘password’, ‘Password’)
->add_rule(‘required’);

if ($val->run())
{
$auth = Auth::instance();

// check the credentials. This assumes that you have the previous table created
if (Auth::check() or $auth->login(Input::post(’email’), Input::post(‘password’)))
{
// credentials ok, go right in
if (Config::get(‘auth.driver’, ‘Simpleauth’) == ‘Ormauth’)
{
$current_user = Model\Auth_User::find_by_username(Auth::get_screen_name());
}
else
{
$current_user = Model_User::find_by_username(Auth::get_screen_name());
}
Session::set_flash(‘success’, e(‘Welcome, ‘.$current_user->username));
Response::redirect(‘/’);
}
else
{
$this->template->set_global(‘login_error’, ‘Fail’);
}
}
}

$this->template->title = ‘Login’;
$this->template->content = View::forge(‘auth/login’, array(‘val’ => $val), false);
}

/**
* The logout action.
*
* @access public
* @return void
*/
public function action_logout()
{
Auth::logout();
Response::redirect(‘/’);
}
}

Similar Posts