diff --git a/common/models/Accounts.php b/common/models/Accounts.php index 9f3cc08..83eff38 100755 --- a/common/models/Accounts.php +++ b/common/models/Accounts.php @@ -51,6 +51,9 @@ use yii\db\ActiveRecord; class Accounts extends ActiveRecord implements IdentityInterface { + /** + * @var + */ public $re_pass; public $surname; public $country_region; @@ -69,6 +72,9 @@ class Accounts extends ActiveRecord implements IdentityInterface } + /** + * @return bool + */ public function beforeSave() { $this->dt = time(); @@ -84,7 +90,7 @@ class Accounts extends ActiveRecord implements IdentityInterface { return [ [['if_manager', 'margin_id', 'country', 'city', 'rating', 'is_active', 'is_firm', 'office_id', 'is_scribe', 'set_manager_id', 'car', 'mod', 'deliveries', 'scode'], 'integer'], - [['company','email', 'pass', 'name','surname', 'phones',], 'required'], + [['company','email', 'pass', 'name', 'phones',], 'required'], [['comment'], 'string'], [['balance'], 'number'], [['email', 'name','surname', 'firm_site'], 'string', 'max' => 150], @@ -95,9 +101,6 @@ class Accounts extends ActiveRecord implements IdentityInterface [['snumb', 'firm_ur_adr', 'firm_fiz_adr', 'firm_code_eg', 'firm_rs', 'firm_mfo', 'company'], 'string', 'max' => 255], [['email'], 'unique'], [['email'], 'email'], - ['re_pass', 'compare', 'compareAttribute' => 'pass'], - ['verifyCode', 'captcha'], - ['dt', 'date', 'format' => 'Y.m.d'], [['rating','if_manager','set_manager_id','balance'], 'default', 'value' => '0'], [['is_active','margin_id','office_id','is_scribe'], 'default', 'value' => '1'], [['comment'], 'default', 'value' => 'Новый пользователь'], diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index e4a6bf6..a983129 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -2,6 +2,7 @@ namespace frontend\controllers; use common\models\Accounts; +use frontend\models\AccountsForm; use common\models\News; use common\models\Slider; use common\models\Team; @@ -338,15 +339,21 @@ class SiteController extends Controller $this->layout = '/internal'; - $model = new Accounts(); + $model = new AccountsForm(); - if ($model->load(Yii::$app->request->post()) ) { + if ($model->load(Yii::$app->request->post()) && $model->validate() ) { - $model->generateAuthKey(); - $model->save(); - if (Yii::$app->getUser()->login($model)) { + $accounts = new Accounts(); + + $accounts->load(Yii::$app->request->post()); + + $accounts->generateAuthKey(); + + $accounts->save(); + + if (Yii::$app->getUser()->login($accounts)) { return $this->goHome(); @@ -369,13 +376,16 @@ class SiteController extends Controller $this->layout = '/internal'; $model = new PasswordResetRequestForm(); + if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->sendEmail()) { + Yii::$app->session->setFlash('success', 'Для того, чтобы изменить пароль, перейдите по ссылке, которая придет Вам на email'); return $this->goHome(); } else { + die('here2'); Yii::$app->session->setFlash('error', 'Пользователя с таким e-mail в базе не существует'); } } diff --git a/frontend/models/AccountsForm.php b/frontend/models/AccountsForm.php new file mode 100644 index 0000000..a9ec146 --- /dev/null +++ b/frontend/models/AccountsForm.php @@ -0,0 +1,142 @@ + 150], + [['pass','re_pass'], 'string', 'max' => 30], + [['phones', 'phones2', 'phones3'], 'string', 'max' => 50], + [['address', 'firm_inn', 'firm_bank'], 'string', 'max' => 254], + [['last_loginin'], 'string', 'max' => 15], + [['snumb', 'firm_ur_adr', 'firm_fiz_adr', 'firm_code_eg', 'firm_rs', 'firm_mfo', 'company'], 'string', 'max' => 255], + [['email'], 'unique'], + [['email'], 'email'], + ['re_pass', 'compare', 'compareAttribute' => 'pass'], + ['verifyCode', 'captcha'], + ['dt', 'date', 'format' => 'Y.m.d'], + [['rating','if_manager','set_manager_id','balance'], 'default', 'value' => '0'], + [['is_active','margin_id','office_id','is_scribe'], 'default', 'value' => '1'], + [['comment'], 'default', 'value' => 'Новый пользователь'], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'if_manager' => 'Статус менеджера', + 'email' => 'E-mail (Логин)', + 'pass' => 'Пароль', + 'margin_id' => 'Тип цены', + 'name' => 'Имя', + 'phones' => 'Телефоны', + 'country' => Yii::t('app', 'Country'), + 'city' =>'Город', + 'address' => 'Адрес', + 'comment' => 'Комментарий', + 'rating' => Yii::t('app', 'Rating'), + 'dt' =>'Дата регистрации', + 'is_active' => 'Активный', + 'is_firm' => 'Юридическое лицо', + 'last_loginin' => Yii::t('app', 'Last Loginin'), + 'firm_inn' => 'ИНН', + 'firm_bank' => 'Банк', + 'balance' => Yii::t('app', 'Balance'), + 'office_id' => Yii::t('app', 'Office ID'), + 'is_scribe' => 'Подписка', + 'set_manager_id' => 'Персональный менеджер', + 'phones2' => 'Телефоны 2', + 'phones3' => 'Телефоны 3', + 'car' => Yii::t('app', 'Car'), + 'mod' => Yii::t('app', 'Mod'), + 'snumb' => 'snumb', + 'deliveries' => Yii::t('app', 'Deliveries'), + 'scode' => 'Код в 1С', + 'firm_ur_adr' => 'Юридический адрес', + 'firm_fiz_adr' => 'Физический адрес', + 'firm_code_eg' => 'Код ЭГ', + 'firm_rs' => 'Расчётный счёт', + 'firm_mfo' => 'МФО', + 'firm_site' => 'Сайт', + 'company' => 'Название фирмы', + 'country_region' => 'Регион' + ]; + } + + + + + + + +} diff --git a/frontend/models/PasswordResetRequestForm.php b/frontend/models/PasswordResetRequestForm.php index ddf1cc4..01a021a 100755 --- a/frontend/models/PasswordResetRequestForm.php +++ b/frontend/models/PasswordResetRequestForm.php @@ -45,11 +45,15 @@ class PasswordResetRequestForm extends Model $user->generatePasswordResetToken(); } + + if ($user->save()) { + $form = array(); $form ['email'] = $user->email; $form ['name'] = $user->name; $form ['pass'] = $user->pass; + die(var_dump(Emails::get('remide',$form,$form ['email']))); return Emails::get('remide',$form,$form ['email']); } diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index 11f7baf..b2289bd 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -8,7 +8,7 @@ use yii\widgets\ActiveForm; use \yii\widgets\Menu; use \yii\helpers\Url; use common\models\Callback; -use \common\models\Accounts; +use \frontend\models\AccountsForm; use \yii\helpers\ArrayHelper; use \common\models\DicCities; use \common\models\Deliveries; @@ -410,41 +410,41 @@ use \common\models\UserLoginForm;