v2/route/auth.js   A
last analyzed

Complexity

Total Complexity 8
Complexity/F 1.33

Size

Lines of Code 56
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
eloc 33
mnd 2
bc 2
fnc 6
dl 0
loc 56
ccs 22
cts 22
cp 1
rs 10
bpm 0.3333
cpm 1.3333
noi 2
c 0
b 0
f 0
1 1
const express = require('express');
2 1
const router = express.Router();
3
4 1
const auth = require("../models/auth.js");
5
6 1
router.get('/api_key', (req, res) => {
7 1
    let data = {
8
        message: "",
9
        email: ""
10
    };
11
12 1
    res.render("api_key/form", data);
13
});
14
15 1
router.post('/api_key/confirmation', (req, res) => {
16 13
    if (req.body.gdpr && req.body.gdpr == "gdpr") {
17 11
        return auth.getNewAPIKey(res, req.body.email);
18
    }
19
20 2
    let data = {
21
        message: "Approve the terms and conditions.",
22
        email: req.body.email
23
    };
24
25 2
    res.render("api_key/form", data);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
26
});
27
28 1
router.get('/api_key/deregister', (req, res) => {
29 1
    let data = {
30
        message: "",
31
        email: "",
32
        apikey: ""
33
    };
34
35 1
    res.render("api_key/deregister", data);
36
});
37
38 1
router.post('/api_key/deregister', (req, res) => {
39 6
    if (req.body.email && req.body.apikey &&
40
        req.body.email.length > 0 && req.body.apikey.length > 0) {
41 1
        return auth.deregister(res, req.body);
42
    }
43
44 2
    let data = {
45
        message: "Both E-mail and API-key is needed to deregister.",
46
        email: "",
47
        apikey: ""
48
    };
49
50 2
    res.render("api_key/deregister", data);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
51
});
52
53 7
router.post('/login', (req, res) => auth.login(res, req.body));
54 6
router.post('/register', (req, res) => auth.register(res, req.body));
55
56
module.exports = router;
57