mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Fixes #1247 - allow SVG logo upload
This commit is contained in:
parent
55415e8f56
commit
fd805bde50
|
@ -3,6 +3,7 @@ namespace App\Http\Controllers;
|
|||
|
||||
use Input;
|
||||
use Lang;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Ldap;
|
||||
use Redirect;
|
||||
|
@ -18,6 +19,8 @@ use Mail;
|
|||
use Auth;
|
||||
use App\Models\User;
|
||||
use App\Http\Requests\SetupUserRequest;
|
||||
use App\Http\Requests\ImageUploadRequest;
|
||||
|
||||
|
||||
/**
|
||||
* This controller handles all actions related to Settings for
|
||||
|
@ -292,7 +295,7 @@ class SettingsController extends Controller
|
|||
* @since [v1.0]
|
||||
* @return Redirect
|
||||
*/
|
||||
public function postEdit()
|
||||
public function postEdit(ImageUploadRequest $request)
|
||||
{
|
||||
|
||||
// Check if the asset exists
|
||||
|
@ -301,25 +304,10 @@ class SettingsController extends Controller
|
|||
return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error'));
|
||||
}
|
||||
|
||||
if (Input::get('clear_logo')=='1') {
|
||||
$setting->logo = null;
|
||||
} elseif (Input::file('logo_img')) {
|
||||
if (!config('app.lock_passwords')) {
|
||||
$image = Input::file('logo_img');
|
||||
$file_name = "logo.".$image->getClientOriginalExtension();
|
||||
$path = public_path('uploads/'.$file_name);
|
||||
Image::make($image->getRealPath())->resize(null, 40, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
})->save($path);
|
||||
$setting->logo = $file_name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!config('app.lock_passwords')) {
|
||||
$setting->site_name = e(Input::get('site_name'));
|
||||
$setting->brand = e(Input::get('brand'));
|
||||
|
||||
$setting->custom_css = e(Input::get('custom_css'));
|
||||
|
||||
if (Input::get('two_factor_enabled')=='') {
|
||||
|
@ -420,6 +408,28 @@ class SettingsController extends Controller
|
|||
$setting->ldap_tls = e(Input::get('ldap_tls', '0'));
|
||||
$setting->ldap_pw_sync = e(Input::get('ldap_pw_sync', '0'));
|
||||
|
||||
|
||||
if ($request->input('clear_logo')=='1') {
|
||||
$setting->logo = null;
|
||||
$setting->brand = 1;
|
||||
} elseif ($request->hasFile('image')) {
|
||||
|
||||
if (!config('app.lock_passwords')) {
|
||||
$image = $request->file('image');
|
||||
$file_name = "logo.".$image->getClientOriginalExtension();
|
||||
$path = public_path('uploads');
|
||||
if ($image->getClientOriginalExtension()!='svg') {
|
||||
Image::make($image->getRealPath())->resize(null, 40, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
})->save($path.'/'.$file_name);
|
||||
} else {
|
||||
$image->move($path, $file_name);
|
||||
}
|
||||
$setting->logo = $file_name;
|
||||
}
|
||||
}
|
||||
|
||||
if ($setting->save()) {
|
||||
return redirect()->to("admin/settings/app")->with('success', trans('admin/settings/message.update.success'));
|
||||
} else {
|
||||
|
|
35
app/Http/Requests/ImageUploadRequest.php
Normal file
35
app/Http/Requests/ImageUploadRequest.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class ImageUploadRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'image' => 'mimes:png,gif,jpg,jpeg,svg|max:2000'
|
||||
];
|
||||
}
|
||||
|
||||
public function response(array $errors)
|
||||
{
|
||||
return $this->redirector->back()->withInput()->withErrors($errors, $this->errorBag);
|
||||
}
|
||||
}
|
|
@ -128,7 +128,7 @@
|
|||
<!-- /.form-group -->
|
||||
|
||||
<!-- Logo -->
|
||||
<div class="form-group {{ $errors->has('logo') ? 'has-error' : '' }}">
|
||||
<div class="form-group {{ $errors->has('image') ? 'has-error' : '' }}">
|
||||
<div class="col-md-3">
|
||||
{{ Form::label('logo', trans('admin/settings/general.logo')) }}
|
||||
</div>
|
||||
|
@ -136,8 +136,8 @@
|
|||
@if (config('app.lock_passwords'))
|
||||
<p class="help-block">{{ trans('general.lock_passwords') }}</p>
|
||||
@else
|
||||
{{ Form::file('logo_img') }}
|
||||
{!! $errors->first('logo', '<span class="alert-msg">:message</span>') !!}
|
||||
{{ Form::file('image') }}
|
||||
{!! $errors->first('image', '<span class="alert-msg">:message</span>') !!}
|
||||
{{ Form::checkbox('clear_logo', '1', Input::old('clear_logo'),array('class' => 'minimal')) }} Remove
|
||||
@endif
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue