Passed
Push — Auth ( e55747...214524 )
by Stone
02:12
created

User::isEmailUnique()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Controllers\Ajax;
4
5
use App\Models\UserModel;
6
use Core\AjaxController;
7
use Core\Container;
8
use Core\Traits\StringFunctions;
9
10
class User  extends AjaxController{
11
12
    use StringFunctions;
0 ignored issues
show
Bug introduced by
The trait Core\Traits\StringFunctions requires the property $childNodes which is not provided by App\Controllers\Ajax\User.
Loading history...
13
14
    private $userModel;
15
16
    public function __construct(Container $container)
17
    {
18
        parent::__construct($container);
19
        $this->userModel = new UserModel($this->container);
20
    }
21
22
    public function isEmailUnique($get)
23
    {
24
        //the router needs a parameter with get functions else throsw a wobbly
25
        //we pass a get variable and call the /controller/function/get?bla
26
        //for better use and security, we must pass "get" as the parameter
27
        if(!$this->startsWith(strtolower($get),"get"))
28
        {
29
            throw new \Exception("invalid call");
30
        }
31
        $email = $this->request->getData("email");
32
        $return =  !$this->userModel->isEmailUsed($email);
33
        echo json_encode($return);
34
35
    }
36
}