added it_update_user_settings, it_update_user_avatar test

This commit is contained in:
Peter Papp
2021-03-03 08:42:07 +01:00
parent 7f21755f5a
commit cd9d1d91bd
8 changed files with 78 additions and 86 deletions
+15 -46
View File
@@ -49,56 +49,13 @@ class AccountController extends Controller
*
* @return InvoiceCollection
*/
public function invoices() {
public function invoices()
{
return new InvoiceCollection(
Auth::user()->invoices()
);
}
/**
* Update user profile
*
* @param Request $request
* @return ResponseFactory|\Illuminate\Http\Response
*/
public function update_profile(Request $request)
{
// Validate request
$validator = Validator::make($request->all(), [
'avatar' => 'file',
'name' => 'string',
'value' => 'string',
]);
// Return error
if ($validator->fails()) abort(400, 'Bad input');
// Get user
$user = Auth::user();
// Check if is demo
if (is_demo($user->id)) {
return Demo::response_204();
}
// Update data
if ($request->hasFile('avatar')) {
// Update avatar
$avatar = store_avatar($request->file('avatar'), 'avatars');
// Update data
$user->update(['avatar' => $avatar]);
} else {
// Update text data
$user->update(make_single_input($request));
}
return response('Saved!', 204);
}
/**
* Update user settings relationship
*
@@ -108,7 +65,9 @@ class AccountController extends Controller
public function update_user_settings(Request $request)
{
// Validate request
// TODO: pridat validator do requestu
$validator = Validator::make($request->all(), [
'avatar' => 'sometimes|file',
'name' => 'string',
'value' => 'string',
]);
@@ -124,7 +83,17 @@ class AccountController extends Controller
return Demo::response_204();
}
// Update text data
// Update avatar
if ($request->hasFile('avatar')) {
$user
->settings()
->update([
'avatar' => store_avatar($request->file('avatar'))
]);
return response('Saved!', 204);
}
$user
->settings()
->update(
+7 -15
View File
@@ -227,16 +227,12 @@ function is_editor($shared)
* Store user avatar to storage
*
* @param $image
* @param $path
* @return string
*/
function store_avatar($image, $path)
function store_avatar($image)
{
// Get directory
$path = check_directory($path);
// Store avatar
$image_path = Str::random(8) . '-' . $image->getClientOriginalName();
$image_path = Str::random(16) . '-' . $image->getClientOriginalName();
// Create intervention image
$img = Image::make($image->getRealPath());
@@ -245,32 +241,28 @@ function store_avatar($image, $path)
$img->fit('150', '150')->stream();
// Store thumbnail to disk
Storage::put($path . '/' . $image_path, $img);
Storage::put("avatars/$image_path", $img);
// Return path to image
return $path . '/' . $image_path;
return "avatars/$image_path";
}
/**
* Store system image
*
* @param $image
* @param $path
* @return string
*/
function store_system_image($image, $path)
function store_system_image($image)
{
// Get directory
$path = check_directory($path);
// Store avatar
$image_path = Str::random(8) . '-' . str_replace(' ', '', $image->getClientOriginalName());
// Store image to disk
Storage::putFileAs($path, $image, $image_path);
Storage::putFileAs('system', $image, $image_path);
// Return path to image
return $path . '/' . $image_path;
return `system/$image_path`;
}
/**