1
<?php
2
/**
3
 * This file is part of the Shieldon package.
4
 *
5
 * (c) Terry L. <contact@terryl.in>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 * 
10
 * php version 7.1.0
11
 * 
12
 * @category  Web-security
13
 * @package   Shieldon
14
 * @author    Terry Lin <contact@terryl.in>
15
 * @copyright 2019 terrylinooo
16
 * @license   https://github.com/terrylinooo/shieldon/blob/2.x/LICENSE MIT
17
 * @link      https://github.com/terrylinooo/shieldon
18
 * @see       https://shieldon.io
19
 */
20

21
declare(strict_types=1);
22

23
namespace Shieldon\Firewall\Panel;
24

25
use Shieldon\Firewall\Container;
26

27
/*
28
 * Tradit for demonstration.
29
 */
30
trait DemoModeTrait
31
{
32
    /**
33
     *   Public methods       | Desctiotion
34
     *  ----------------------|---------------------------------------------
35
     *   demo                 | Start a demo mode. Setting fields are hidden.
36
     *  ----------------------|---------------------------------------------
37
     */
38

39
    /**
40
     * The mode of the firewall control panel.
41
     * self: Shieldon | managed: Firewall | demo: Demo
42
     *
43
     * @var string
44
     */
45
    protected $mode = 'self';
46

47
    /**
48
     * Login as a demo user.
49
     *
50
     * @var array
51
     */
52
    protected $demoUser = [
53
        'user' => 'demo',
54
        'pass' => 'demo',
55
    ];
56

57
    /**
58
     * Mark as demo.
59
     *
60
     * @var string
61
     */
62
    protected $markAsDemo = '';
63

64
    /**
65
     * In demo mode, user's submit will not take effect.
66
     *
67
     * @param string $user The user name.
68
     * @param string $pass The user password.
69
     *
70
     * @return void
71
     */
72 3
    public function demo(string $user = '', string $pass = ''): void
73
    {
74 3
        $this->demoUser['user'] = $user ?: 'demo';
75 3
        $this->demoUser['pass'] = $pass ?: 'demo';
76

77 3
        $this->mode = 'demo';
78 3
        $this->markAsDemo = ' (DEMO)';
79

80 3
        Container::get('shieldon')->managedBy('demo');
81
    }
82
}

Read our documentation on viewing source code .

Loading