|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sausin\Signere\Http\Controllers\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Sausin\Signere\ApiKey; |
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
use Illuminate\Support\Facades\Config; |
|
8
|
|
|
use Sausin\Signere\Http\Controllers\Controller; |
|
9
|
|
|
|
|
10
|
|
|
class PrimaryKeyRecoveryController extends Controller |
|
11
|
|
|
{ |
|
12
|
|
|
/** @var \Sausin\Signere\ApiKey */ |
|
13
|
|
|
protected $key; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Create a new controller instance. |
|
17
|
|
|
* |
|
18
|
|
|
* @param \Sausin\Signere\ApiKey $key |
|
19
|
|
|
*/ |
|
20
|
3 |
|
public function __construct(ApiKey $key) |
|
21
|
|
|
{ |
|
22
|
3 |
|
parent::__construct(); |
|
23
|
|
|
|
|
24
|
3 |
|
$this->key = $key; |
|
25
|
3 |
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Generates a new primary key and returns it. |
|
29
|
|
|
* |
|
30
|
|
|
* @param Request $request |
|
31
|
|
|
* @return \Illuminate\Http\Response |
|
32
|
|
|
*/ |
|
33
|
1 |
|
public function store(Request $request) |
|
34
|
|
|
{ |
|
35
|
1 |
|
$this->validate($request, ['otp' => 'required|numeric']); |
|
36
|
|
|
|
|
37
|
1 |
|
return $this->key->createPrimary(Config::get('signere.id'), (int) $request->otp) |
|
38
|
1 |
|
->getBody() |
|
39
|
1 |
|
->getContents(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Request new key generation. |
|
44
|
|
|
* |
|
45
|
|
|
* @param Request $request |
|
46
|
|
|
* @return \Illuminate\Http\Response |
|
47
|
|
|
*/ |
|
48
|
2 |
|
public function update(Request $request) |
|
49
|
|
|
{ |
|
50
|
2 |
|
$this->validate($request, [ |
|
51
|
2 |
|
'phone_number' => [ |
|
52
|
|
|
'required', |
|
53
|
|
|
'string', |
|
54
|
|
|
'regex:/^\+47\d{8}$/i', |
|
55
|
|
|
], |
|
56
|
|
|
'message' => [ |
|
57
|
|
|
'string', |
|
58
|
|
|
'nullable', |
|
59
|
|
|
'regex:/\{0\}/i', |
|
60
|
|
|
], |
|
61
|
|
|
]); |
|
62
|
|
|
|
|
63
|
|
|
// create the body |
|
64
|
|
|
$body = [ |
|
65
|
2 |
|
'MobileNumber' => $request->phone_number, |
|
66
|
2 |
|
'ProviderID' => Config::get('signere.id'), |
|
67
|
2 |
|
'SmsMessage' => $request->message, |
|
68
|
|
|
]; |
|
69
|
|
|
|
|
70
|
2 |
|
if (empty($request->message)) { |
|
71
|
1 |
|
unset($body['SmsMessage']); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
2 |
|
return $this->key->recoverPrimary($body) |
|
75
|
2 |
|
->getBody() |
|
76
|
2 |
|
->getContents(); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|