Passed
Push — master ( b162a4...87a689 )
by Ross
03:05
created

TwoFactorUrls::areWeOnTheVerificationPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
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 getCustomerLogInUrl()
59
    {
60
        return $this->url->getUrl('customer/account/login');
61
    }
62
63
    public function getAdminAuthenticationUrl()
64
    {
65
        return $this->url->getUrl('twofactor/adminlogin/index');
66
    }
67
68
    public function getAdminVerificationUrl()
69
    {
70
        return $this->url->getUrl('twofactor/adminlogin/verify');
71
    }
72
73
74
    public function getCurrentUrl()
75
    {
76
        return $this->url->getCurrentUrl();
77
    }
78
79
    public function areWeOnTheAuthenticationPage($forAdmin = false)
80
    {
81
        $authenticationUrl = $this->getAuthenticationUrl($forAdmin);
82
83
        return $this->compareUrls($this->getCurrentUrl(), $authenticationUrl);
84
    }
85
86
    public function getAuthenticationUrl($forAdmin = false)
87
    {
88
        if ($forAdmin === true) {
89
            return $this->getAdminAuthenticationUrl();
90
        }
91
92
        return $this->getCustomerAuthenticationUrl();
93
    }
94
95
    public function getVerificationUrl($forAdmin = false)
96
    {
97
        if ($forAdmin === true) {
98
            return $this->getAdminVerificationUrl();
99
        }
100
101
        return $this->getCustomerAuthenticationUrl();
102
    }
103
104
    public function areWeOnTheVerificationPage($forAdmin = false)
105
    {
106
        $verificationUrl = $this->getVerificationUrl($forAdmin);
107
108
        return $this->compareUrls($this->getCurrentUrl(), $verificationUrl);
109
    }
110
111
    private function compareUrls($firstUrl, $secondUrl)
112
    {
113
        $charList = '\t\n\r/';
114
115
        return (trim($firstUrl, $charList) === trim($secondUrl, $charList));
116
    }
117
}
118