public $helpers = array('Html', 'Form');
public $components = array('RequestHandler');
+ public function beforeFilter() {
+ parent::beforeFilter();
+ $this->Auth->allow('register', 'logout');
+ }
+
public function index() {
$administrators = $this->Administrator->find('all');
$this->set(array(
public function login() {
if ($this->request->is('POST')) {
- $administrators = $this->Administrator->find('all');
+ if($this->Auth->login()) {
+ return $this->redirect($this->Auth->redirectUrl());
+ }
+ /*$administrators = $this->Administrator->find('all');
$success = false;
$login = $_POST['login'];
$pass = md5($_POST['pass']);
$success = true;
break;
}
- }
- if ($success) {
- $this->Session->setFlash(__("Login OK."));
- $this->redirect(array(/*'controller' => 'instances', */'action' => 'index'));
+ }*/
+ //if ($success) {
+ // $this->Session->setFlash(__("Login OK."));
+ // $this->redirect(array(/*'controller' => 'instances', */'action' => 'index'));
- } else {
- $this->Session->setFlash(__("Login FAIL."));
- $this->redirect(array('action' => 'login'));
- }
+ //} else {
+ // $this->Session->setFlash(__("Login FAIL."));
+ // $this->redirect(array('action' => 'login'));
+ //}
}
}
public function register() {
if ($this->request->is('POST')) {
- $login = $_POST['login'];
+ $username = $_POST['username'];
+ $password = $_POST['password'];
// CHECKING IF LOGIN IS ALREADY TAKEN
$administrators = $this->Administrator->find('all');
- $isLoginAvailable = true;
+ $isUsernameAvailable = true;
foreach($administrators as $administrator) {
- if($administrator['Administrator']['login'] === $login) {
- $isLoginAvailable = false;
+ if($administrator['Administrator']['username'] === $username) {
+ $isUsernameAvailable = false;
break;
}
}
- if($isLoginAvailable) {
- $pass = md5($_POST['pass']);
+ if($isUsernameAvailable) {
+ //$pass = md5($pass);
$this->Administrator->create();
- $this->Administrator->value('login', $login);
- $this->Administrator->value('pass', $pass);
+ $this->Administrator->value('username', $username);
+ $this->Administrator->value('password', $password);
$this->Administrator->save();
if (isset($this->Administrator)) {
$this->Session->setFlash(__("Register OK."));
}
$this->Session->setFlash(__("Register FAIL."));
} else {
- $this->Session->setFlash(__("Ce pseudo est déjà utilisé."));
+ $this->Session->setFlash(__("Ce nom est déjà utilisé."));
}
}
}
+
+ public function logout() {
+ $this->redirect($this->Auth->logout());
+ }
}