ResendVerificationEmailForm.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace frontend\models;
  3. use Yii;
  4. use common\models\User;
  5. use yii\base\Model;
  6. class ResendVerificationEmailForm extends Model
  7. {
  8. /**
  9. * @var string
  10. */
  11. public $email;
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public function rules()
  16. {
  17. return [
  18. ['email', 'trim'],
  19. ['email', 'required'],
  20. ['email', 'email'],
  21. ['email', 'exist',
  22. 'targetClass' => '\common\models\User',
  23. 'filter' => ['status' => User::STATUS_INACTIVE],
  24. 'message' => 'There is no user with this email address.'
  25. ],
  26. ];
  27. }
  28. /**
  29. * Sends confirmation email to user
  30. *
  31. * @return bool whether the email was sent
  32. */
  33. public function sendEmail()
  34. {
  35. $user = User::findOne([
  36. 'email' => $this->email,
  37. 'status' => User::STATUS_INACTIVE
  38. ]);
  39. if ($user === null) {
  40. return false;
  41. }
  42. return Yii::$app
  43. ->mailer
  44. ->compose(
  45. ['html' => 'emailVerify-html', 'text' => 'emailVerify-text'],
  46. ['user' => $user]
  47. )
  48. ->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name . ' robot'])
  49. ->setTo($this->email)
  50. ->setSubject('Account registration at ' . Yii::$app->name)
  51. ->send();
  52. }
  53. }