Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class User extends Model{
- protected $table = 'user';
- protected $fillable = array('userID','username', 'password', 'email');
- public $timestamps = false;
- protected $primaryKey = 'userID';
- }
- class Controller
- {
- public function registerUser()
- {
- try{
- if(Input::get('password1') == Input::get('password2'))
- {
- $count = User::where('username', Input::get('username'))->count();
- if(!$count)
- {
- if($admin == 0)
- {
- $count2 = User::where('email', Input::get('email'))->count();
- }
- else
- {
- $count2 = false;
- }
- if(!$count2)
- {
- $user = new User();
- $user->username = Input::get('username');
- $user->password = Hash::make(Input::get('password1'));
- if($admin == 0)
- {
- $user->email = Input::get('email');
- $registerToken = str_random(50);
- $user->activate_token = $registerToken;
- $mailTxt = Lang::get('msg.emailActivationTextLink', ['link' => url('activate', ["code"=>$registerToken])]);
- Mail::raw($mailTxt, function($message)
- {
- $message->subject(Lang::get('msg.emailActivateSubject'));
- $message->from(Lang::get('msg.senderEmail'), Lang::get('msg.emailFrom'));
- $message->to(Input::get('email'));
- });
- }
- else
- {
- $user->active = 1;
- $user->activate_token = 'activated';
- $user->adminCreated = 1;
- $user->showPassword = Input::get('password1');
- }
- $user->save();
- $group = new Group();
- $group->setUserByKey(Input::get('keyGroup'),$user->id);
- if($admin == 0)
- {
- return Lang::get('msg.CheckUrEmail');
- }
- }else throw new \Exception(Lang::get('msg.emailAlreadyUser'));
- }else throw new \Exception(Lang::get('msg.userExist'));
- }else
- {
- throw new \Exception(Lang::get('msg.passwordNotMatch'));
- }
- }catch(\Exception $e){
- return new JsonResponse(['msg'=>$e->getMessage()], 422);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement