Advertisement
Guest User

Untitled

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