$exactTerms = [];
foreach ($terms as $key => $term) {
$term = htmlentities($term, ENT_QUOTES);
- $term = preg_replace('/[+\-><\(\)~*\"@]+/', ' ', $term);
+ $term = preg_replace('/[+\-><\(\)~*\"@]+/', ' ', $term);
if (preg_match('/\s/', $term)) {
$exactTerms[] = '%' . $term . '%';
$term = '"' . $term . '"';
// Ensure at least one exact term matches if in search
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 ($fieldsToSearch as $field) {
$query->orWhere($field, 'like', $exactTerm);
/**
* Create a new authentication controller instance.
- * @param SocialAuthService $socialAuthService
+ * @param SocialAuthService $socialAuthService
* @param EmailConfirmationService $emailConfirmationService
- * @param UserRepo $userRepo
+ * @param UserRepo $userRepo
*/
public function __construct(SocialAuthService $socialAuthService, EmailConfirmationService $emailConfirmationService, UserRepo $userRepo)
{
protected function validator(array $data)
{
return Validator::make($data, [
- 'name' => 'required|max:255',
- 'email' => 'required|email|max:255|unique:users',
+ 'name' => 'required|max:255',
+ 'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6',
]);
}
protected function checkRegistrationAllowed()
{
- if (!\Setting::get('registration-enabled')) {
+ if (!setting('registration-enabled')) {
throw new UserRegistrationException('Registrations are currently disabled.', '/login');
}
}
/**
* Overrides the action when a user is authenticated.
* If the user authenticated but does not exist in the user table we create them.
- * @param Request $request
+ * @param Request $request
* @param Authenticatable $user
* @return \Illuminate\Http\RedirectResponse
*/
// Create an array of the user data to create a new user instance
$userData = [
- 'name' => $socialUser->getName(),
- 'email' => $socialUser->getEmail(),
+ 'name' => $socialUser->getName(),
+ 'email' => $socialUser->getEmail(),
'password' => str_random(30)
];
return $this->registerUser($userData, $socialAccount);
/**
* The registrations flow for all users.
- * @param array $userData
+ * @param array $userData
* @param bool|false|SocialAccount $socialAccount
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @throws UserRegistrationException
*/
protected function registerUser(array $userData, $socialAccount = false)
{
- if (\Setting::get('registration-restrict')) {
- $restrictedEmailDomains = explode(',', str_replace(' ', '', \Setting::get('registration-restrict')));
+ if (setting('registration-restrict')) {
+ $restrictedEmailDomains = explode(',', str_replace(' ', '', setting('registration-restrict')));
$userEmailDomain = $domain = substr(strrchr($userData['email'], "@"), 1);
if (!in_array($userEmailDomain, $restrictedEmailDomains)) {
throw new UserRegistrationException('That email domain does not have access to this application', '/register');
$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->save();
$this->emailConfirmationService->sendConfirmation($newUser);
return redirect()->guest('/register/confirm/awaiting');
}
- if ($this->auth->guest() && !Setting::get('app-public')) {
+ if ($this->auth->guest() && !setting('app-public')) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
// Prevent deleting admin role or default registration role.
if ($role->name === 'admin') {
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.');
}
*/
public function attachDefaultRole($user)
{
- $roleId = Setting::get('registration-role');
+ $roleId = setting('registration-role');
if ($roleId === false) $roleId = $this->role->first()->id;
$user->attachRoleId($roleId);
}
'token' => $token,
]);
$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 . '.');
});
}
private function saveNew($imageName, $imageData, $type)
{
$storage = $this->getStorage();
- $secureUploads = Setting::get('app-secure-images');
+ $secureUploads = setting('app-secure-images');
$imageName = str_replace(' ', '-', $imageName);
if ($secureUploads) $imageName = str_random(16) . '-' . $imageName;
// 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';
- 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';
}
throw new SocialSignInException($message . '.', '/login');
$action = end($explodedPermission);
$hasAccess = $restrictionService->checkIfEntityRestricted($ownable, $action);
return $hasAccess && $hasPermission;
-}
\ No newline at end of file
+}
+
+/**
+ * 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);
+}
<!DOCTYPE html>
<html>
<head>
- <title>{{ isset($pageTitle) ? $pageTitle . ' | ' : '' }}{{ Setting::get('app-name', 'BookStack') }}</title>
+ <title>{{ isset($pageTitle) ? $pageTitle . ' | ' : '' }}{{ setting('app-name', 'BookStack') }}</title>
<!-- Meta -->
<meta name="viewport" content="width=device-width">
<div class="row">
<div class="col-lg-4 col-sm-4" ng-non-bindable>
<a href="/" class="logo">
- @if(Setting::get('app-logo', '') !== 'none')
- <img class="logo-image" src="{{ Setting::get('app-logo', '') === '' ? '/logo.png' : Setting::get('app-logo', '') }}" alt="Logo">
+ @if(setting('app-logo', '') !== 'none')
+ <img class="logo-image" src="{{ setting('app-logo', '') === '' ? '/logo.png' : setting('app-logo', '') }}" alt="Logo">
@endif
- <span class="logo-text">{{ Setting::get('app-name', 'BookStack') }}</span>
+ <span class="logo-text">{{ setting('app-name', 'BookStack') }}</span>
</a>
</div>
<div class="col-lg-4 col-sm-3 text-center">