BaseController::checkRegistrationEnabled()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 4
rs 10
1
<?php
2
/**
3
 * @link      https://dukt.net/social/
4
 * @copyright Copyright (c) Dukt
5
 * @license   https://github.com/dukt/social/blob/v2/LICENSE.md
6
 */
7
8
namespace dukt\social\controllers;
9
10
use craft\web\Controller;
11
use dukt\social\errors\RegistrationException;
12
use dukt\social\Plugin;
13
14
/**
15
 * The LoginAccountsController class is a controller that handles various login account related tasks.
16
 *
17
 * Note that all actions in the controller, except [[actionLogin]], [[actionCallback]], require an authenticated Craft session via [[allowAnonymous]].
18
 *
19
 * @author  Dukt <[email protected]>
20
 * @since   1.0
21
 */
22
abstract class BaseController extends Controller
23
{
24
    // Public Methods
25
    // =========================================================================
26
27
    /**
28
     * Check if social registration is enabled.
29
     *
30
     * @param $settings
31
     *
32
     * @throws RegistrationException
33
     */
34
    public function checkRegistrationEnabled($settings)
35
    {
36
        if (!$settings['enableSocialRegistration']) {
37
            throw new RegistrationException('Social registration is disabled.');
38
        }
39
    }
40
41
    /**
42
     * Check locked domains.
43
     *
44
     * @param $email
45
     *
46
     * @throws RegistrationException
47
     */
48
    public function checkLockedDomains($email)
49
    {
50
        $lockDomains = Plugin::getInstance()->getSettings()->lockDomains;
51
52
        if (is_array($lockDomains) && $lockDomains !== []) {
53
            $domainRejected = true;
54
55
            foreach ($lockDomains as $lockDomain) {
56
                if (strpos($email, '@' . $lockDomain) !== false) {
57
                    $domainRejected = false;
58
                }
59
            }
60
61
            if ($domainRejected) {
62
                throw new RegistrationException('Couldn’t register with this email (domain is not allowed): ' . $email);
63
            }
64
        }
65
    }
66
}
67