User.php 4.3 KB

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