array('className' => 'Alerta')); function login() { $this->set('error', false); if (!empty($this->data)) { $someone = $this->User->findByUsername($this->data['User']['username']); if(!empty($someone['User']['password']) && $someone['User']['password'] == md5($this->data['User']['password'])) { $this->Session->write('User', $someone['User']); $this->Session->write('UserId', $someone['User']['id']); $this->redirect('/users/profile'); } else { $this->set('error', true); } } } function add() { if (!empty($this->data)) { $this->data['User']['password'] = md5($this->data['User']['password']); if ($this->User->save($this->data)) { $this->redirect('/users/login'); } } } function profile($id = null) { $this->checkSession(); $id = $this->Session->read('UserId'); $this->set('user', $this->User->read(null, $id)); } function edit($id = null) { $id = $this->Session->read('UserId'); if (empty($this->data)) { $this->User->id = $id; $this->data = $this->User->read(); } else { $this->data['User']['password'] = md5($this->data['User']['password']); if ($this->User->save($this->data['User'])) { $this->redirect('/users/profile'); } } } function delete() { $this->checkSession(); $id = $this->Session->read('UserId'); $this->User->del($id); $this->Session->delete('User'); $this->Session->delete('UserId'); $this->redirect('/'); } function logout() { $this->checkSession(); $this->Session->delete('User'); $this->Session->delete('UserId'); $this->redirect('/'); } } ?>