Guest User

Untitled

a guest
May 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. <?php defined('SYSPATH') OR die('No direct access allowed.');
  2.  
  3. class Register_Controller extends Authenticate_Controller {
  4.  
  5. public $template = 'shared/template';
  6. public $auto_render = TRUE;
  7.  
  8. public function __construct()
  9. {
  10. parent::__construct();
  11.  
  12. $this->template->title = 'Register';
  13. if (!$this->authentic->logged_in('admin'))
  14. {
  15. url::redirect('dashboard');
  16. }
  17. }
  18.  
  19. public function index()
  20. {
  21. $this->template->title .= template::append_title('Register User');
  22. $this->template->content = new View('account/register/index');
  23.  
  24. if($this->input->post())
  25. {
  26. $this->perform_register();
  27. }
  28. }
  29.  
  30. private function perform_register()
  31. {
  32. $user = ORM::factory('user');
  33. $photo = $this->handle_photo();
  34. $user->username = $this->input->post('username');
  35. $user->password = $this->input->post('password');
  36. $user->email = $this->input->post('email');
  37. $user->title = $this->input->post('title');
  38. $user->first_name = $this->input->post('first_name');
  39. $user->last_name = $this->input->post('last_name');
  40. $user->twitter = $this->input->post('twitter');
  41. $user->phone = $this->input->post('phone');
  42. $user->email = $this->input->post('email');
  43.  
  44. if ($user->add(ORM::factory('role', 'login')) AND $user->add(ORM::factory('user_photo' , $photo)) AND $user->save())
  45. {
  46. url::redirect('account/dashboard');
  47. }
  48. }
  49.  
  50. private function handle_photo()
  51. {
  52. $files = Validation::factory($_FILES)->add_rules('picture', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[1M]');
  53.  
  54. if ($files->validate())
  55. {
  56. $filename = upload::save('picture');
  57.  
  58. Image::factory($filename)
  59. ->resize(144, 196, Image::WIDTH)
  60. ->save(DOCROOT.'images/team/'.basename($filename));
  61.  
  62.  
  63. // Save Into Database
  64. $image = ORM::factory('user_photo');
  65. $image->primary = 1;
  66. $image->name = basename($filename);
  67. $image->save();
  68.  
  69. unlink($filename);
  70.  
  71. return $image;
  72. }
  73. }
  74.  
  75. }
Add Comment
Please, Sign In to add comment