/**
  * Create a new user authenticated through a social provider
  *
  * @param $field
  * @param $fieldValue
  * @return mixed
  */
 protected function createUser($userData, $provider)
 {
     $nameFromProvider = isset($userData->user['first_name']) ? $userData->user['first_name'] : $userData->nickname;
     $providerField = $this->selectProviderField($provider);
     $user = new User();
     $user->{$providerField} = $userData->id;
     $user->username = is_null(User::where('username', $nameFromProvider)->first()) ? $nameFromProvider : NULL;
     $user->email = !is_null($userData->email) && is_null(User::where('email', $userData->email)->first()) ? $userData->email : NULL;
     //$userData->email;
     $user->save();
     return User::where($providerField, $userData->id)->first();
 }
 /**
  * Update Profile
  *
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function updateProfile(Request $request)
 {
     $user = Auth::user();
     $profile = Profile::where('user_id', $user->id)->first();
     $userUpdateCheck = 0;
     $profileUpdateCheck = 0;
     if (!empty($request['username']) && is_null(User::where('username', $request['username'])->first())) {
         $user->username = $request['username'];
         $userUpdateCheck++;
     }
     if (!empty($request['email']) && is_null(User::where('email', $request['email'])->first())) {
         $user->email = $request['email'];
         $userUpdateCheck++;
     }
     if (!empty($request['first_name'])) {
         $profile->first_name = $request['first_name'];
         $profileUpdateCheck++;
     }
     if (!empty($request['last_name'])) {
         $profile->last_name = $request['last_name'];
         $profileUpdateCheck++;
     }
     if ($userUpdateCheck !== 0) {
         $user->save();
     }
     if ($profileUpdateCheck !== 0) {
         $profile->save();
     }
     return redirect('dashboard');
 }
 /**
  * Update the specified user profile in storage.
  * Receives POST from user/{id}/update.
  *
  * @param  \Learn\Http\Requests\UserProfileRequest $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(UserProfileRequest $request, $id)
 {
     $user = User::find($id);
     if ($request->hasFile('avatar')) {
         // Take new avatar, upload to cloudinary.
         $avatar = $request->file('avatar');
         $uploader = new FileUploader();
         $uploadedFile = $uploader->uploadFile($avatar);
         $user->avatar = $uploadedFile['url'];
     }
     $user->name = $request->input('name');
     $user->email = $request->input('email');
     $user->save();
     return redirect('/dashboard');
 }
 /**
  * Handle a login request to the application.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function postLogin(Request $request)
 {
     $field = filter_var($request['email'], FILTER_VALIDATE_EMAIL) ? "email" : "username";
     $user = User::where($field, $request['email'])->first();
     if (!is_null($user)) {
         if ($user->password == md5($request['password'])) {
             $request->has('remember') ? Auth::login($user, true) : Auth::login($user);
             return redirect('dashboard');
         }
     }
     return redirect('login');
 }
Exemple #5
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }
 /**
  * Find or create a new instance of a social user.
  *
  * @param array $data
  * @return User
  */
 protected function findOrCreateSocialUser(array $data)
 {
     $user = User::where('social_id', $data['social_id'])->first();
     if (is_null($user)) {
         return User::create($data);
     }
     return $user;
 }
 public function createUser()
 {
     User::create(['name' => 'johndoe', 'email' => '*****@*****.**', 'password' => md5('password')]);
 }