public function store(UserFormRequest $request)
 {
     $user = new User(['email' => $request->input('email'), 'status' => $request->input('status'), 'password' => bcrypt($request->input('password'))]);
     $user->save();
     $user->assignRole($request->input('role'));
     $profile = new Profile($request->input('profile'));
     $profile->user()->associate($user);
     if ($request->hasFile('profile.profile_picture') && $request->file('profile.profile_picture')->isValid()) {
         $profile->profile_picture = $profile->saveProfilePicture($request->file('profile.profile_picture'));
     }
     $extendedProfile = new ExtendedProfile($request->input('profile.extendedProfile', []));
     $profile->save();
     $profile->extendedProfile()->save($extendedProfile);
     return redirect()->route('admin.user.index')->with('messages', [$user->getName() . ' has been created.']);
 }
 public function store(UserFormRequest $request)
 {
     $currentUser = Auth::user();
     if (!$currentUser->is('administrator')) {
         return redirect()->back()->withErrors(['You are not authorized to do this.']);
     }
     $user = new User(['email' => $request->input('email'), 'status' => $request->input('status'), 'password' => bcrypt($request->input('password'))]);
     $user->manage_property = $request->input('manage_property', false);
     $user->save();
     $user->assignRole('agent');
     $profile = new Profile($request->input('profile'));
     $profile->user()->associate($user);
     if ($request->hasFile('profile.profile_picture') && $request->file('profile.profile_picture')->isValid()) {
         $profile->profile_picture = $profile->saveProfilePicture($request->file('profile.profile_picture'));
     }
     $profile->save();
     return redirect()->route('admin.agent.index')->with('messages', [$user->getName() . ' has been created.']);
 }
 public function store(UserFormRequest $request)
 {
     $user = new User(['email' => $request->input('email'), 'status' => $request->input('status'), 'password' => bcrypt($request->input('password'))]);
     $user->save();
     $user->assignRole('authenticated_user');
     $profile = new Profile($request->input('profile'));
     $profile->user()->associate($user);
     if ($request->hasFile('profile.profile_picture') && $request->file('profile.profile_picture')->isValid()) {
         $profile->profile_picture = $profile->saveProfilePicture($request->file('profile.profile_picture'));
     }
     $extendedProfile = new ExtendedProfile($request->input('profile.extendedProfile'));
     $profile->save();
     $profile->extendedProfile()->save($extendedProfile);
     $subscriptions = [];
     foreach ($request->input('subscriptions', []) as $subscriptionSlug) {
         $subscriptions[] = Subscription::findBySlug($subscriptionSlug)->id;
     }
     $user->subscriptions()->sync($subscriptions);
     return redirect()->route('admin.member.index')->with('messages', [$user->getName() . ' has been created.']);
 }
 protected function findOrCreateUser($socialUser)
 {
     $authUser = User::where('facebook_id', $socialUser->getId())->orWhere('email', $socialUser->getEmail())->first();
     if ($authUser) {
         return $authUser;
     }
     $user = User::create(['email' => $socialUser->getEmail(), 'facebook_id' => $socialUser->getId()]);
     $user->assignRole('authenticated_user');
     //Set Name
     $exploded = explode(' ', $socialUser->getName());
     $profile = new Profile();
     $profile->first_name = $exploded[0];
     unset($exploded[0]);
     if (isset($exploded[1])) {
         $profile->last_name = implode(' ', $exploded);
     }
     $profile->user()->associate($user);
     /*
     if(!empty($data['profile']['profile_picture']) && $data['profile']['profile_picture']->isValid()){
         $profile->profile_picture = $profile->saveProfilePicture($data['profile']['profile_picture']);
     }
     */
     $profile->profile_picture = $profile->saveRemoteProfilePicture($socialUser->getAvatar());
     $profile->save();
     $extendedProfile = new ExtendedProfile();
     $profile->extendedProfile()->save($extendedProfile);
     $subscriptions = Subscription::all()->pluck('id')->all();
     $user->subscriptions()->sync($subscriptions);
     return $user;
 }
 public function notifySignedUpReferralAgents()
 {
     $submissions = FormSubmission::groupBy('email')->get();
     foreach ($submissions as $submission) {
         if (User::where('email', $submission->email)->count() < 1) {
             $password = str_random(8);
             $user = new User(['email' => $submission->email, 'status' => User::STATUS_ACTIVE, 'password' => bcrypt($password)]);
             $user->manage_property = FALSE;
             $user->save();
             $user->assignRole('agent');
             $names = explode(' ', $submission->getData('name'));
             $profile = new Profile();
             $profile->fill(['first_name' => array_shift($names), 'last_name' => !empty($names) ? implode(' ', $names) : '', 'mobile_phone_number' => $submission->getData('contact_number'), 'address' => $submission->getData('address') . ', ' . $submission->getData('city')]);
             $profile->user()->associate($user);
             $profile->save();
             $user->load('profile');
             $this->notifyReferralAgent($user, $password);
         }
     }
 }