Zitadel PHP Client 1.3.6
PHP Client for Zitadel
Loading...
Searching...
No Matches
Password.php
Go to the documentation of this file.
1<?php
2
4
5use Exception;
6
11{
12 private array $settings;
13 private int $userid;
14 private array $request;
15 private string $verifyCode;
16
20 public function __construct(array $settings) {
21 $this->settings = $settings;
22 }
23
28 public function setUserId(int $userid) {
29 $this->userid = $userid;
30 }
31
32 public function setVerifyCode($verifyCode) {
33 $this->request["verificationCode"] = $verifyCode;
34 }
35
36 public function setCurrentPassword($currentPassword) {
37 $this->request["currentPassword"] = $currentPassword;
38 }
39
40 public function setNewPassword($newPassword, $changeRequired) {
41 $this->request["newPassword"] = array(
42 "password" => $newPassword,
43 "changeRequired" => $changeRequired
44 );
45 }
46
47 public function getVerifyCode(): string {
48 return $this->verifyCode;
49 }
50
51 public function change(): bool {
52 $token = $this->settings["serviceUserToken"];
53 $curl = curl_init();
54 curl_setopt_array($curl, array(
55 CURLOPT_URL => $this->settings["domain"] . "/v2beta/users/$this->userid/password",
56 CURLOPT_RETURNTRANSFER => true,
57 CURLOPT_ENCODING => '',
58 CURLOPT_MAXREDIRS => 10,
59 CURLOPT_TIMEOUT => 0,
60 CURLOPT_FOLLOWLOCATION => true,
61 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
62 CURLOPT_CUSTOMREQUEST => 'POST',
63 CURLOPT_POSTFIELDS => json_encode($this->request),
64 CURLOPT_HTTPHEADER => array(
65 "Content-Type: application/json",
66 "Accept: application/json",
67 "Authorization: Bearer $token"
68 ),
69 ));
70
71 $response = json_decode(curl_exec($curl));
72 curl_close($curl);
73 if(isset($response->code)) {
74 return true;
75 }
76 return false;
77 }
78
79 public function requestVerifyCode() {
80 $token = $this->settings["serviceUserToken"];
81 $curl = curl_init();
82 curl_setopt_array($curl, array(
83 CURLOPT_URL => $this->settings["domain"] . "/v2beta/users/$this->userid/password_reset",
84 CURLOPT_RETURNTRANSFER => true,
85 CURLOPT_ENCODING => '',
86 CURLOPT_MAXREDIRS => 10,
87 CURLOPT_TIMEOUT => 0,
88 CURLOPT_FOLLOWLOCATION => true,
89 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
90 CURLOPT_CUSTOMREQUEST => 'POST',
91 CURLOPT_POSTFIELDS => "{
92 \"returnCode\": {}
93 }",
94 CURLOPT_HTTPHEADER => array(
95 "Content-Type: application/json",
96 "Accept: application/json",
97 "Authorization: Bearer $token"
98 ),
99 ));
100
101 $response = json_decode(curl_exec($curl));
102 if(isset($response->code)) {
103 throw new Exception("Error-Code: " . $response->code . " Message: " . $response->message);
104 } else {
105 $this->verifyCode = $response->verificationCode;
106 }
107 curl_close($curl);
108 }
109}
setNewPassword($newPassword, $changeRequired)
Definition Password.php:40
__construct(array $settings)
Definition Password.php:20
setCurrentPassword($currentPassword)
Definition Password.php:36