Registration

parent ac08a4b4
...@@ -275,6 +275,7 @@ JS; ...@@ -275,6 +275,7 @@ 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');
} }
if ($config['buttons']){
foreach($config['buttons'] as $buttonName => $button) foreach($config['buttons'] as $buttonName => $button)
{ {
if($button['type'] == 'htmlBlock') if($button['type'] == 'htmlBlock')
...@@ -291,6 +292,8 @@ JS; ...@@ -291,6 +292,8 @@ JS;
$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
)
);
} }
......
<?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"]
] ]*/
]; ];
...@@ -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%);
...@@ -11465,3 +11466,10 @@ h6 { ...@@ -11465,3 +11466,10 @@ h6 {
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);
return false;
});
// !!! Important !!! $(".submit_form_reg").on('click', function () {
// always return false to prevent standard browser submit and page navigation $('#sh_reg_form').ajaxSubmit(options);
return false; 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