use Illuminate\Http\Request;
-use Illuminate\Support\Facades\Hash;
+use Illuminate\Http\Response;
use BookStack\Http\Requests;
use BookStack\Repos\UserRepo;
use BookStack\Services\SocialAuthService;
/**
* Display a listing of the users.
- *
* @return Response
*/
public function index()
/**
* Show the form for creating a new user.
- *
* @return Response
*/
public function create()
/**
* Store a newly created user in storage.
- *
* @param Request $request
* @return Response
*/
$user->save();
$user->attachRoleId($request->get('role'));
+
+ // Get avatar from gravatar and save
+ if (!env('DISABLE_EXTERNAL_SERVICES', false)) {
+ $avatar = \Images::saveUserGravatar($user);
+ $user->avatar()->associate($avatar);
+ $user->save();
+ }
+
return redirect('/users');
}
/**
* Show the form for editing the specified user.
- *
* @param int $id
* @param SocialAuthService $socialAuthService
* @return Response
/**
* Update the specified user in storage.
- *
* @param Request $request
* @param int $id
* @return Response
/**
* Remove the specified user from storage.
- *
* @param int $id
* @return Response
*/
return $this->currentUser->id == $id;
});
$user = $this->userRepo->getById($id);
+
// Delete social accounts
- if($this->userRepo->isOnlyAdmin($user)) {
+ if ($this->userRepo->isOnlyAdmin($user)) {
session()->flash('error', 'You cannot delete the only admin');
return redirect($user->getEditUrl());
}
+
$user->socialAccounts()->delete();
$user->delete();
return redirect('/users');
* Get a thumbnail for this image.
* @param int $width
* @param int $height
- * @param bool|false $hardCrop
+ * @param bool|false $keepRatio
* @return string
*/
- public function getThumb($width, $height, $hardCrop = false)
+ public function getThumb($width, $height, $keepRatio = false)
{
- return Images::getThumbnail($this, $width, $height, $hardCrop);
+ return Images::getThumbnail($this, $width, $height, $keepRatio);
}
}
*/
public function saveUserGravatar(User $user, $size = 500)
{
- if (!env('USE_GRAVATAR', false)) return false;
$emailHash = md5(strtolower(trim($user->email)));
$url = 'http://www.gravatar.com/avatar/' . $emailHash . '?s=' . $size . '&d=identicon';
$imageName = str_replace(' ', '-', $user->name . '-gravatar.png');
$image = $this->saveNewFromUrl($url, 'user', $imageName);
$image->created_by = $user->id;
$image->save();
- $user->avatar()->associate($image);
- $user->save();
return $image;
}
public function getAvatar($size = 50)
{
if ($this->image_id === 0 || $this->image_id === null) return '/user_avatar.png';
- return $this->avatar->getThumb($size, $size, true);
+ return $this->avatar->getThumb($size, $size, false);
}
/**
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="mysql_testing"/>
<env name="MAIL_PRETEND" value="true"/>
+ <env name="DISABLE_EXTERNAL_SERVICES" value="true"/>
</php>
</phpunit>