Added settings helper and formatted code in some files

This commit is contained in:
Dan Brown
2016-03-06 12:55:08 +00:00
parent e744d4c82c
commit 66c56e9d02
10 changed files with 37 additions and 25 deletions

View File

@ -123,7 +123,7 @@ abstract class Entity extends Ownable
// Ensure at least one exact term matches if in search // Ensure at least one exact term matches if in search
if (count($exactTerms) > 0) { if (count($exactTerms) > 0) {
$search = $search->where(function($query) use ($exactTerms, $fieldsToSearch) { $search = $search->where(function ($query) use ($exactTerms, $fieldsToSearch) {
foreach ($exactTerms as $exactTerm) { foreach ($exactTerms as $exactTerm) {
foreach ($fieldsToSearch as $field) { foreach ($fieldsToSearch as $field) {
$query->orWhere($field, 'like', $exactTerm); $query->orWhere($field, 'like', $exactTerm);

View File

@ -71,7 +71,7 @@ class AuthController extends Controller
protected function checkRegistrationAllowed() protected function checkRegistrationAllowed()
{ {
if (!\Setting::get('registration-enabled')) { if (!setting('registration-enabled')) {
throw new UserRegistrationException('Registrations are currently disabled.', '/login'); throw new UserRegistrationException('Registrations are currently disabled.', '/login');
} }
} }
@ -170,8 +170,8 @@ class AuthController extends Controller
*/ */
protected function registerUser(array $userData, $socialAccount = false) protected function registerUser(array $userData, $socialAccount = false)
{ {
if (\Setting::get('registration-restrict')) { if (setting('registration-restrict')) {
$restrictedEmailDomains = explode(',', str_replace(' ', '', \Setting::get('registration-restrict'))); $restrictedEmailDomains = explode(',', str_replace(' ', '', setting('registration-restrict')));
$userEmailDomain = $domain = substr(strrchr($userData['email'], "@"), 1); $userEmailDomain = $domain = substr(strrchr($userData['email'], "@"), 1);
if (!in_array($userEmailDomain, $restrictedEmailDomains)) { if (!in_array($userEmailDomain, $restrictedEmailDomains)) {
throw new UserRegistrationException('That email domain does not have access to this application', '/register'); throw new UserRegistrationException('That email domain does not have access to this application', '/register');
@ -183,7 +183,7 @@ class AuthController extends Controller
$newUser->socialAccounts()->save($socialAccount); $newUser->socialAccounts()->save($socialAccount);
} }
if (\Setting::get('registration-confirmation') || \Setting::get('registration-restrict')) { if (setting('registration-confirmation') || setting('registration-restrict')) {
$newUser->email_confirmed = false; $newUser->email_confirmed = false;
$newUser->save(); $newUser->save();
$this->emailConfirmationService->sendConfirmation($newUser); $this->emailConfirmationService->sendConfirmation($newUser);

View File

@ -39,7 +39,7 @@ class Authenticate
return redirect()->guest('/register/confirm/awaiting'); return redirect()->guest('/register/confirm/awaiting');
} }
if ($this->auth->guest() && !Setting::get('app-public')) { if ($this->auth->guest() && !setting('app-public')) {
if ($request->ajax()) { if ($request->ajax()) {
return response('Unauthorized.', 401); return response('Unauthorized.', 401);
} else { } else {

View File

@ -124,7 +124,7 @@ class PermissionsRepo
// Prevent deleting admin role or default registration role. // Prevent deleting admin role or default registration role.
if ($role->name === 'admin') { if ($role->name === 'admin') {
throw new PermissionsException('The admin role cannot be deleted'); throw new PermissionsException('The admin role cannot be deleted');
} else if ($role->id == Setting::get('registration-role')) { } else if ($role->id == setting('registration-role')) {
throw new PermissionsException('This role cannot be deleted while set as the default registration role.'); throw new PermissionsException('This role cannot be deleted while set as the default registration role.');
} }

View File

@ -77,7 +77,7 @@ class UserRepo
*/ */
public function attachDefaultRole($user) public function attachDefaultRole($user)
{ {
$roleId = Setting::get('registration-role'); $roleId = setting('registration-role');
if ($roleId === false) $roleId = $this->role->first()->id; if ($roleId === false) $roleId = $this->role->first()->id;
$user->attachRoleId($roleId); $user->attachRoleId($roleId);
} }

View File

@ -45,7 +45,7 @@ class EmailConfirmationService
'token' => $token, 'token' => $token,
]); ]);
$this->mailer->send('emails/email-confirmation', ['token' => $token], function (Message $message) use ($user) { $this->mailer->send('emails/email-confirmation', ['token' => $token], function (Message $message) use ($user) {
$appName = \Setting::get('app-name', 'BookStack'); $appName = setting('app-name', 'BookStack');
$message->to($user->email, $user->name)->subject('Confirm your email on ' . $appName . '.'); $message->to($user->email, $user->name)->subject('Confirm your email on ' . $appName . '.');
}); });
} }

View File

@ -79,7 +79,7 @@ class ImageService
private function saveNew($imageName, $imageData, $type) private function saveNew($imageName, $imageData, $type)
{ {
$storage = $this->getStorage(); $storage = $this->getStorage();
$secureUploads = Setting::get('app-secure-images'); $secureUploads = setting('app-secure-images');
$imageName = str_replace(' ', '-', $imageName); $imageName = str_replace(' ', '-', $imageName);
if ($secureUploads) $imageName = str_random(16) . '-' . $imageName; if ($secureUploads) $imageName = str_random(16) . '-' . $imageName;

View File

@ -135,7 +135,7 @@ class SocialAuthService
// Otherwise let the user know this social account is not used by anyone. // Otherwise let the user know this social account is not used by anyone.
$message = 'This ' . $socialDriver . ' account is not linked to any users. Please attach it in your profile settings'; $message = 'This ' . $socialDriver . ' account is not linked to any users. Please attach it in your profile settings';
if (\Setting::get('registration-enabled')) { if (setting('registration-enabled')) {
$message .= ' or, If you do not yet have an account, You can register an account using the ' . $socialDriver . ' option'; $message .= ' or, If you do not yet have an account, You can register an account using the ' . $socialDriver . ' option';
} }
throw new SocialSignInException($message . '.', '/login'); throw new SocialSignInException($message . '.', '/login');

View File

@ -59,3 +59,15 @@ function userCan($permission, \BookStack\Ownable $ownable = null)
$hasAccess = $restrictionService->checkIfEntityRestricted($ownable, $action); $hasAccess = $restrictionService->checkIfEntityRestricted($ownable, $action);
return $hasAccess && $hasPermission; return $hasAccess && $hasPermission;
} }
/**
* Helper to access system settings.
* @param $key
* @param bool $default
* @return mixed
*/
function setting($key, $default = false)
{
$settingService = app('BookStack\Services\SettingService');
return $settingService->get($key, $default);
}

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>{{ isset($pageTitle) ? $pageTitle . ' | ' : '' }}{{ Setting::get('app-name', 'BookStack') }}</title> <title>{{ isset($pageTitle) ? $pageTitle . ' | ' : '' }}{{ setting('app-name', 'BookStack') }}</title>
<!-- Meta --> <!-- Meta -->
<meta name="viewport" content="width=device-width"> <meta name="viewport" content="width=device-width">
@ -29,10 +29,10 @@
<div class="row"> <div class="row">
<div class="col-lg-4 col-sm-4" ng-non-bindable> <div class="col-lg-4 col-sm-4" ng-non-bindable>
<a href="/" class="logo"> <a href="/" class="logo">
@if(Setting::get('app-logo', '') !== 'none') @if(setting('app-logo', '') !== 'none')
<img class="logo-image" src="{{ Setting::get('app-logo', '') === '' ? '/logo.png' : Setting::get('app-logo', '') }}" alt="Logo"> <img class="logo-image" src="{{ setting('app-logo', '') === '' ? '/logo.png' : setting('app-logo', '') }}" alt="Logo">
@endif @endif
<span class="logo-text">{{ Setting::get('app-name', 'BookStack') }}</span> <span class="logo-text">{{ setting('app-name', 'BookStack') }}</span>
</a> </a>
</div> </div>
<div class="col-lg-4 col-sm-3 text-center"> <div class="col-lg-4 col-sm-3 text-center">