]> BookStack Code Mirror - bookstack/commitdiff
Added settings helper and formatted code in some files
authorDan Brown <redacted>
Sun, 6 Mar 2016 12:55:08 +0000 (12:55 +0000)
committerDan Brown <redacted>
Sun, 6 Mar 2016 12:55:08 +0000 (12:55 +0000)
app/Entity.php
app/Http/Controllers/Auth/AuthController.php
app/Http/Middleware/Authenticate.php
app/Repos/PermissionsRepo.php
app/Repos/UserRepo.php
app/Services/EmailConfirmationService.php
app/Services/ImageService.php
app/Services/SocialAuthService.php
app/helpers.php
resources/views/base.blade.php

index 6bf29ca0fbb17b5650a653385edfd01211037441..4f97c6bab255caa63e880a19c187469942666a9c 100644 (file)
@@ -107,7 +107,7 @@ abstract class Entity extends Ownable
         $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 . '"';
@@ -123,7 +123,7 @@ abstract class Entity extends Ownable
 
         // 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);
index fef87d5c87cff3a6759a6b835c0eb496fc29d79d..fda0ee66842547d8819ba673f30a659230b2bcf0 100644 (file)
@@ -41,9 +41,9 @@ class AuthController extends Controller
 
     /**
      * 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)
     {
@@ -63,15 +63,15 @@ class AuthController extends Controller
     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');
         }
     }
@@ -112,7 +112,7 @@ class AuthController extends Controller
     /**
      * 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
      */
@@ -153,8 +153,8 @@ class AuthController extends Controller
 
         // 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);
@@ -162,7 +162,7 @@ class AuthController extends Controller
 
     /**
      * 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
@@ -170,8 +170,8 @@ class AuthController extends Controller
      */
     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');
@@ -183,7 +183,7 @@ class AuthController extends Controller
             $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);
index ad804d0d86b15e16fb6c2bb6a553d7f4b29401ab..81392fe6e94a152faf290271b95554594aa0e18a 100644 (file)
@@ -39,7 +39,7 @@ class Authenticate
             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 {
index 2d497b76a245b0c272014e45aff3f01f2c141019..3c5efde23dfe7ea50491104d56446143d750c91e 100644 (file)
@@ -124,7 +124,7 @@ class PermissionsRepo
         // 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.');
         }
 
index 01cf80d29fcf0322f7847516130d2d9d87798bbe..ec6f3d0d1df920ea0d13392371bc6749c49e8b7b 100644 (file)
@@ -77,7 +77,7 @@ class UserRepo
      */
     public function attachDefaultRole($user)
     {
-        $roleId = Setting::get('registration-role');
+        $roleId = setting('registration-role');
         if ($roleId === false) $roleId = $this->role->first()->id;
         $user->attachRoleId($roleId);
     }
index ffe21eec4d4181d32bfcf20d0564bf8a7d654fe8..c3096c654fb0fb0e1853d6ec5961b8f9df78d07a 100644 (file)
@@ -45,7 +45,7 @@ class EmailConfirmationService
             '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 . '.');
         });
     }
index 47c27cd0a2930f08fedba74127d9c76548d99de0..aefc8a4fb4920d977b02136fc8045555cb902677 100644 (file)
@@ -79,7 +79,7 @@ class ImageService
     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;
index 2437a482706b20dd4db1eebcfef5f512d0e1e013..df213609a5e540d5ffb48003fc3352c6d24a5912 100644 (file)
@@ -135,7 +135,7 @@ class SocialAuthService
 
         // 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');
index ead6b300810130111fc146e6923cdfe86aed4e15..f60e917c55cf5ef3656ea2e75118211dc4f43c53 100644 (file)
@@ -58,4 +58,16 @@ function userCan($permission, \BookStack\Ownable $ownable = null)
     $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);
+}
index 109d373f9e953378b34ea449cf8bad32b388556e..5c744d821fc123a80259aad71059a3a699a43d95 100644 (file)
@@ -1,7 +1,7 @@
 <!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">