Example #1
2
 public function store()
 {
     $data = Input::all();
     if (isset($data['phone_number'])) {
         $data['phone_number'] = str_replace(' ', '', $data['phone_number']);
     }
     if (isset($data['work_phone'])) {
         $data['work_phone'] = str_replace(' ', '', $data['work_phone']);
     }
     $u = new User();
     $a = false;
     $role_id = Input::get('role_id');
     if ($role_id == Config::get('constants.ROLE_BUYER')) {
         $a = new Buyer();
         $u->status = 2;
         $data['skip_verification'] = true;
     } elseif ($role_id == Config::get('constants.ROLE_SELLER')) {
         $a = new Seller();
     } elseif ($role_id == Config::get('constants.ROLE_BROKER')) {
         $a = new Broker();
     } else {
         //we don't know this role or attempt to register unlisted role
         unset($data['role_id']);
     }
     if (!isset($data['password']) || $data['password'] == "") {
         $pwd = Str::random(10);
         $data['password'] = $data['password_confirmation'] = $pwd;
     }
     if ($u->validate($data)) {
         if ($a && $a->validate($data)) {
             if (isset($pwd)) {
                 Session::set('validate_password', true);
             }
             $data['password'] = Hash::make($data['password']);
             $u->fill($data);
             $code = Str::random(10);
             $u->verification_code = $code;
             $data['verification_code'] = $code;
             $u->save();
             $data['user_id'] = $u->id;
             $a->fill($data);
             $a->save();
             $email = $u->email;
             if (isset($data['skip_verification'])) {
                 $data['url']['link'] = url('/');
                 $data['url']['name'] = 'Go to CompanyExchange';
                 Mail::queue('emails.templates.welcome', $data, function ($message) use($email) {
                     $message->from('*****@*****.**', 'CompanyExchange');
                     $message->to($email);
                     $message->subject('Welcome to CompanyExchange');
                 });
             } else {
                 Mail::queue('emails.templates.progress', $data, function ($message) use($email) {
                     $message->from('*****@*****.**', 'CompanyExchange');
                     $message->to($email);
                     $message->subject('Welcome to CompanyExchange');
                 });
             }
             if ($role_id == Config::get('constants.ROLE_BUYER')) {
                 Auth::loginUsingId($u->id);
                 Alert::success('Welcome to CompanyExchange. Please feel free to browse through our listings and contact sellers you would like to buy from.', 'Congratulations');
                 return Redirect::to('search?q=')->withSuccess("Welcome {$u->first_name}. Use the form on the left to search for listed businesses or browse the most recent listings below");
             }
             return Redirect::to('login')->withSuccess('Registration successful. Please check email to activate your account');
         }
         Input::flash();
         return View::make('users.register')->withErrors($a ? $a->getValidator() : []);
     }
     Input::flash();
     return View::make('users.register')->withErrors($u->getValidator());
 }
Example #2
0
 /**
  * Create a user.
  *
  * @param User The user to create.
  *
  * @return void
  */
 public static function createUser(User $user)
 {
     Log::info('Create user.', compact('user'));
     $validator = $user->getValidator();
     if ($validator->fails()) {
         throw new ValidationException($validator);
     }
     unset($user->password_confirmation);
     $user->password = Hash::make($user->password);
     $user->created_by = Auth::user()->id;
     $user->updated_by = Auth::user()->id;
     $user->save();
 }
Example #3
0
 private function registerUser($data, $role)
 {
     if (isset($data['phone_number'])) {
         $data['phone_number'] = str_replace(' ', '', $data['phone_number']);
     }
     if (isset($data['work_phone'])) {
         $data['work_phone'] = str_replace(' ', '', $data['work_phone']);
     }
     $u = new User();
     $data['role_id'] = $role;
     switch (strtolower($role)) {
         case Config::get('constants.ROLE_SELLER'):
             $a = new Seller();
             break;
         case Config::get('constants.ROLE_BROKER'):
             $a = new Broker();
             break;
         default:
             $a = new Buyer();
             $u->status = 2;
             $data['skip_verification'] = true;
             break;
     }
     if (!isset($data['password']) || $data['password'] == "") {
         $pwd = Str::random(10);
         $data['password'] = $data['password_confirmation'] = $pwd;
     }
     if ($u->validate($data)) {
         if ($a->validate($data)) {
             if (isset($pwd)) {
                 Session::set('validate_password', true);
             }
             $data['password'] = Hash::make($data['password']);
             $u->fill($data);
             $code = Str::random(10);
             $u->verification_code = $code;
             $data['verification_code'] = $code;
             $u->save();
             $data['user_id'] = $u->id;
             $a->fill($data);
             $a->save();
             $email = $u->email;
             if (isset($data['skip_verification'])) {
                 $data['url']['link'] = url('/');
                 $data['url']['name'] = 'Go to CompanyExchange';
                 Mail::queue('emails.templates.welcome', $data, function ($message) use($email) {
                     $message->from('*****@*****.**', 'CompanyExchange');
                     $message->to($email);
                     $message->subject('Welcome to CompanyExchange');
                 });
             } else {
                 Mail::queue('emails.templates.progress', $data, function ($message) use($email) {
                     $message->from('*****@*****.**', 'CompanyExchange');
                     $message->to($email);
                     $message->subject('Welcome to CompanyExchange');
                 });
             }
             Auth::loginUsingId($u->id);
             return true;
         }
         Input::flash();
         return $a->getValidator();
     }
     Input::flash();
     return $u->getValidator();
 }