Guest User

Untitled

a guest
Jul 18th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. <?php defined('SYSPATH') or die('No direct script access.');
  2.  
  3. class User_Controller extends Application_Controller {
  4.  
  5. public function register() {
  6.  
  7. if ($_POST)
  8. {
  9. $post = new Validation($_POST);
  10. $user_model = ORM::factory('user');
  11.  
  12. $post->pre_filter('trim','email')
  13. ->add_rules('email', 'valid::email', array($user_model, 'email_available'));
  14. $post->add_rules('password', 'length[6,20]', 'matches[confirm_password]');
  15. $post->add_rules('*', 'required');
  16.  
  17. if($post->validate())
  18. {
  19. $user_model->username = $post->email;
  20. $user_model->email = $post->email;
  21. $user_model->password = $post->password;
  22.  
  23. if ($user_model->add(ORM::factory('role', 'login')) && $user_model->save())
  24. {
  25. // login using the collected data
  26. Auth::instance()->login($user_model->username, $user_model->password);
  27. url::redirect('index/index');
  28. }
  29. }
  30. else
  31. {
  32. $this->session->set('error_messages', 'This user already exists in the system.');
  33. url::redirect('user/register');
  34. }
  35. }
  36.  
  37. echo $this->session->get('error_messages');
  38.  
  39. $this->template->subtitle = 'New User';
  40. $this->template->content = new View('user/register_view');
  41. }
  42. }
Add Comment
Please, Sign In to add comment