Conditions | 3 |
Paths | 4 |
Total Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
23 | public function create($nameId, $tokenType, $institution, $identifier = null) |
||
24 | { |
||
25 | $uuid = Uuid::uuid4()->toString(); |
||
26 | |||
27 | // If an identifier is not importand, simply use the UUID, otherwise use the provide one |
||
28 | if (!$identifier) { |
||
29 | $identifier = $uuid; |
||
30 | } |
||
31 | |||
32 | $data = [ |
||
33 | 'identityId' => $uuid, |
||
34 | 'nameId' => $nameId, |
||
35 | 'institution' => $institution, |
||
36 | 'secondFactorId' => $uuid, |
||
37 | 'secondFactorType' => $tokenType, |
||
38 | 'secondFactorIdentifier' => $identifier, |
||
39 | 'id' => $uuid, |
||
40 | 'displayLocale' => 'en_GB', |
||
41 | ]; |
||
42 | $sql = <<<SQL |
||
43 | INSERT INTO second_factor ( |
||
44 | identity_id, |
||
45 | name_id, |
||
46 | institution, |
||
47 | second_factor_id, |
||
48 | second_factor_type, |
||
49 | second_factor_identifier, |
||
50 | id, |
||
51 | display_locale |
||
52 | ) |
||
53 | VALUES ( |
||
54 | :identityId, |
||
55 | :nameId, |
||
56 | :institution, |
||
57 | :secondFactorId, |
||
58 | :secondFactorType, |
||
59 | :secondFactorIdentifier, |
||
60 | :id, |
||
61 | :displayLocale |
||
62 | ) |
||
63 | SQL; |
||
64 | $stmt = $this->connection->prepare($sql); |
||
65 | if ($stmt->execute($data)) { |
||
66 | return $data; |
||
67 | } |
||
68 | |||
69 | throw new Exception('Unable to insert the new second_factor'); |
||
70 | } |
||
71 | } |
||
72 |