1. function register()
  2. {
  3. $this->set('username_error', 'Username must be between 6 and 40 characters.');
  4. if (!empty($this->data))
  5. {
  6. if ($this->User->validates($this->data))
  7. {
  8. if ($this->User->findByUsername($this->data['User']['username']))
  9. {
  10. $this->User->invalidate('username');
  11. $this->set('username_error', 'User already exists.');
  12. } else {
  13. $this->data['User']['password'] = md5($this->data['User']['password']);
  14. if ($this->User->save($this->data))
  15. {
  16. $aro = new Aro();
  17. $aro->create($this->User->id, 'User', $this->data['User']['username']);
  18. $this->Session->write('user', $this->data['User']['username']);
  19. $this->redirect('/users/cp');
  20. } else {
  21. $this->flash('There was a problem saving this information', '/users/register');
  22. }
  23. }
  24. } else {
  25. $this->validateErrors($this->User);
  26. }
  27. }
  28. }