Completed
Push — master ( 1107dd...e5e0f9 )
by Craig
07:21 queued 01:34
created

NativeEitherAuthenticationMethod::getDisplayName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
/*
4
 * This file is part of the Zikula package.
5
 *
6
 * Copyright Zikula Foundation - http://zikula.org/
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zikula\ZAuthModule\AuthenticationMethod;
13
14
use Zikula\ZAuthModule\Form\Type\EitherLoginType;
15
use Zikula\ZAuthModule\ZAuthConstant;
16
17
class NativeEitherAuthenticationMethod extends AbstractNativeAuthenticationMethod
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function getAlias()
23
    {
24
        return ZAuthConstant::AUTHENTICATION_METHOD_EITHER;
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function getDisplayName()
31
    {
32
        return $this->translator->__('Native Uname or Email');
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function getDescription()
39
    {
40
        return $this->translator->__('Allow a user to authenticate and login via Zikula\'s native user database with their username or email address.');
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getLoginFormClassName()
47
    {
48
        return EitherLoginType::class;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function getLoginTemplateName($type = 'page', $position = 'left')
55
    {
56
        if ($type == 'block') {
57
            if ($position == 'topnav') {
58
                return 'ZikulaZAuthModule:Authentication:EitherLoginBlock.topnav.html.twig';
59
            }
60
61
            return 'ZikulaZAuthModule:Authentication:EitherLoginBlock.html.twig';
62
        }
63
64
        return 'ZikulaZAuthModule:Authentication:EitherLogin.html.twig';
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function authenticate(array $data = [])
71
    {
72
        $field = filter_var($data['either'], FILTER_VALIDATE_EMAIL) ? 'email' : 'uname';
73
        $data[$field] = $data['either'];
74
75
        return $this->authenticateByField($data, $field);
76
    }
77
}
78