That's pretty easy with akelos.
This is how I did it. (I'am new to Akelos-Framework but I think this way to implement authentication is ok? But anyway I know pretty less about Akelos-Framework It's fun to work with it :-) )
**prerequisites:**
a user-model with at least the following fields (name, password and e_mail). If you don't have one [[create a user-model]]
OK, You know all your controllers extends the ApplicationController (app/application_controller.php)?
place the following function into it
redirectTo(array('controller' => 'home', 'action' => 'login'));
}
} else
$this->redirectTo(array('controller' => 'home', 'action' => 'login'));
}
}
?>
generate a home controller
''script/generate controller Home''
write the following methods
beforeFilter('authentication', array('forbiddenAction'=>array('except'=>array('login', 'index', 'logout'))));
}
public function index()
{
}
public function login()
{
if(!empty($this->params['login'])){
$user = $this->User->find('first', array('conditions' => array('e_mail =?', $this->params['login']['e_mail'])));
if ($user->password == $this->params['login']['password'])
{
$_SESSION['uid'] = $user->id;
$_SESSION['name'] = $user->name;
$_SESSION['time'] = time();
}
}
}
public function logout()
{
$_SESSION['uid'] = '';
$_SESSION['name'] = '';
$_SESSION['time'] = '';
$this -> redirectTo(array('action' => 'index'));
}
}
?>
now you can write a login/logout link into your template I use the layout (my layout called app/views/layouts/forum.tpl)
{?session-name}
link_to($text_helper->translate('Logout'), array('controller' => 'home', 'action' => 'logout'))?> {session-name}
{else}
link_to($text_helper->translate('Login'), array('controller' => 'home', 'action' => 'login'))?>
{end}
now you're ready :-)
don't forget place in every controller your
public function __construct()
{
$this->beforeFilter('authentication', array('forbiddenAction'=>array('except'=>array('index', 'listing', 'show'))));
}
OK, hope this help a bit for the first steps ;-)
badPussycat