Browse Source

New configuration file

tags/v1.4.4
Simon Vieille 2 years ago
parent
commit
48eacc5cb8

+ 5
- 0
app/bootstrap.php.d/10-config.php View File

@@ -1,9 +1,14 @@
1 1
 <?php
2 2
 
3 3
 use Symfony\Component\Config\FileLocator;
4
+use Symfony\Component\Yaml\Yaml;
4 5
 
5 6
 $app['config.locator.path'] = $app['root_path'].'/app/config/';
6 7
 
7 8
 $app['config.locator'] = function ($app) {
8 9
     return new FileLocator($app['config.locator.path']);
9 10
 };
11
+
12
+$app['settings'] = $app->share(function ($app) {
13
+    return Yaml::parse($app['config.locator']->locate('config.yml'));
14
+});

+ 8
- 2
app/bootstrap.php.d/50-git.php View File

@@ -3,10 +3,16 @@
3 3
 use GitWrapper\GitWrapper;
4 4
 use Gist\Service\Gist;
5 5
 
6
-$app['gist_path'] = $app['root_path'].'/data/git';
6
+$dataPath = $app['settings']['data']['path'];
7
+
8
+if ($dataPath[0] !== '/') {
9
+    $app['gist_path'] = $app['root_path'].$dataPath;
10
+} else {
11
+    $app['gist_path'] = $dataPath;
12
+}
7 13
 
8 14
 $app['git_wrapper'] = $app->share(function ($app) {
9
-    return new GitWrapper('/usr/bin/git');
15
+    return new GitWrapper($app['settings']['git']['path']);
10 16
 });
11 17
 
12 18
 $app['git_working_copy'] = $app->share(function ($app) {

+ 1
- 1
app/bootstrap.php.d/60-api.php View File

@@ -3,5 +3,5 @@
3 3
 use Gist\Api\Client;
4 4
 
5 5
 $app['api_client'] = $app->share(function ($app) {
6
-    return new Client(['base_uri' => 'https://gist.deblan.org/']);
6
+    return new Client(['base_uri' => $app['settings']['api']['base_uri']]);
7 7
 });

+ 6
- 10
app/bootstrap.php.d/70-security.php View File

@@ -9,13 +9,9 @@ use Gist\Security\AuthenticationListener;
9 9
 use Gist\Security\LogoutSuccessHandler;
10 10
 use Silex\Provider\SessionServiceProvider;
11 11
 
12
-$app['enable_registration'] = true;
13
-$app['enable_login'] = true;
14
-$app['login_required_to_edit_gist'] = false;
15
-$app['login_required_to_view_gist'] = false;
16
-$app['login_required_to_view_embeded_gist'] = false;
12
+$securitySettings = $app['settings']['security'];
17 13
 
18
-$app['token'] = 'ThisTokenIsNotSoSecretChangeIt';
14
+$app['token'] = $securitySettings['token'];
19 15
 
20 16
 $app['salt_generator'] = $app->share(function ($app) {
21 17
     return new SaltGenerator();
@@ -77,10 +73,10 @@ $firewall = [
77 73
     ],
78 74
 ];
79 75
 
80
-if ($app['login_required_to_edit_gist'] || $app['login_required_to_view_gist'] || $app['login_required_to_view_embeded_gist']) {
76
+if ($securitySettings['login_required_to_edit_gist'] || $securitySettings['login_required_to_view_gist'] || $securitySettings['login_required_to_view_embeded_gist']) {
81 77
     $exceptedUriPattern = ['login', 'register'];
82 78
 
83
-    if ($app['login_required_to_view_gist'] === true) {
79
+    if ($securitySettings['login_required_to_view_gist'] === true) {
84 80
         $firewall['security.access_rules'][] = ['^/[a-z]{2}/view.*$', 'ROLE_USER'];
85 81
         $firewall['security.access_rules'][] = ['^/[a-z]{2}/revs.*$', 'ROLE_USER'];
86 82
     } else {
@@ -88,13 +84,13 @@ if ($app['login_required_to_edit_gist'] || $app['login_required_to_view_gist'] |
88 84
         $exceptedUriPattern[] = 'revs';
89 85
     }
90 86
 
91
-    if ($app['login_required_to_view_embeded_gist'] === true) {
87
+    if ($securitySettings['login_required_to_view_embeded_gist'] === true) {
92 88
         $firewall['security.access_rules'][] = ['^/[a-z]{2}/embed.*$', 'ROLE_USER'];
93 89
     } else {
94 90
         $exceptedUriPattern[] = 'embed';
95 91
     }
96 92
 
97
-    if ($app['login_required_to_edit_gist'] === true) {
93
+    if ($securitySettings['login_required_to_edit_gist'] === true) {
98 94
         $firewall['security.access_rules'][] = ['^/[a-z]{2}/(?!('.implode('|', $exceptedUriPattern).')).*$', 'ROLE_USER'];
99 95
     }
100 96
 }

+ 15
- 0
app/config/config.yml.dist View File

@@ -0,0 +1,15 @@
1
+security:
2
+    token: ThisTokenIsNotSoSecretChangeIt
3
+    enable_registration: true
4
+    enable_login: true
5
+    login_required_to_edit_gist: true
6
+    login_required_to_view_gist: true
7
+    login_required_to_view_embeded_gist: true
8
+api:
9
+    base_url: 'https://gist.deblan.org/'
10
+data:
11
+    path: data/git
12
+git:
13
+    path: /usr/bin/git
14
+theme:
15
+    name: dark

+ 2
- 2
src/Gist/Controller/LoginController.php View File

@@ -26,7 +26,7 @@ class LoginController extends Controller
26 26
     {
27 27
         $app = $this->getApp();
28 28
 
29
-        if (false === $app['enable_registration']) {
29
+        if (false === $app['settings']['enable_registration']) {
30 30
             return new Response('', 403);
31 31
         }
32 32
 
@@ -78,7 +78,7 @@ class LoginController extends Controller
78 78
     {
79 79
         $app = $this->getApp();
80 80
 
81
-        if (false === $app['enable_login']) {
81
+        if (false === $app['settings']['enable_login']) {
82 82
             return new Response('', 403);
83 83
         }
84 84
 

+ 13
- 5
src/Gist/Resources/views/base.html.twig View File

@@ -1,11 +1,19 @@
1 1
 <!DOCTYPE html>
2
+{% set theme_settings = app.settings.theme %}
3
+{% set security_dettings = app.settings.security %}
2 4
 <html xmlns="http://www.w3.org/1999/xhtml">
3 5
     <head>
4 6
         {% block css %}
5 7
             <link rel="stylesheet" href="{{ web_path }}components/bootstrap/dist/css/bootstrap.min.css" />
6 8
             <link rel="stylesheet" href="{{ web_path }}components/flag-icon-css/css/flag-icon.min.css" />
7
-            <link rel="stylesheet" href="{{ web_path }}app/css/bootstrap/bootstrap.min.css" />
8
-            <link rel="stylesheet" href="{{ web_path }}app/css/app.css" />
9
+
10
+            {% if theme_settings.name == 'dark' %}
11
+                <link rel="stylesheet" href="{{ web_path }}app/css/bootstrap/bootstrap.min.css" />
12
+            {% else %}
13
+                <link rel="stylesheet" href="{{ web_path }}components/bootstrap/dist/css/bootstrap-theme.min.css" />
14
+            {% endif %}
15
+
16
+            <link rel="stylesheet" href="{{ web_path }}app/css/themes/{{ theme_settings.name }}.css" />
9 17
         {% endblock %}
10 18
 
11 19
         {% block metas %}
@@ -17,7 +25,7 @@
17 25
     </head>
18 26
     <body>
19 27
         {% block nav %}
20
-            <nav class="navbar navbar-inverse">
28
+            <nav class="navbar navbar-{{ theme_settings.name == 'dark' ? 'inverse' : 'default' }}">
21 29
                 <div class="container-fluid">
22 30
                     <div class="navbar-header">
23 31
                         <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu">
@@ -48,14 +56,14 @@
48 56
                                         {{ 'app.menu.my.logout.title'|trans }}
49 57
                                     </a>
50 58
                                 </li>
51
-                            {% elseif app.enable_login %}
59
+                            {% elseif security_dettings.enable_login %}
52 60
                                 <li>
53 61
                                     <a href="{{ path('login') }}">
54 62
                                         {{ 'app.menu.my.login.title'|trans }}
55 63
                                     </a>
56 64
                                 </li>
57 65
 
58
-                                {% if app.enable_registration %}
66
+                                {% if security_dettings.enable_registration %}
59 67
                                     <li>
60 68
                                         <a href="{{ path('register') }}">
61 69
                                             {{ 'app.menu.my.register.title'|trans }}

Loading…
Cancel
Save