コード例 #1
0
 public function findBySocialIdOrCreate($user)
 {
     $authUser = User::firstOrNew(['social_id' => $user->id]);
     if (!is_null($authUser->id)) {
         return $authUser;
     }
     $authUser->username = $user->name ? $user->name : $user->nickname;
     $authUser->email = $user->email ? $user->email : "";
     $authUser->password = bcrypt($user->id);
     $authUser->social_id = $user->id;
     $authUser->avatar_url = $user->avatar;
     $authUser->save();
     return $authUser;
 }
コード例 #2
0
 /**
  * 
  * @param  Request $request [description]
  * @param  $id
  */
 public function postUpdateUserProfile(Request $request, $id)
 {
     $id = Auth::user()->id;
     try {
         $user = User::find($id);
         if (isset($request->avatar)) {
             $user->avatar = $this->uploadAvatarCloudinary($request->avatar);
             $user->fullname = $request->fullname;
             $user->occupation = $request->occupation;
         } else {
             $user->fullname = $request->fullname;
             $user->occupation = $request->occupation;
         }
         $user->save();
         return back()->with('status', 'Yay! Status updated successfully');
     } catch (QueryException $e) {
         return back()->with('status', $e->getMessage());
     }
 }
コード例 #3
0
 /**
  * Handles user registration
  *
  * @param \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function postRegister(Request $request)
 {
     $v = Validator::make($request->all(), ['fullname' => 'required', 'username' => 'required|max:255', 'occupation' => 'required', 'email' => 'required|email|unique:users', 'password' => 'required']);
     if ($v->fails()) {
         return redirect()->back()->withErrors($v->errors());
     }
     $data = $request->all();
     $data['password'] = bcrypt($request->input('password'));
     User::create($data);
     return redirect('/auth/login');
 }
コード例 #4
0
 /**
  * create a new instance of a user
  * @param $data
  */
 public function create($data)
 {
     User::create($data);
 }
コード例 #5
0
 public function testFacebookSocialOAuth()
 {
     User::create(['id' => 1, 'fullname' => 'florence', 'username' => 'florence', 'provider_id' => 1146673212009898, 'avatar' => 'https://graph.facebook.com/v2.5/1146673212009898/picture?type=normal']);
     $user = User::where('provider_id', '=', 1146673212009898)->first();
     $userData = ['id' => 1146673212009898, 'nickname' => 'florence', 'name' => 'florence', 'email' => '*****@*****.**', 'avatar' => 'https://graph.facebook.com/v2.5/1146673212009898/picture?type=normal'];
     $provider = 'github';
     $mock = Mockery::mock('Techademia\\Repositories\\UserRepository');
     $mock->shouldReceive('findByProviderIdOrCreate')->with($userData, $provider)->andReturn($user);
     $this->assertSame($user, $mock->findByProviderIdOrCreate($userData, $provider));
 }
コード例 #6
0
 /**
  * getSocialData Pass the user details to signup form
  *
  * @param  $userData
  * @param  $provider
  */
 protected function getUserData($data, $provider)
 {
     $array = ['username' => $data->getNickname(), 'email' => $data->getEmail(), 'facebookID' => 0, 'twitterID' => 0, 'githubID' => 0];
     $array[$provider . 'ID'] = $data->getId();
     if ($data->getNickname() === null) {
         $array['username'] = Str::slug($userData->getName());
     }
     $user = User::create($array);
     if ($user) {
         $this->createAvatar($array['username'], $data->getAvatar());
         Auth::loginUsingId($user->id, true);
         return $this->userHasLoggedIn();
     }
 }