1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cloudflare; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* CloudFlare API wrapper |
7
|
|
|
* |
8
|
|
|
* User |
9
|
|
|
* The currently logged in/authenticated User |
10
|
|
|
* |
11
|
|
|
* @author James Bell <[email protected]> |
12
|
|
|
* |
13
|
|
|
* @version 1 |
14
|
|
|
*/ |
15
|
|
|
class User extends Api |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* User details |
19
|
|
|
*/ |
20
|
|
|
public function user() |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
return $this->get('user'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Update user |
27
|
|
|
* Update part of your user details |
28
|
|
|
* |
29
|
|
|
* @param string|null $first_name User's first name |
30
|
|
|
* @param string|null $last_name User's last name |
31
|
|
|
* @param string|null $telephone User's telephone number |
32
|
|
|
* @param string|null $country The country in which the user lives. (Full list is here: http://en.wikipedia.org/wiki/List_of_country_calling_codes) |
33
|
|
|
* @param string|null $zipcode The zipcode or postal code where the user lives. |
34
|
|
|
*/ |
35
|
|
|
public function update($first_name = null, $last_name = null, $telephone = null, $country = null, $zipcode = null) |
36
|
|
|
{ |
37
|
|
|
$data = [ |
38
|
|
|
'first_name' => $first_name, |
39
|
|
|
'last_name' => $last_name, |
40
|
|
|
'telephone' => $telephone, |
41
|
|
|
'country' => $country, |
42
|
|
|
'zipcode' => $zipcode, |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
return $this->patch('user', $data); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Change your email address. Note: You must provide your current password. |
50
|
|
|
* |
51
|
|
|
* @param string $email Your contact email address |
52
|
|
|
* @param string $confirm_email Your contact email address, repeated |
53
|
|
|
* @param string $password Your current password |
54
|
|
|
*/ |
55
|
|
|
public function change_email($email, $confirm_email, $password) |
56
|
|
|
{ |
57
|
|
|
$data = [ |
58
|
|
|
'email' => $email, |
59
|
|
|
'confirm_email' => $confirm_email, |
60
|
|
|
'password' => $password, |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
return $this->put('user/email', $data); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Change your password |
68
|
|
|
* |
69
|
|
|
* @param string $old_password Your current password |
70
|
|
|
* @param string $new_password Your new password |
71
|
|
|
* @param string $new_password_confirm Your new password, repeated |
72
|
|
|
*/ |
73
|
|
|
public function change_password($old_password, $new_password, $new_password_confirm) |
74
|
|
|
{ |
75
|
|
|
$data = [ |
76
|
|
|
'old_password' => $old_password, |
77
|
|
|
'new_password' => $new_password, |
78
|
|
|
'new_password_confirm' => $new_password_confirm, |
79
|
|
|
]; |
80
|
|
|
|
81
|
|
|
return $this->put('user/password', $data); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Change your username. Note: You must provide your current password. |
86
|
|
|
* |
87
|
|
|
* @param string $username A username used to access other cloudflare services, like support |
88
|
|
|
* @param string $password Your current password |
89
|
|
|
*/ |
90
|
|
|
public function change_username($username, $password) |
91
|
|
|
{ |
92
|
|
|
$data = [ |
93
|
|
|
'username' => $username, |
94
|
|
|
'password' => $password, |
95
|
|
|
]; |
96
|
|
|
|
97
|
|
|
return $this->put('user/username', $data); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Begin setting up CloudFlare two-factor authentication with a given telephone number |
102
|
|
|
* |
103
|
|
|
* @param int $country_code The country code of your mobile phone number |
104
|
|
|
* @param string $mobile_phone_number Your mobile phone number |
105
|
|
|
* @param string $current_password Your current CloudFlare password |
106
|
|
|
*/ |
107
|
|
|
public function initialize_two_factor_authentication($country_code, $mobile_phone_number, $current_password) |
108
|
|
|
{ |
109
|
|
|
$data = [ |
110
|
|
|
'country_code' => $country_code, |
111
|
|
|
'mobile_phone_number' => $mobile_phone_number, |
112
|
|
|
'current_password' => $current_password, |
113
|
|
|
]; |
114
|
|
|
|
115
|
|
|
return $this->post('/user/two_factor_authentication', $data); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Finish setting up CloudFlare two-factor authentication with a given telephone number |
120
|
|
|
* |
121
|
|
|
* @param int $auth_token The token provided by the two-factor authenticator |
122
|
|
|
*/ |
123
|
|
|
public function finalize_two_factor_authentication($auth_token) |
124
|
|
|
{ |
125
|
|
|
$data = [ |
126
|
|
|
'auth_token' => $auth_token, |
127
|
|
|
]; |
128
|
|
|
|
129
|
|
|
return $this->put('user/two_factor_authentication', $data); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Disable two-factor authentication for your CloudFlare user account |
134
|
|
|
* |
135
|
|
|
* @param int The token provided by the two-factor authenticator |
136
|
|
|
*/ |
137
|
|
|
public function disable_two_factor_authentication($auth_token) |
138
|
|
|
{ |
139
|
|
|
$data = [ |
140
|
|
|
'auth_token' => $auth_token, |
141
|
|
|
]; |
142
|
|
|
|
143
|
|
|
return $this->delete('user/two_factor_authentication', $data); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|