Advertisement
Guest User

Untitled

a guest
Feb 25th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.99 KB | None | 0 0
  1. <?php
  2.  
  3. class User extends Model{
  4.  
  5.     protected $table = 'user';
  6.     protected $fillable = array('userID','username', 'password', 'email');
  7.     public  $timestamps = false;
  8.     protected $primaryKey = 'userID';
  9.                
  10. }
  11.  
  12.  
  13.  
  14. class Controller
  15. {
  16.    
  17.    
  18.     public function registerUser()
  19.     {
  20.         try{
  21.             if(Input::get('password1') == Input::get('password2'))
  22.             {
  23.                 $count = User::where('username', Input::get('username'))->count();
  24.                 if(!$count)
  25.                 {
  26.                     if($admin == 0)
  27.                     {
  28.                         $count2 = User::where('email', Input::get('email'))->count();
  29.                     }
  30.                     else
  31.                     {
  32.                         $count2 = false;
  33.                     }
  34.                     if(!$count2)
  35.                     {
  36.                         $user = new User();
  37.                         $user->username = Input::get('username');
  38.                         $user->password = Hash::make(Input::get('password1'));
  39.                         if($admin == 0)
  40.                         {
  41.                             $user->email = Input::get('email');
  42.                             $registerToken = str_random(50);
  43.                             $user->activate_token = $registerToken;
  44.                             $mailTxt = Lang::get('msg.emailActivationTextLink', ['link' => url('activate', ["code"=>$registerToken])]);
  45.                             Mail::raw($mailTxt, function($message)
  46.                             {
  47.                                 $message->subject(Lang::get('msg.emailActivateSubject'));
  48.                                 $message->from(Lang::get('msg.senderEmail'), Lang::get('msg.emailFrom'));
  49.                                 $message->to(Input::get('email'));
  50.                             });
  51.                         }
  52.                         else
  53.                         {
  54.                             $user->active = 1;
  55.                             $user->activate_token = 'activated';
  56.                             $user->adminCreated = 1;
  57.                             $user->showPassword = Input::get('password1');
  58.                         }
  59.  
  60.                         $user->save();
  61.                         $group = new Group();
  62.                         $group->setUserByKey(Input::get('keyGroup'),$user->id);
  63.                         if($admin == 0)
  64.                         {
  65.                             return Lang::get('msg.CheckUrEmail');
  66.                         }
  67.                     }else throw new \Exception(Lang::get('msg.emailAlreadyUser'));
  68.                 }else throw new \Exception(Lang::get('msg.userExist'));
  69.             }else
  70.             {
  71.                 throw new \Exception(Lang::get('msg.passwordNotMatch'));
  72.             }
  73.         }catch(\Exception $e){
  74.             return new JsonResponse(['msg'=>$e->getMessage()], 422);
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement