Наведён порядок в моделях проекта

This commit is contained in:
ErickSkrauch
2016-05-14 02:47:17 +03:00
parent ecd92b8fda
commit 0ba1be27e8
21 changed files with 93 additions and 204 deletions

View File

@@ -1,59 +0,0 @@
<?php
namespace api\models;
use Yii;
use yii\base\Model;
/**
* ContactForm is the model behind the contact form.
*/
class ContactForm extends Model
{
public $name;
public $email;
public $subject;
public $body;
public $verifyCode;
/**
* @inheritdoc
*/
public function rules()
{
return [
// name, email, subject and body are required
[['name', 'email', 'subject', 'body'], 'required'],
// email has to be a valid email address
['email', 'email'],
// verifyCode needs to be entered correctly
['verifyCode', 'captcha'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'verifyCode' => 'Verification Code',
];
}
/**
* Sends an email to the specified email address using the information collected by this model.
*
* @param string $email the target email address
* @return boolean whether the email was sent
*/
public function sendEmail($email)
{
return Yii::$app->mailer->compose()
->setTo($email)
->setFrom([$this->email => $this->name])
->setSubject($this->subject)
->setTextBody($this->body)
->send();
}
}

View File

@@ -1,65 +0,0 @@
<?php
namespace api\models;
use common\models\Account;
use yii\base\InvalidParamException;
use yii\base\Model;
use Yii;
/**
* Password reset form
*/
class ResetPasswordForm extends Model
{
public $password;
/**
* @var \common\models\Account
*/
private $_user;
/**
* Creates a form model given a token.
*
* @param string $token
* @param array $config name-value pairs that will be used to initialize the object properties
* @throws \yii\base\InvalidParamException if token is empty or not valid
*/
public function __construct($token, $config = [])
{
if (empty($token) || !is_string($token)) {
throw new InvalidParamException('Password reset token cannot be blank.');
}
$this->_user = Account::findByPasswordResetToken($token);
if (!$this->_user) {
throw new InvalidParamException('Wrong password reset token.');
}
parent::__construct($config);
}
/**
* @inheritdoc
*/
public function rules()
{
return [
['password', 'required'],
['password', 'string', 'min' => 6],
];
}
/**
* Resets password.
*
* @return boolean if password was reset.
*/
public function resetPassword()
{
$user = $this->_user;
$user->setPassword($this->password);
$user->removePasswordResetToken();
return $user->save(false);
}
}

View File

@@ -1,5 +1,5 @@
<?php
namespace api\models;
namespace api\models\authentication;
use api\models\base\KeyConfirmationForm;
use common\models\Account;

View File

@@ -1,5 +1,5 @@
<?php
namespace api\models;
namespace api\models\authentication;
use api\models\base\ApiForm;
use api\traits\AccountFinder;

View File

@@ -1,5 +1,5 @@
<?php
namespace api\models;
namespace api\models\authentication;
use api\models\base\ApiForm;
use api\traits\AccountFinder;

View File

@@ -1,5 +1,5 @@
<?php
namespace api\models;
namespace api\models\authentication;
use api\models\base\KeyConfirmationForm;
use common\models\EmailActivation;

View File

@@ -1,8 +1,9 @@
<?php
namespace api\models;
namespace api\models\authentication;
use api\components\ReCaptcha\Validator as ReCaptchaValidator;
use api\models\base\ApiForm;
use api\models\profile\ChangeUsernameForm;
use common\components\UserFriendlyRandomKey;
use common\models\Account;
use common\models\confirmations\RegistrationConfirmation;

View File

@@ -1,5 +1,5 @@
<?php
namespace api\models;
namespace api\models\authentication;
use api\models\base\ApiForm;
use common\components\UserFriendlyRandomKey;

View File

@@ -1,5 +1,5 @@
<?php
namespace api\models;
namespace api\models\profile;
use api\models\base\PasswordProtectedForm;
use common\models\Account;

View File

@@ -1,5 +1,5 @@
<?php
namespace api\models;
namespace api\models\profile;
use api\models\base\PasswordProtectedForm;
use common\helpers\Amqp;