AccountManagementInterface.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Customer\Api;
  8. use Magento\Framework\Exception\InputException;
  9. /**
  10. * Interface for managing customers accounts.
  11. * @api
  12. * @since 100.0.2
  13. */
  14. interface AccountManagementInterface
  15. {
  16. /**#@+
  17. * Constant for confirmation status
  18. */
  19. const ACCOUNT_CONFIRMED = 'account_confirmed';
  20. const ACCOUNT_CONFIRMATION_REQUIRED = 'account_confirmation_required';
  21. const ACCOUNT_CONFIRMATION_NOT_REQUIRED = 'account_confirmation_not_required';
  22. const MAX_PASSWORD_LENGTH = 256;
  23. /**#@-*/
  24. /**
  25. * Create customer account. Perform necessary business operations like sending email.
  26. *
  27. * @param \Magento\Customer\Api\Data\CustomerInterface $customer
  28. * @param string $password
  29. * @param string $redirectUrl
  30. * @return \Magento\Customer\Api\Data\CustomerInterface
  31. * @throws \Magento\Framework\Exception\LocalizedException
  32. */
  33. public function createAccount(
  34. \Magento\Customer\Api\Data\CustomerInterface $customer,
  35. $password = null,
  36. $redirectUrl = ''
  37. );
  38. /**
  39. * Create customer account using provided hashed password. Should not be exposed as a webapi.
  40. *
  41. * @api
  42. * @param \Magento\Customer\Api\Data\CustomerInterface $customer
  43. * @param string $hash Password hash that we can save directly
  44. * @param string $redirectUrl URL fed to welcome email templates. Can be used by templates to, for example, direct
  45. * the customer to a product they were looking at after pressing confirmation link.
  46. * @return \Magento\Customer\Api\Data\CustomerInterface
  47. * @throws \Magento\Framework\Exception\InputException If bad input is provided
  48. * @throws \Magento\Framework\Exception\State\InputMismatchException If the provided email is already used
  49. * @throws \Magento\Framework\Exception\LocalizedException
  50. */
  51. public function createAccountWithPasswordHash(
  52. \Magento\Customer\Api\Data\CustomerInterface $customer,
  53. $hash,
  54. $redirectUrl = ''
  55. );
  56. /**
  57. * Validate customer data.
  58. *
  59. * @param \Magento\Customer\Api\Data\CustomerInterface $customer
  60. * @return \Magento\Customer\Api\Data\ValidationResultsInterface
  61. * @throws \Magento\Framework\Exception\LocalizedException
  62. */
  63. public function validate(\Magento\Customer\Api\Data\CustomerInterface $customer);
  64. /**
  65. * Check if customer can be deleted.
  66. *
  67. * @api
  68. * @param int $customerId
  69. * @return bool
  70. * @throws \Magento\Framework\Exception\NoSuchEntityException If group is not found
  71. * @throws \Magento\Framework\Exception\LocalizedException
  72. */
  73. public function isReadonly($customerId);
  74. /**
  75. * Activate a customer account using a key that was sent in a confirmation email.
  76. *
  77. * @param string $email
  78. * @param string $confirmationKey
  79. * @return \Magento\Customer\Api\Data\CustomerInterface
  80. * @throws \Magento\Framework\Exception\LocalizedException
  81. */
  82. public function activate($email, $confirmationKey);
  83. /**
  84. * Activate a customer account using a key that was sent in a confirmation email.
  85. *
  86. * @api
  87. * @param int $customerId
  88. * @param string $confirmationKey
  89. * @return \Magento\Customer\Api\Data\CustomerInterface
  90. * @throws \Magento\Framework\Exception\LocalizedException
  91. */
  92. public function activateById($customerId, $confirmationKey);
  93. /**
  94. * Authenticate a customer by username and password
  95. *
  96. * @param string $email
  97. * @param string $password
  98. * @return \Magento\Customer\Api\Data\CustomerInterface
  99. * @throws \Magento\Framework\Exception\LocalizedException
  100. */
  101. public function authenticate($email, $password);
  102. /**
  103. * Change customer password.
  104. *
  105. * @param string $email
  106. * @param string $currentPassword
  107. * @param string $newPassword
  108. * @return bool true on success
  109. * @throws \Magento\Framework\Exception\LocalizedException
  110. */
  111. public function changePassword($email, $currentPassword, $newPassword);
  112. /**
  113. * Change customer password.
  114. *
  115. * @param int $customerId
  116. * @param string $currentPassword
  117. * @param string $newPassword
  118. * @return bool true on success
  119. * @throws \Magento\Framework\Exception\LocalizedException
  120. */
  121. public function changePasswordById($customerId, $currentPassword, $newPassword);
  122. /**
  123. * Send an email to the customer with a password reset link.
  124. *
  125. * @param string $email
  126. * @param string $template
  127. * @param int $websiteId
  128. * @return bool true on success
  129. * @throws \Magento\Framework\Exception\LocalizedException
  130. */
  131. public function initiatePasswordReset($email, $template, $websiteId = null);
  132. /**
  133. * Reset customer password.
  134. *
  135. * @param string $email If empty value given then the customer
  136. * will be matched by the RP token.
  137. * @param string $resetToken
  138. * @param string $newPassword
  139. *
  140. * @return bool true on success
  141. * @throws \Magento\Framework\Exception\LocalizedException
  142. * @throws InputException
  143. */
  144. public function resetPassword($email, $resetToken, $newPassword);
  145. /**
  146. * Check if password reset token is valid.
  147. *
  148. * @param int $customerId If null is given then a customer
  149. * will be matched by the RP token.
  150. * @param string $resetPasswordLinkToken
  151. *
  152. * @return bool True if the token is valid
  153. * @throws \Magento\Framework\Exception\State\InputMismatchException If token is mismatched
  154. * @throws \Magento\Framework\Exception\State\ExpiredException If token is expired
  155. * @throws \Magento\Framework\Exception\InputException If token or customer id is invalid
  156. * @throws \Magento\Framework\Exception\NoSuchEntityException If customer doesn't exist
  157. * @throws \Magento\Framework\Exception\LocalizedException
  158. */
  159. public function validateResetPasswordLinkToken($customerId, $resetPasswordLinkToken);
  160. /**
  161. * Gets the account confirmation status.
  162. *
  163. * @param int $customerId
  164. * @return string
  165. * @throws \Magento\Framework\Exception\LocalizedException
  166. */
  167. public function getConfirmationStatus($customerId);
  168. /**
  169. * Resend confirmation email.
  170. *
  171. * @param string $email
  172. * @param int $websiteId
  173. * @param string $redirectUrl
  174. * @return bool true on success
  175. * @throws \Magento\Framework\Exception\LocalizedException
  176. */
  177. public function resendConfirmation($email, $websiteId, $redirectUrl = '');
  178. /**
  179. * Check if given email is associated with a customer account in given website.
  180. *
  181. * @param string $customerEmail
  182. * @param int $websiteId If not set, will use the current websiteId
  183. * @return bool
  184. * @throws \Magento\Framework\Exception\LocalizedException
  185. */
  186. public function isEmailAvailable($customerEmail, $websiteId = null);
  187. /**
  188. * Check store availability for customer given the customerId.
  189. *
  190. * @param int $customerWebsiteId
  191. * @param int $storeId
  192. * @return bool
  193. * @throws \Magento\Framework\Exception\LocalizedException
  194. */
  195. public function isCustomerInStore($customerWebsiteId, $storeId);
  196. /**
  197. * Retrieve default billing address for the given customerId.
  198. *
  199. * @param int $customerId
  200. * @return \Magento\Customer\Api\Data\AddressInterface
  201. * @throws \Magento\Framework\Exception\NoSuchEntityException If the customer Id is invalid
  202. * @throws \Magento\Framework\Exception\LocalizedException
  203. */
  204. public function getDefaultBillingAddress($customerId);
  205. /**
  206. * Retrieve default shipping address for the given customerId.
  207. *
  208. * @param int $customerId
  209. * @return \Magento\Customer\Api\Data\AddressInterface
  210. * @throws \Magento\Framework\Exception\NoSuchEntityException If the customer Id is invalid
  211. * @throws \Magento\Framework\Exception\LocalizedException
  212. */
  213. public function getDefaultShippingAddress($customerId);
  214. /**
  215. * Return hashed password, which can be directly saved to database.
  216. *
  217. * @param string $password
  218. * @return string
  219. */
  220. public function getPasswordHash($password);
  221. }