Registration

parent ac08a4b4
...@@ -275,22 +275,25 @@ JS; ...@@ -275,22 +275,25 @@ JS;
$config['options'][] = $this->field($meta, 'description'); $config['options'][] = $this->field($meta, 'description');
$config['options'][] = $this->field($meta, 'keywords'); $config['options'][] = $this->field($meta, 'keywords');
} }
foreach($config['buttons'] as $buttonName => $button) if ($config['buttons']){
{ foreach($config['buttons'] as $buttonName => $button)
if($button['type'] == 'htmlBlock') {
$config['options'][] = $button['value']; if($button['type'] == 'htmlBlock')
else if($button['type'] == 'submit') $config['options'][] = $button['value'];
$config['options'][] = (!empty($button['class'])) ? \yii\helpers\Html::submitButton($button['value'], ['class'=> $button['class']]) else if($button['type'] == 'submit')
: \yii\helpers\Html::submitButton($button['value'], ['class'=> 'btn btn-success']); $config['options'][] = (!empty($button['class'])) ? \yii\helpers\Html::submitButton($button['value'], ['class'=> $button['class']])
else if($button['type'] == 'cancel') : \yii\helpers\Html::submitButton($button['value'], ['class'=> 'btn btn-success']);
$config['options'][] = \yii\helpers\Html::resetButton($button['value'], ['class'=> 'btn btn-default']); else if($button['type'] == 'cancel')
else if($button['type'] == 'danger') $config['options'][] = \yii\helpers\Html::resetButton($button['value'], ['class'=> 'btn btn-default']);
$config['options'][] = \yii\helpers\Html::button($button['value'], ['class'=> 'btn btn-danger', 'id' => $buttonName]); else if($button['type'] == 'danger')
else $config['options'][] = \yii\helpers\Html::button($button['value'], ['class'=> 'btn btn-danger', 'id' => $buttonName]);
$config['options'][] = \yii\helpers\Html::button($button['value'], ['class'=> 'btn btn-info', 'id' => $buttonName]); else
$config['options'][] = \yii\helpers\Html::button($button['value'], ['class'=> 'btn btn-info', 'id' => $buttonName]);
$config['options'][] = ' ';
} $config['options'][] = ' ';
}
}
unset($config['buttons']); unset($config['buttons']);
self::initCustom($config); self::initCustom($config);
......
<?php
use yii\helpers\Html;
/* @var $this \yii\web\View view component instance */
/* @var $message \yii\mail\MessageInterface the message being composed */
/* @var $content string main view render result */
?>
<?php $this->beginPage() ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?= Yii::$app->charset ?>" />
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
Вы получили это письмо, потому что ваш адрес был указан
при регистрации нового логина на сайте <?php echo $link;?>
Чтобы завершить регистрацию, пройдите по ссылке:
<a href="<?php echo $link;?>">
<?php echo $link;?>
</a>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
...@@ -31,14 +31,15 @@ class AuthAssignment extends \common\components\ActiveRecordModel ...@@ -31,14 +31,15 @@ class AuthAssignment extends \common\components\ActiveRecordModel
public function rules() public function rules()
{ {
return array( return [
array('item_name, user_id', 'required'), [['item_name', 'user_id'], 'required'],
array('item_name, user_id', 'string', 'max' => 64), [['item_name'], 'string', 'max' => 64],
[['user_id'], 'integer'],
//array('user_id', 'unique'), //array('user_id', 'unique'),
array('created_at, updated_at', 'safe'), [['created_at'], 'safe'],
//array('item_name, user_id', 'safe', 'on' => 'search'), //array('item_name, user_id', 'safe', 'on' => 'search'),
); ];
} }
...@@ -67,6 +68,13 @@ class AuthAssignment extends \common\components\ActiveRecordModel ...@@ -67,6 +68,13 @@ class AuthAssignment extends \common\components\ActiveRecordModel
)); ));
} }
public function behaviors()
{
return [
];
}
public static function updateuser_idRole($user_id, $role) public static function updateuser_idRole($user_id, $role)
{ {
......
...@@ -2,11 +2,15 @@ ...@@ -2,11 +2,15 @@
namespace common\modules\school\controllers; namespace common\modules\school\controllers;
use Yii;
use common\components\BaseController; use common\components\BaseController;
use common\modules\school\models\Courses; use common\modules\school\models\Courses;
use common\modules\school\models\SearchCourses; use common\modules\school\models\SearchCourses;
use common\modules\school\models\SearchLessons; use common\modules\school\models\SearchLessons;
use common\modules\users\models\User; use common\modules\users\models\User;
use \common\modules\rbac\models\AuthAssignment;
class CourseController extends BaseController class CourseController extends BaseController
{ {
......
<?php <?php
namespace common\modules\users\controllers; namespace common\modules\users\controllers;
use Yii;
use common\modules\users\models\User;
use \common\modules\rbac\models\AuthAssignment;
class UserController extends \common\components\BaseController { class UserController extends \common\components\BaseController {
const ERROR_PASSWORD_RECOVER_AUTH = 'Вы не можете восстановить пароль будучи авторизованным!'; const ERROR_PASSWORD_RECOVER_AUTH = 'Вы не можете восстановить пароль будучи авторизованным!';
public $cats; public $cats;
...@@ -104,43 +109,35 @@ class UserController extends \common\components\BaseController { ...@@ -104,43 +109,35 @@ class UserController extends \common\components\BaseController {
public function actionRegistration() { public function actionRegistration() {
die('');
$model = new User(); $model = new User();
$model->scenario = User::SCENARIO_REGISTRATION; $model->scenario = User::SCENARIO_REGISTRATION;
/* $form = new BaseForm('users.RegistrationForm', $model);
$this->performAjaxValidation($model);
unset($form->elements['captcha']);
$is_created = false;*/
if (isset($_POST['User'])) { if (isset($_POST['User'])) {
$model->attributes = $_POST['User']; $model->attributes = $_POST['User'];
if ($model->validate()) { if ($model->validate()) {
$password = $model->password;
$model->password = md5($model->password); $model->password = md5($model->password);
$model->activate_code = md5($model->password . 'xdf5sf'); $model->activate_code = md5($model->password . 'xdf5sf');
$model->save(false); $model->save(false);
$assignment = new AuthAssignment(); $assignment = new AuthAssignment();
$assignment->itemname = 'user'; $assignment->item_name = 'user';
$assignment->userid = $model->id; $assignment->user_id = $model->id;
$assignment->save(); $assignment->save();
$this->saveEmailToNewUser($model, $password, $model->activate_code);
$is_created = true; $subject = 'Регистрация на сайте '.Yii::$app->params['frontUrl'].'/school';
Yii::$app->mailer->compose('activate', ['link' => Yii::$app->params['frontUrl']])
->setFrom(Yii::$app->params['adminEmail'])
->setTo($model->email)
->setSubject($subject)
->send();
echo json_encode(array('success'=>true));
}
else {
echo json_encode(array('errors'=>$model->getErrors()));
} }
} }
$this->cats = Categories::model()->parentCats()->findAll();
$this->render(
'registration',
array(
'form' => $form,
'model' => $model,
'is_created' => $is_created
)
);
} }
...@@ -150,7 +147,7 @@ class UserController extends \common\components\BaseController { ...@@ -150,7 +147,7 @@ class UserController extends \common\components\BaseController {
if ($user===null) if ($user===null)
$activate_error = 'Неверные данные активации аккаунта!'; $activate_error = 'Неверные данные активации аккаунта!';
else { else {
if (strtotime($user->date_create) + 24 * 3600 > time()) { if (strtotime($user->date_create) + 24 * 3600 > time()) {
$user->activate_date = null; $user->activate_date = null;
$user->activate_code = null; $user->activate_code = null;
...@@ -161,7 +158,7 @@ class UserController extends \common\components\BaseController { ...@@ -161,7 +158,7 @@ class UserController extends \common\components\BaseController {
} else } else
$activate_error = 'С момента регистрации прошло больше суток!'; $activate_error = 'С момента регистрации прошло больше суток!';
} }
$this->render('activateAccount', array( $this->render('activateAccount', array(
'activate_error' => isset($activate_error) ? $activate_error : null, 'activate_error' => isset($activate_error) ? $activate_error : null,
'message' => isset($message) ? $message : null 'message' => isset($message) ? $message : null
......
<?php <?php
use yii\helpers\Url;
use common\modules\users\models\User; use common\modules\users\models\User;
$elements = [ $elements = [
'errors_reg' => '<div class="errors-reg"></div>',
'name' => ['type' => 'text', 'placeholder'=>"Ваше имя*", 'options'=>['label'=>false], 'name' => ['type' => 'text', 'placeholder'=>"Ваше имя*", 'options'=>['label'=>false],
'inputOptions'=>['class'=>'input_st field-input required alphanumeric']], 'inputOptions'=>['class'=>'input_st field-input required alphanumeric']],
'email' => ['type' => 'text', 'placeholder'=>"E-mail*", 'options'=>['label'=>false], 'email' => ['type' => 'text', 'placeholder'=>"E-mail*", 'options'=>['label'=>false],
...@@ -25,6 +23,11 @@ $elements = [ ...@@ -25,6 +23,11 @@ $elements = [
'empty'=>'Чем вы занимаетесь', 'empty'=>'Чем вы занимаетесь',
'inputOptions'=>['class'=>'input_st field-input required alphanumeric'] 'inputOptions'=>['class'=>'input_st field-input required alphanumeric']
], ],
'button_submit' => '<a href="javascript:void(0)" class="submit_form_reg">
<div class="save-button sh_bt_send">
Записаться
</div>
</a>',
]; ];
...@@ -32,13 +35,12 @@ return [ ...@@ -32,13 +35,12 @@ return [
'activeForm'=>[ 'activeForm'=>[
'id' => 'sh_reg_form', 'id' => 'sh_reg_form',
'options' => [ 'options' => [
//'onsubmit'=>"ajaxSubmit(url: ".Url::toRoute(['/users/user/registration']).")";
'enctype' => 'multipart/form-data' 'enctype' => 'multipart/form-data'
], ],
], ],
'elements' => $elements, 'elements' => $elements,
'buttons' => [ /*'buttons' => [
'submit' => ['type' => 'submit', 'value' => 'Записаться', 'class'=>"save-button sh_bt_send"] 'submit' => ['type' => 'submit', 'value' => 'Записаться', 'class'=>"save-button sh_bt_send"]
] ]*/
]; ];
...@@ -15,57 +15,57 @@ use \common\modules\rbac\models\AuthAssignment; ...@@ -15,57 +15,57 @@ use \common\modules\rbac\models\AuthAssignment;
class User extends \common\components\ActiveRecordModel implements IdentityInterface class User extends \common\components\ActiveRecordModel implements IdentityInterface
{ {
const PAGE_SIZE = 10; const PAGE_SIZE = 10;
const OCCUPATION_CHIEF_IT = 1; const OCCUPATION_CHIEF_IT = 1;
const OCCUPATION_MANAGER_IT = 2; const OCCUPATION_MANAGER_IT = 2;
const OCCUPATION_CREATOR = 3; const OCCUPATION_CREATOR = 3;
const OCCUPATION_NOT_IT = 4; const OCCUPATION_NOT_IT = 4;
const STATUS_ACTIVE = 'active'; const STATUS_ACTIVE = 'active';
const STATUS_NEW = 'new'; const STATUS_NEW = 'new';
const STATUS_BLOCKED = 'blocked'; const STATUS_BLOCKED = 'blocked';
const GENDER_MAN = "man"; const GENDER_MAN = "man";
const GENDER_WOMAN = "woman"; const GENDER_WOMAN = "woman";
const SETTING_CHANGE_PASSWORD_REQUEST_MAIL_SUBJECT = 'change_password_request_mail_subject'; const SETTING_CHANGE_PASSWORD_REQUEST_MAIL_SUBJECT = 'change_password_request_mail_subject';
const SETTING_CHANGE_PASSWORD_REQUEST_MAIL_BODY = 'change_password_request_mail_body'; const SETTING_CHANGE_PASSWORD_REQUEST_MAIL_BODY = 'change_password_request_mail_body';
const SETTING_CHANGE_PASSWORD_REQUEST_MAIL_BODY_SINGLE = 'change_password_request_mail_body_single'; const SETTING_CHANGE_PASSWORD_REQUEST_MAIL_BODY_SINGLE = 'change_password_request_mail_body_single';
const SETTING_ACTIVATE_REQUEST_DONE_MESSAGE = 'activate_request_done_message'; const SETTING_ACTIVATE_REQUEST_DONE_MESSAGE = 'activate_request_done_message';
const SETTING_REGISTRATION_MAIL_SUBJECT = 'registration_mail_subject'; const SETTING_REGISTRATION_MAIL_SUBJECT = 'registration_mail_subject';
const SETTING_REGISTRATION_DONE_MESSAGE = 'registration_done_message'; const SETTING_REGISTRATION_DONE_MESSAGE = 'registration_done_message';
const SETTING_REGISTRATION_MAIL_BODY = 'registration_mail_body'; const SETTING_REGISTRATION_MAIL_BODY = 'registration_mail_body';
const SCENARIO_CHANGE_PASSWORD_REQUEST = 'ChangePasswordRequest'; const SCENARIO_CHANGE_PASSWORD_REQUEST = 'ChangePasswordRequest';
const SCENARIO_SEND_NEW_PASSWORD = 'SendNewPassword'; const SCENARIO_SEND_NEW_PASSWORD = 'SendNewPassword';
const SCENARIO_ACTIVATE_REQUEST = 'ActivateRequest'; const SCENARIO_ACTIVATE_REQUEST = 'ActivateRequest';
const SCENARIO_CHANGE_PASSWORD = 'ChangePassword'; const SCENARIO_CHANGE_PASSWORD = 'ChangePassword';
const SCENARIO_REGISTRATION = 'Registration'; const SCENARIO_REGISTRATION = 'Registration';
const SCENARIO_UPDATE = 'Update'; const SCENARIO_UPDATE = 'Update';
const SCENARIO_CREATE = 'Create'; const SCENARIO_CREATE = 'Create';
const SCENARIO_LOGIN = 'Login'; const SCENARIO_LOGIN = 'Login';
const SCENARIO_DELETE = 'Delete'; const SCENARIO_DELETE = 'Delete';
const SCENARIO_SEARCH = 'Search'; const SCENARIO_SEARCH = 'Search';
const SCENARIO_CSV_IMPORT = 'CSV_IMPORT'; const SCENARIO_CSV_IMPORT = 'CSV_IMPORT';
const SCENARIO_RECOVER_PASSWORD = 'RecoverPassword'; const SCENARIO_RECOVER_PASSWORD = 'RecoverPassword';
// public $email; // public $email;
public $role; public $role;
public $password_c; public $password_c;
public $captcha; public $captcha;
public $remember_me = false; public $remember_me = false;
public $activate_error; public $activate_error;
// public $activate_code; // public $activate_code;
// public $checked; // public $checked;
public $csv_file; public $csv_file;
public $send_email; public $send_email;
public $generate_new; public $generate_new;
// public $fio; // public $fio;
// public $phone; // public $phone;
// public $mobile_phone; // public $mobile_phone;
// public $skype; // public $skype;
public $tmp; //for external using. no delete! public $tmp; //for external using. no delete!
// public $post; // public $post;
...@@ -76,19 +76,19 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter ...@@ -76,19 +76,19 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
self::OCCUPATION_NOT_IT => 'Не работаю в IT', self::OCCUPATION_NOT_IT => 'Не работаю в IT',
]; ];
public function behaviors() public function behaviors()
{ {
return [ return [
'eavAttributes' => [ 'eavAttributes' => [
'class' => '\lagman\eav\EavBehavior', 'class' => '\lagman\eav\EavBehavior',
'valueClass' => 'User', 'valueClass' => 'User',
], ],
'sort' => [ 'sort' => [
'class' => SortableGridBehavior::className(), 'class' => SortableGridBehavior::className(),
'sortableAttribute' => 'sort' 'sortableAttribute' => 'sort'
], ],
]; ];
} }
public function attributeLabels() public function attributeLabels()
{ {
...@@ -126,11 +126,12 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter ...@@ -126,11 +126,12 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
], 'message' => 'Пожалуйста, укажите корректный e-mail адрес'], ], 'message' => 'Пожалуйста, укажите корректный e-mail адрес'],
[['send_email'], 'safe'], [['send_email'], 'safe'],
[['fio','name', 'surname'], 'safe', 'on' => [ [['fio','name', 'surname'], 'safe', 'on' => [
self::SCENARIO_REGISTRATION,
self::SCENARIO_CREATE, self::SCENARIO_CREATE,
], 'message' => 'Пожалуйста, укажите Ваше имя'], ], 'message' => 'Пожалуйста, укажите Ваше имя'],
[['phone'], 'required', 'on' => [ [['name'], 'required', 'on' => [
self::SCENARIO_REGISTRATION, self::SCENARIO_REGISTRATION,
], 'message' => 'Пожалуйста, укажите Ваше имя'],
[['phone'], 'required', 'on' => [
self::SCENARIO_CREATE, self::SCENARIO_CREATE,
], 'message' => 'Пожалуйста, укажите Ваш номер телефона'], ], 'message' => 'Пожалуйста, укажите Ваш номер телефона'],
[['phone'], 'string', 'max'=> 50], [['phone'], 'string', 'max'=> 50],
......
...@@ -8827,7 +8827,8 @@ a.kurs_bt:active { ...@@ -8827,7 +8827,8 @@ a.kurs_bt:active {
color: #908505; color: #908505;
border: none; border: none;
border-bottom: 4px solid #D2BF00; border-bottom: 4px solid #D2BF00;
margin: 0 auto; padding-top: 20px;
/* margin: 0 auto;*/
} }
.sh_bt_send:hover, .sh_bt_send:focus { .sh_bt_send:hover, .sh_bt_send:focus {
background-image: linear-gradient(to top, #fde654 0%, #fef77d 100%); background-image: linear-gradient(to top, #fde654 0%, #fef77d 100%);
...@@ -11464,4 +11465,11 @@ h6 { ...@@ -11464,4 +11465,11 @@ h6 {
margin-bottom: 15px; margin-bottom: 15px;
color: #698387; color: #698387;
font-size: 14px; font-size: 14px;
}
a.submit_form_reg{
text-decoration: none;
}
.errors-reg{
color: #ff5b57;
margin-bottom: 10px;
} }
\ No newline at end of file
...@@ -584,63 +584,44 @@ jQuery(document).ready(function(){ ...@@ -584,63 +584,44 @@ jQuery(document).ready(function(){
// prepare the form when the DOM is ready // prepare the form when the DOM is ready
$(document).ready(function() { $(document).ready(function() {
var options = { var options = {
//target: '#output2', // target element(s) to be updated with server response
beforeSubmit: showRequest, // pre-submit callback beforeSubmit: showRequest, // pre-submit callback
success: showResponse, // post-submit callback success: showResponse, // post-submit callback
// other available options: // other available options:
url: '/users/user/registration' // override for form's 'action' attribute url: '/users/user/registration', // override for form's 'action' attribute
//type: type // 'get' or 'post', override for form's 'method' attribute dataType: 'json' // 'xml', 'script', or 'json' (expected server response type)
//dataType: null // 'xml', 'script', or 'json' (expected server response type)
//clearForm: true // clear all form fields after successful submit
//resetForm: true // reset the form after successful submit
// $.ajax options can be used here too, for example:
//timeout: 3000
}; };
// bind to the form's submit event // bind to the form's submit event
$('#sh_reg_form').submit(function() { $('#sh_reg_form').submit(function() {
// inside event callbacks 'this' is the DOM element so we first $('.errors-reg').append('');
// wrap it in a jQuery object and then invoke ajaxSubmit
$(this).ajaxSubmit(options); $(this).ajaxSubmit(options);
// !!! Important !!!
// always return false to prevent standard browser submit and page navigation
return false; return false;
}); });
$(".submit_form_reg").on('click', function () {
$('#sh_reg_form').ajaxSubmit(options);
return false;
});
}); });
// pre-submit callback // pre-submit callback
function showRequest(formData, jqForm, options) { function showRequest(formData, jqForm, options) {
// formData is an array; here we use $.param to convert it to a string to display it
// but the form plugin does this for you automatically when it submits the data
var queryString = $.param(formData); var queryString = $.param(formData);
// jqForm is a jQuery object encapsulating the form element. To access the
// DOM element for the form do this:
// var formElement = jqForm[0];
//alert('About to submit: \n\n' + queryString);
// here we could return false to prevent the form from being submitted;
// returning anything other than false will allow the form submit to continue
return true; return true;
} }
// post-submit callback // post-submit callback
function showResponse(responseText, statusText, xhr, $form) { function showResponse(responseText, statusText, xhr, $form) {
// for normal html responses, the first argument to the success callback if (responseText.errors){
// is the XMLHttpRequest object's responseText property $.each(responseText.errors, function(key,value) {
$('.errors-reg').append(value+'<br>');
// if the ajaxSubmit method was passed an Options Object with the dataType $('.field-user-'+key).addClass('has-error');
// property set to 'xml' then the first argument to the success callback });
// is the XMLHttpRequest object's responseXML property }
else{
// if the ajaxSubmit method was passed an Options Object with the dataType console.log(responseText.success);
// property set to 'json' then the first argument to the success callback $('#sh_reg_form').html('Регистрация успешно завершена. Вам отправлено письмо для активации аккаунта.');
// is the json data object returned by the server }
//alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
// '\n\nThe output div should have already been updated with the responseText.');
} }
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment