Beispiel #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());
 }
Beispiel #2
0
 /**
  * Store user account
  * @return Response
  */
 public function storeUser()
 {
     $data = Input::all();
     $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();
     }
     $data['password_confirmation'] = $data['password'];
     if ($u->validate($data)) {
         if ($a->validate($data)) {
             $data['password'] = Hash::make($data['password']);
             $u->fill($data);
             $u->save();
             $a->fill($data);
             $a->user_id = $u->id;
             $a->save();
             return Redirect::to('admin/accounts')->withCreate(true)->withUsr($u);
         }
         return View::make('admin.users.create')->withErrors($a->getValidator());
     }
     return View::make('admin.users.create')->withErrors($u->getValidator());
 }