Passed
Push — master ( 64a1db...f9577e )
by Ross
02:54
created

TwoFactorUrls::getAdminAuthenticationUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * A two factor authentication module that protects both the admin and customer logins
4
 * Copyright (C) 2017  Ross Mitchell
5
 *
6
 * This file is part of Rossmitchell/Twofactor.
7
 *
8
 * Rossmitchell/Twofactor is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
namespace Rossmitchell\Twofactor\Model;
23
24
use Magento\Framework\UrlInterface;
25
26
class TwoFactorUrls
27
{
28
    /**
29
     * @var UrlInterface
30
     */
31
    private $url;
32
33
    /**
34
     * TwoFactorUrls constructor.
35
     *
36
     * @param UrlInterface $url
37
     */
38
    public function __construct(UrlInterface $url)
39
    {
40
        $this->url = $url;
41
    }
42
43
    public function getCustomerAuthenticationUrl()
44
    {
45
        return $this->url->getUrl('twofactor/customerlogin/index');
46
    }
47
48
    public function getCustomerVerificationUrl()
49
    {
50
        return $this->url->getUrl('twofactor/customerlogin/verify');
51
    }
52
53
    public function getCustomerAccountUrl()
54
    {
55
        return $this->url->getUrl('customer/account/index');
56
    }
57
58
    public function getAdminDashboardUrl()
59
    {
60
        return $this->url->getUrl('admin/dashboard/index');
61
    }
62
63
    public function getCustomerLogInUrl()
64
    {
65
        return $this->url->getUrl('customer/account/login');
66
    }
67
68
    public function getAdminAuthenticationUrl()
69
    {
70
        return $this->url->getUrl('twofactor/adminlogin/index');
71
    }
72
73
    public function getAdminVerificationUrl()
74
    {
75
        return $this->url->getUrl('twofactor/adminlogin/verify');
76
    }
77
78
79
    public function getCurrentUrl()
80
    {
81
        return $this->url->getCurrentUrl();
82
    }
83
84
    public function areWeOnTheAuthenticationPage($forAdmin = false)
85
    {
86
        $authenticationUrl = $this->getAuthenticationUrl($forAdmin);
87
88
        return $this->compareUrls($this->getCurrentUrl(), $authenticationUrl);
89
    }
90
91
    public function getAuthenticationUrl($forAdmin = false)
92
    {
93
        if ($forAdmin === true) {
94
            return $this->getAdminAuthenticationUrl();
95
        }
96
97
        return $this->getCustomerAuthenticationUrl();
98
    }
99
100
    public function getVerificationUrl($forAdmin = false)
101
    {
102
        if ($forAdmin === true) {
103
            return $this->getAdminVerificationUrl();
104
        }
105
106
        return $this->getCustomerAuthenticationUrl();
107
    }
108
109
    public function areWeOnTheVerificationPage($forAdmin = false)
110
    {
111
        $verificationUrl = $this->getVerificationUrl($forAdmin);
112
113
        return $this->compareUrls($this->getCurrentUrl(), $verificationUrl);
114
    }
115
116
    private function compareUrls($firstUrl, $secondUrl)
117
    {
118
        $charList = '\t\n\r/';
119
120
        return (trim($firstUrl, $charList) === trim($secondUrl, $charList));
121
    }
122
}
123