Zitadel PHP Client 1.3.6 PHP Client for Zitadel

Loading...
Searching...
No Matches
Email.php
Go to the documentation of this file.
1<?php
2
3 namespace ZitadelPhpClient\User;
4
5use Exception;
6
10 class Email
11{
12 private array $settings;
13 private int $userid;
14 private string $returnedVerificationCode;
15
19 public function __construct(array $settings) {
20 $this->settings = $settings;
21 }
22
27 public function setUserId(int $userid) {
28 $this->userid = $userid;
29 }
30
34 public function getVerificationCode(): string
35 {
36 return $this->returnedVerificationCode;
37 }
38
44 public function changeEmail(string $email) {
45 $token = $this->settings["serviceUserToken"];
46
47 $curl = curl_init();
48 curl_setopt_array($curl, array(
49 CURLOPT_URL => $this->settings["domain"] . "/v2beta/users/$this->userid/email",
50 CURLOPT_RETURNTRANSFER => true,
51 CURLOPT_ENCODING => '',
52 CURLOPT_MAXREDIRS => 10,
53 CURLOPT_TIMEOUT => 0,
54 CURLOPT_FOLLOWLOCATION => true,
55 CURLOPT_CUSTOMREQUEST => 'POST',
56 CURLOPT_POSTFIELDS => "{
57 \"email\": \"$email\",
58 \"returnCode\": {}
59 }",
60 CURLOPT_HTTPHEADER => array(
61 "Content-Type: application/json",
62 "Accept: application/json",
63 "Authorization: Bearer $token"
64 ),
65 ));
66
67 $response = json_decode(curl_exec($curl));
68 curl_close($curl);
69 if(isset($response->code)) {
70 throw new Exception("Error-Code: " . $response->code . " Message: " . $response->message);
71 } else {
72 $this->returnedVerificationCode = $response->verificationCode;
73 }
74 }
75
80 public function resendVerificationCode() {
81 $curl = curl_init();
82 $token = $this->settings["serviceUserToken"];
83 curl_setopt_array($curl, array(
84 CURLOPT_URL => $this->settings["domain"] . "/v2beta/users/$this->userid/email/resend",
85 CURLOPT_RETURNTRANSFER => true,
86 CURLOPT_ENCODING => '',
87 CURLOPT_MAXREDIRS => 10,
88 CURLOPT_TIMEOUT => 0,
89 CURLOPT_FOLLOWLOCATION => true,
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->returnedVerificationCode = $response->verificationCode;
106 }
107 curl_close($curl);
108 }
109
114 public function verify(string $verifyCode): bool {
115 $token = $this->settings["serviceUserToken"];
116 $curl = curl_init();
117
118 curl_setopt_array($curl, array(
119 CURLOPT_URL => $this->settings["domain"] . "/v2beta/users/$this->userid/email/verify",
120 CURLOPT_RETURNTRANSFER => true,
121 CURLOPT_ENCODING => '',
122 CURLOPT_MAXREDIRS => 10,
123 CURLOPT_TIMEOUT => 0,
124 CURLOPT_FOLLOWLOCATION => true,
125 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
126 CURLOPT_CUSTOMREQUEST => 'POST',
127 CURLOPT_POSTFIELDS =>"{
128 \"verificationCode\": \"$verifyCode\"
129 }",
130 CURLOPT_HTTPHEADER => array(
131 "Content-Type: application/json",
132 "Accept: application/json",
133 "Authorization: Bearer $token"
134 ),
135 ));
136
137 $response = curl_exec($curl);
138 curl_close($curl);
139 if(isset($response->code)) {
140 return false;
141 }
142 return true;
143 }
144}
ZitadelPhpClient\User\Email
Definition Email.php:11
ZitadelPhpClient\User\Email\verify
verify(string $verifyCode)
Definition Email.php:114
ZitadelPhpClient\User\Email\setUserId
setUserId(int $userid)
Definition Email.php:27
ZitadelPhpClient\User\Email\changeEmail
changeEmail(string $email)
Definition Email.php:44
ZitadelPhpClient\User\Email\getVerificationCode
getVerificationCode()
Definition Email.php:34
ZitadelPhpClient\User\Email\resendVerificationCode
resendVerificationCode()
Definition Email.php:80
ZitadelPhpClient\User\Email\__construct
__construct(array $settings)
Definition Email.php:19
ZitadelPhpClient\User
Definition Account.php:3