Completed
Branch master (6a6544)
by Pierre-Henry
33:43
created

validate-site/controllers/MainController.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * @author         Pierre-Henry Soria <[email protected]>
4
 * @copyright      (c) 2015-2017, Pierre-Henry Soria. All Rights Reserved.
5
 * @license        GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory.
6
 * @package        PH7 / App / System / Module / Validate Site / Controller
7
 */
8
namespace PH7;
9
10
use
0 ignored issues
show
There must be a single space after the USE keyword
Loading history...
11
PH7\Framework\Layout\Html\Design,
12
PH7\Framework\Mvc\Model\DbConfig,
13
PH7\Framework\Cache\Cache,
14
PH7\Framework\Url\Header;
15
16
class MainController extends Controller
17
{
18
    private $oValidateModel;
19
20
    public function __construct()
21
    {
22
        parent::__construct();
23
24
        $this->oValidateModel = new ValidateSiteModel;
25
    }
26
27
    public function validationBox()
28
    {
29
        // Display the form box only if the site isn't validated yet
30
        if (!$this->oValidateModel->is()) {
31
            $this->session->set(ValidateSiteCore::SESS_IS_VISITED, 1);
32
            $this->view->page_title = t('Validate your Site');
33
            $this->output();
0 ignored issues
show
The method output() does not seem to exist on object<PH7\MainController>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
        } else {
35
            $this->displayPageNotFound(t('Whoops! It appears the site has already been activated.'));
36
        }
37
    }
38
39
    public function pending()
40
    {
41
        $this->view->page_title = t('Pending Status: Please confirm your site');
42
        $this->view->h1_title = t('We sent an email. Please confirm your Site');
43
        $this->output();
0 ignored issues
show
The method output() does not seem to exist on object<PH7\MainController>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
    }
45
46
    public function validator($sHash = null)
47
    {
48
        if ($this->oValidateModel->is()) {
49
            Header::redirect(
50
                PH7_ADMIN_MOD,
51
                t('Your site is already validated!'),
52
                Design::SUCCESS_TYPE
53
            );
54
        } elseif (!empty($sHash) && $this->checkHash($sHash)) {
55
            // Set the site to "validated" status
56
            $this->oValidateModel->set();
57
58
            DbConfig::clearCache();
59
60
            Header::redirect(
61
                PH7_ADMIN_MOD,
62
                t('Congrats! Your site has now the Published status and you will be aware by email to any security patches or updates.'),
63
                Design::SUCCESS_TYPE
64
            );
65
        } else {
66
            Header::redirect(
67
                PH7_ADMIN_MOD,
68
                t('The hash is incorrect. Please copy/paste the hash link received in your email in Web browser URL bar.'),
69
                Design::ERROR_TYPE
70
            );
71
        }
72
    }
73
74
    protected function checkHash($sHash)
75
    {
76
        return ('681cd81b17b71c746e9ab7ac0445d3a3c960c329' === sha1(substr($sHash,3,24)));
77
    }
78
}
79