Fixes #1247 - allow SVG logo upload

This commit is contained in:
snipe 2016-12-27 17:31:53 -08:00
parent 55415e8f56
commit fd805bde50
3 changed files with 65 additions and 20 deletions

View file

@ -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 {

View 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);
}
}

View file

@ -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>