Passed
Push — master ( e0ed8e...0d3aa7 )
by Nils
11:00
created

AuthController::verifyToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
/**
3
 * Teampass - a collaborative passwords manager.
4
 * ---
5
 * This library is distributed in the hope that it will be useful,
6
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8
 * ---
9
 *
10
 * @project   Teampass API
11
 *
12
 * @file      AuthControler.php
13
 * ---
14
 *
15
 * @author    Nils Laumaillé ([email protected])
16
 *
17
 * @copyright 2009-2022 Teampass.net
18
 *
19
 * @license   https://spdx.org/licenses/GPL-3.0-only.html#licenseText GPL-3.0
20
 * ---
21
 *
22
 * @see       https://www.teampass.net
23
 */
24
class AuthController extends BaseController
25
{
26
    /**
27
     * 
28
     */
29
    public function authorizeAction()
30
    {
31
        $strErrorDesc = '';
32
        $responseData = '';
33
        $requestMethod = $_SERVER["REQUEST_METHOD"];
34
        $arrQueryStringParams = $this->getQueryStringParams();
35
36
        if (strtoupper($requestMethod) === 'POST') {
37
            // Get data
38
            $data = json_decode(file_get_contents("php://input"));
39
            $login = $data->login;
40
            $password = $data->password;
41
            $apikey = $data->apikey;
42
43
            require PROJECT_ROOT_PATH . "/Model/AuthModel.php";
44
            try {
45
                $authModel = new AuthModel();
46
                $arrUser = $authModel->getUserAuth($login, $password, $apikey);
47
                $responseData = json_encode($arrUser);
48
            } catch (Error $e) {
49
                $strErrorDesc = $e->getMessage().' Something went wrong! Please contact support.';
50
                $strErrorHeader = 'HTTP/1.1 500 Internal Server Error';
51
            }
52
            
53
        } else {
54
            $strErrorDesc = 'Method '.$requestMethod.' not supported';
55
            $strErrorHeader = 'HTTP/1.1 422 Unprocessable Entity';
56
        }
57
58
        // send output
59
        if (!$strErrorDesc) {
60
            $this->sendOutput(
61
                $responseData,
62
                array('Content-Type: application/json', 'HTTP/1.1 200 OK')
63
            );
64
        } else {
65
            $this->sendOutput(json_encode(array('error' => $strErrorDesc)), 
66
                array('Content-Type: application/json', $strErrorHeader)
67
            );
68
        }
69
    }
70
}