Showing
10 changed files
with
37 additions
and
25 deletions
| ... | @@ -107,7 +107,7 @@ abstract class Entity extends Ownable | ... | @@ -107,7 +107,7 @@ abstract class Entity extends Ownable |
| 107 | $exactTerms = []; | 107 | $exactTerms = []; |
| 108 | foreach ($terms as $key => $term) { | 108 | foreach ($terms as $key => $term) { |
| 109 | $term = htmlentities($term, ENT_QUOTES); | 109 | $term = htmlentities($term, ENT_QUOTES); |
| 110 | - $term = preg_replace('/[+\-><\(\)~*\"@]+/', ' ', $term); | 110 | + $term = preg_replace('/[+\-><\(\)~*\"@]+/', ' ', $term); |
| 111 | if (preg_match('/\s/', $term)) { | 111 | if (preg_match('/\s/', $term)) { |
| 112 | $exactTerms[] = '%' . $term . '%'; | 112 | $exactTerms[] = '%' . $term . '%'; |
| 113 | $term = '"' . $term . '"'; | 113 | $term = '"' . $term . '"'; |
| ... | @@ -123,7 +123,7 @@ abstract class Entity extends Ownable | ... | @@ -123,7 +123,7 @@ abstract class Entity extends Ownable |
| 123 | 123 | ||
| 124 | // Ensure at least one exact term matches if in search | 124 | // Ensure at least one exact term matches if in search |
| 125 | if (count($exactTerms) > 0) { | 125 | if (count($exactTerms) > 0) { |
| 126 | - $search = $search->where(function($query) use ($exactTerms, $fieldsToSearch) { | 126 | + $search = $search->where(function ($query) use ($exactTerms, $fieldsToSearch) { |
| 127 | foreach ($exactTerms as $exactTerm) { | 127 | foreach ($exactTerms as $exactTerm) { |
| 128 | foreach ($fieldsToSearch as $field) { | 128 | foreach ($fieldsToSearch as $field) { |
| 129 | $query->orWhere($field, 'like', $exactTerm); | 129 | $query->orWhere($field, 'like', $exactTerm); | ... | ... |
| ... | @@ -41,9 +41,9 @@ class AuthController extends Controller | ... | @@ -41,9 +41,9 @@ class AuthController extends Controller |
| 41 | 41 | ||
| 42 | /** | 42 | /** |
| 43 | * Create a new authentication controller instance. | 43 | * Create a new authentication controller instance. |
| 44 | - * @param SocialAuthService $socialAuthService | 44 | + * @param SocialAuthService $socialAuthService |
| 45 | * @param EmailConfirmationService $emailConfirmationService | 45 | * @param EmailConfirmationService $emailConfirmationService |
| 46 | - * @param UserRepo $userRepo | 46 | + * @param UserRepo $userRepo |
| 47 | */ | 47 | */ |
| 48 | public function __construct(SocialAuthService $socialAuthService, EmailConfirmationService $emailConfirmationService, UserRepo $userRepo) | 48 | public function __construct(SocialAuthService $socialAuthService, EmailConfirmationService $emailConfirmationService, UserRepo $userRepo) |
| 49 | { | 49 | { |
| ... | @@ -63,15 +63,15 @@ class AuthController extends Controller | ... | @@ -63,15 +63,15 @@ class AuthController extends Controller |
| 63 | protected function validator(array $data) | 63 | protected function validator(array $data) |
| 64 | { | 64 | { |
| 65 | return Validator::make($data, [ | 65 | return Validator::make($data, [ |
| 66 | - 'name' => 'required|max:255', | 66 | + 'name' => 'required|max:255', |
| 67 | - 'email' => 'required|email|max:255|unique:users', | 67 | + 'email' => 'required|email|max:255|unique:users', |
| 68 | 'password' => 'required|min:6', | 68 | 'password' => 'required|min:6', |
| 69 | ]); | 69 | ]); |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | protected function checkRegistrationAllowed() | 72 | protected function checkRegistrationAllowed() |
| 73 | { | 73 | { |
| 74 | - if (!\Setting::get('registration-enabled')) { | 74 | + if (!setting('registration-enabled')) { |
| 75 | throw new UserRegistrationException('Registrations are currently disabled.', '/login'); | 75 | throw new UserRegistrationException('Registrations are currently disabled.', '/login'); |
| 76 | } | 76 | } |
| 77 | } | 77 | } |
| ... | @@ -112,7 +112,7 @@ class AuthController extends Controller | ... | @@ -112,7 +112,7 @@ class AuthController extends Controller |
| 112 | /** | 112 | /** |
| 113 | * Overrides the action when a user is authenticated. | 113 | * Overrides the action when a user is authenticated. |
| 114 | * If the user authenticated but does not exist in the user table we create them. | 114 | * If the user authenticated but does not exist in the user table we create them. |
| 115 | - * @param Request $request | 115 | + * @param Request $request |
| 116 | * @param Authenticatable $user | 116 | * @param Authenticatable $user |
| 117 | * @return \Illuminate\Http\RedirectResponse | 117 | * @return \Illuminate\Http\RedirectResponse |
| 118 | */ | 118 | */ |
| ... | @@ -153,8 +153,8 @@ class AuthController extends Controller | ... | @@ -153,8 +153,8 @@ class AuthController extends Controller |
| 153 | 153 | ||
| 154 | // Create an array of the user data to create a new user instance | 154 | // Create an array of the user data to create a new user instance |
| 155 | $userData = [ | 155 | $userData = [ |
| 156 | - 'name' => $socialUser->getName(), | 156 | + 'name' => $socialUser->getName(), |
| 157 | - 'email' => $socialUser->getEmail(), | 157 | + 'email' => $socialUser->getEmail(), |
| 158 | 'password' => str_random(30) | 158 | 'password' => str_random(30) |
| 159 | ]; | 159 | ]; |
| 160 | return $this->registerUser($userData, $socialAccount); | 160 | return $this->registerUser($userData, $socialAccount); |
| ... | @@ -162,7 +162,7 @@ class AuthController extends Controller | ... | @@ -162,7 +162,7 @@ class AuthController extends Controller |
| 162 | 162 | ||
| 163 | /** | 163 | /** |
| 164 | * The registrations flow for all users. | 164 | * The registrations flow for all users. |
| 165 | - * @param array $userData | 165 | + * @param array $userData |
| 166 | * @param bool|false|SocialAccount $socialAccount | 166 | * @param bool|false|SocialAccount $socialAccount |
| 167 | * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | 167 | * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
| 168 | * @throws UserRegistrationException | 168 | * @throws UserRegistrationException |
| ... | @@ -170,8 +170,8 @@ class AuthController extends Controller | ... | @@ -170,8 +170,8 @@ class AuthController extends Controller |
| 170 | */ | 170 | */ |
| 171 | protected function registerUser(array $userData, $socialAccount = false) | 171 | protected function registerUser(array $userData, $socialAccount = false) |
| 172 | { | 172 | { |
| 173 | - if (\Setting::get('registration-restrict')) { | 173 | + if (setting('registration-restrict')) { |
| 174 | - $restrictedEmailDomains = explode(',', str_replace(' ', '', \Setting::get('registration-restrict'))); | 174 | + $restrictedEmailDomains = explode(',', str_replace(' ', '', setting('registration-restrict'))); |
| 175 | $userEmailDomain = $domain = substr(strrchr($userData['email'], "@"), 1); | 175 | $userEmailDomain = $domain = substr(strrchr($userData['email'], "@"), 1); |
| 176 | if (!in_array($userEmailDomain, $restrictedEmailDomains)) { | 176 | if (!in_array($userEmailDomain, $restrictedEmailDomains)) { |
| 177 | throw new UserRegistrationException('That email domain does not have access to this application', '/register'); | 177 | throw new UserRegistrationException('That email domain does not have access to this application', '/register'); |
| ... | @@ -183,7 +183,7 @@ class AuthController extends Controller | ... | @@ -183,7 +183,7 @@ class AuthController extends Controller |
| 183 | $newUser->socialAccounts()->save($socialAccount); | 183 | $newUser->socialAccounts()->save($socialAccount); |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | - if (\Setting::get('registration-confirmation') || \Setting::get('registration-restrict')) { | 186 | + if (setting('registration-confirmation') || setting('registration-restrict')) { |
| 187 | $newUser->email_confirmed = false; | 187 | $newUser->email_confirmed = false; |
| 188 | $newUser->save(); | 188 | $newUser->save(); |
| 189 | $this->emailConfirmationService->sendConfirmation($newUser); | 189 | $this->emailConfirmationService->sendConfirmation($newUser); | ... | ... |
| ... | @@ -39,7 +39,7 @@ class Authenticate | ... | @@ -39,7 +39,7 @@ class Authenticate |
| 39 | return redirect()->guest('/register/confirm/awaiting'); | 39 | return redirect()->guest('/register/confirm/awaiting'); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | - if ($this->auth->guest() && !Setting::get('app-public')) { | 42 | + if ($this->auth->guest() && !setting('app-public')) { |
| 43 | if ($request->ajax()) { | 43 | if ($request->ajax()) { |
| 44 | return response('Unauthorized.', 401); | 44 | return response('Unauthorized.', 401); |
| 45 | } else { | 45 | } else { | ... | ... |
| ... | @@ -124,7 +124,7 @@ class PermissionsRepo | ... | @@ -124,7 +124,7 @@ class PermissionsRepo |
| 124 | // Prevent deleting admin role or default registration role. | 124 | // Prevent deleting admin role or default registration role. |
| 125 | if ($role->name === 'admin') { | 125 | if ($role->name === 'admin') { |
| 126 | throw new PermissionsException('The admin role cannot be deleted'); | 126 | throw new PermissionsException('The admin role cannot be deleted'); |
| 127 | - } else if ($role->id == Setting::get('registration-role')) { | 127 | + } else if ($role->id == setting('registration-role')) { |
| 128 | throw new PermissionsException('This role cannot be deleted while set as the default registration role.'); | 128 | throw new PermissionsException('This role cannot be deleted while set as the default registration role.'); |
| 129 | } | 129 | } |
| 130 | 130 | ... | ... |
| ... | @@ -77,7 +77,7 @@ class UserRepo | ... | @@ -77,7 +77,7 @@ class UserRepo |
| 77 | */ | 77 | */ |
| 78 | public function attachDefaultRole($user) | 78 | public function attachDefaultRole($user) |
| 79 | { | 79 | { |
| 80 | - $roleId = Setting::get('registration-role'); | 80 | + $roleId = setting('registration-role'); |
| 81 | if ($roleId === false) $roleId = $this->role->first()->id; | 81 | if ($roleId === false) $roleId = $this->role->first()->id; |
| 82 | $user->attachRoleId($roleId); | 82 | $user->attachRoleId($roleId); |
| 83 | } | 83 | } | ... | ... |
| ... | @@ -45,7 +45,7 @@ class EmailConfirmationService | ... | @@ -45,7 +45,7 @@ class EmailConfirmationService |
| 45 | 'token' => $token, | 45 | 'token' => $token, |
| 46 | ]); | 46 | ]); |
| 47 | $this->mailer->send('emails/email-confirmation', ['token' => $token], function (Message $message) use ($user) { | 47 | $this->mailer->send('emails/email-confirmation', ['token' => $token], function (Message $message) use ($user) { |
| 48 | - $appName = \Setting::get('app-name', 'BookStack'); | 48 | + $appName = setting('app-name', 'BookStack'); |
| 49 | $message->to($user->email, $user->name)->subject('Confirm your email on ' . $appName . '.'); | 49 | $message->to($user->email, $user->name)->subject('Confirm your email on ' . $appName . '.'); |
| 50 | }); | 50 | }); |
| 51 | } | 51 | } | ... | ... |
| ... | @@ -79,7 +79,7 @@ class ImageService | ... | @@ -79,7 +79,7 @@ class ImageService |
| 79 | private function saveNew($imageName, $imageData, $type) | 79 | private function saveNew($imageName, $imageData, $type) |
| 80 | { | 80 | { |
| 81 | $storage = $this->getStorage(); | 81 | $storage = $this->getStorage(); |
| 82 | - $secureUploads = Setting::get('app-secure-images'); | 82 | + $secureUploads = setting('app-secure-images'); |
| 83 | $imageName = str_replace(' ', '-', $imageName); | 83 | $imageName = str_replace(' ', '-', $imageName); |
| 84 | 84 | ||
| 85 | if ($secureUploads) $imageName = str_random(16) . '-' . $imageName; | 85 | if ($secureUploads) $imageName = str_random(16) . '-' . $imageName; | ... | ... |
| ... | @@ -135,7 +135,7 @@ class SocialAuthService | ... | @@ -135,7 +135,7 @@ class SocialAuthService |
| 135 | 135 | ||
| 136 | // Otherwise let the user know this social account is not used by anyone. | 136 | // Otherwise let the user know this social account is not used by anyone. |
| 137 | $message = 'This ' . $socialDriver . ' account is not linked to any users. Please attach it in your profile settings'; | 137 | $message = 'This ' . $socialDriver . ' account is not linked to any users. Please attach it in your profile settings'; |
| 138 | - if (\Setting::get('registration-enabled')) { | 138 | + if (setting('registration-enabled')) { |
| 139 | $message .= ' or, If you do not yet have an account, You can register an account using the ' . $socialDriver . ' option'; | 139 | $message .= ' or, If you do not yet have an account, You can register an account using the ' . $socialDriver . ' option'; |
| 140 | } | 140 | } |
| 141 | throw new SocialSignInException($message . '.', '/login'); | 141 | throw new SocialSignInException($message . '.', '/login'); | ... | ... |
| ... | @@ -58,4 +58,16 @@ function userCan($permission, \BookStack\Ownable $ownable = null) | ... | @@ -58,4 +58,16 @@ function userCan($permission, \BookStack\Ownable $ownable = null) |
| 58 | $action = end($explodedPermission); | 58 | $action = end($explodedPermission); |
| 59 | $hasAccess = $restrictionService->checkIfEntityRestricted($ownable, $action); | 59 | $hasAccess = $restrictionService->checkIfEntityRestricted($ownable, $action); |
| 60 | return $hasAccess && $hasPermission; | 60 | return $hasAccess && $hasPermission; |
| 61 | -} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 61 | +} | ||
| 62 | + | ||
| 63 | +/** | ||
| 64 | + * Helper to access system settings. | ||
| 65 | + * @param $key | ||
| 66 | + * @param bool $default | ||
| 67 | + * @return mixed | ||
| 68 | + */ | ||
| 69 | +function setting($key, $default = false) | ||
| 70 | +{ | ||
| 71 | + $settingService = app('BookStack\Services\SettingService'); | ||
| 72 | + return $settingService->get($key, $default); | ||
| 73 | +} | ... | ... |
| 1 | <!DOCTYPE html> | 1 | <!DOCTYPE html> |
| 2 | <html> | 2 | <html> |
| 3 | <head> | 3 | <head> |
| 4 | - <title>{{ isset($pageTitle) ? $pageTitle . ' | ' : '' }}{{ Setting::get('app-name', 'BookStack') }}</title> | 4 | + <title>{{ isset($pageTitle) ? $pageTitle . ' | ' : '' }}{{ setting('app-name', 'BookStack') }}</title> |
| 5 | 5 | ||
| 6 | <!-- Meta --> | 6 | <!-- Meta --> |
| 7 | <meta name="viewport" content="width=device-width"> | 7 | <meta name="viewport" content="width=device-width"> |
| ... | @@ -29,10 +29,10 @@ | ... | @@ -29,10 +29,10 @@ |
| 29 | <div class="row"> | 29 | <div class="row"> |
| 30 | <div class="col-lg-4 col-sm-4" ng-non-bindable> | 30 | <div class="col-lg-4 col-sm-4" ng-non-bindable> |
| 31 | <a href="/" class="logo"> | 31 | <a href="/" class="logo"> |
| 32 | - @if(Setting::get('app-logo', '') !== 'none') | 32 | + @if(setting('app-logo', '') !== 'none') |
| 33 | - <img class="logo-image" src="{{ Setting::get('app-logo', '') === '' ? '/logo.png' : Setting::get('app-logo', '') }}" alt="Logo"> | 33 | + <img class="logo-image" src="{{ setting('app-logo', '') === '' ? '/logo.png' : setting('app-logo', '') }}" alt="Logo"> |
| 34 | @endif | 34 | @endif |
| 35 | - <span class="logo-text">{{ Setting::get('app-name', 'BookStack') }}</span> | 35 | + <span class="logo-text">{{ setting('app-name', 'BookStack') }}</span> |
| 36 | </a> | 36 | </a> |
| 37 | </div> | 37 | </div> |
| 38 | <div class="col-lg-4 col-sm-3 text-center"> | 38 | <div class="col-lg-4 col-sm-3 text-center"> | ... | ... |
-
Please register or sign in to post a comment