Example #1
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (Auth::guest()) {
         return $next($request);
     }
     UserDetail::firstOrCreate(['user_id' => Auth::user()->id]);
     return $next($request);
 }
Example #2
0
 /**
  * Display the specified resource.
  *
  * @param User $user
  * @param  int  $slug
  * @return \Illuminate\Http\Response
  */
 public function show(User $user, $slug)
 {
     $user = $user->findBySlug($slug)->first();
     $userDetails = UserDetail::whereUserId($user->id)->first();
     return view('users.profile_show', compact('user', 'userDetails'));
 }
Example #3
0
 /**
  * Store the user account details (user_details)
  **
  *
  * @return \Illuminate\Http\Response
  */
 public function storeDetails()
 {
     $userDetail = new UserDetail($this->request->all());
     $oUserDetail = UserDetail::find($this->request['user_id']);
     Helper::allow('user-edit');
     //check if there is a new avatar and upload it
     if ($this->request->file('avatar')) {
         $imgPath = storage_path() . '/app/public/users/avatars/';
         $img = Image::make(Input::file('avatar'))->fit(200, 200)->encode('jpg', 75)->save($imgPath . $oUserDetail->user->slug . '.jpg');
         $oUserDetail->avatar->update(['location' => $img->basename]);
     }
     $oUserDetail->update($userDetail->toArray());
     //update the last update timestamp
     $oUserDetail->user->touch();
     return redirect()->route('user.details.show', Auth::user()->slug)->with(['success' => 'Your account details have been updated!']);
 }
Example #4
0
 /**
  * Return user if exists; create and create if not
  *
  * @param $facebookUser
  *
  * @return User
  */
 private function findOrCreateUser($facebookUser)
 {
     $user = User::where('sns_acc_id', $facebookUser->id)->first();
     //check if the facebook id already exists
     if ($user) {
         return $user;
     }
     //get the profile picture contents
     /*$contents = file_get_contents('http://graph.facebook.com/' . $facebookUser->id . '/picture?type=large&redirect=false');
       $contents = json_decode($contents, true);*/
     //check if the email exists, update the facebook id
     if ($user = User::where('email', $facebookUser->email)->first()) {
         User::whereId($user->id)->update(['sns_acc_id' => $facebookUser->id]);
         $user->userDetail->update(['gender' => strtoupper(substr($facebookUser['gender'], 0, 1)), 'first_name' => $facebookUser['first_name'], 'last_name' => $facebookUser['last_name'], 'confirmed' => $facebookUser['verified']]);
         /*if (empty($user->userDetail->avatar->location)) {
               $user->userDetail->avatar->update(['location' => $contents['data']['url']]);
           }*/
         return $user;
     }
     //continue adding a new user
     $name = $this->generateUsername($facebookUser->name);
     $user_id = User::insertGetId(['username' => $name, 'slug' => str_slug($name), 'email' => $facebookUser->email, 'sns_acc_id' => $facebookUser->id]);
     $details_id = UserDetail::insertGetId(['user_id' => $user_id, 'first_name' => $facebookUser['first_name'], 'last_name' => $facebookUser['last_name'], 'gender' => strtoupper(substr($facebookUser['gender'], 0, 1)), 'confirmed' => $facebookUser['verified']]);
     //UserAvatar::insert(['user_detail_id' => $details_id, 'location' => $contents['data']['url']]);
     $user = User::find($user_id);
     Email::sendWelcomeEmail($user);
     return $user;
 }