| Total Complexity | 8 |
| Total Lines | 70 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class ResendVerificationEmailForm extends Model |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var string |
||
| 12 | */ |
||
| 13 | public $email; |
||
| 14 | |||
| 15 | |||
| 16 | /** |
||
| 17 | * {@inheritdoc} |
||
| 18 | */ |
||
| 19 | public function rules() |
||
| 20 | { |
||
| 21 | return [ |
||
| 22 | ['email', 'trim'], |
||
| 23 | ['email', 'required'], |
||
| 24 | ['email', 'email'], |
||
| 25 | ['email', 'validateEmail'], |
||
| 26 | ]; |
||
| 27 | } |
||
| 28 | |||
| 29 | public function validateEmail($attribute) |
||
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Sends confirmation email to user |
||
| 44 | * |
||
| 45 | * @return bool whether the email was sent |
||
| 46 | */ |
||
| 47 | public function sendEmail() |
||
| 48 | { |
||
| 49 | $user = User::findOne([ |
||
| 50 | 'email' => $this->email, |
||
| 51 | ]); |
||
| 52 | |||
| 53 | if ($user === null) { |
||
| 54 | return false; |
||
| 55 | } |
||
| 56 | |||
| 57 | return Yii::$app |
||
| 58 | ->mailer |
||
| 59 | ->compose( |
||
| 60 | ['html' => 'emailVerify-html', 'text' => 'emailVerify-text'], |
||
| 61 | ['user' => $user] |
||
| 62 | ) |
||
| 63 | ->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name . ' robot']) |
||
| 64 | ->setTo($this->email) |
||
| 65 | ->setSubject('Account registration at ' . Yii::$app->name) |
||
| 66 | ->send(); |
||
| 67 | } |
||
| 68 | |||
| 69 | private $user; |
||
| 70 | |||
| 71 | public function getUser(): ?User |
||
| 78 | } |
||
| 79 | } |
||
| 80 |