Registration

parent ac08a4b4
......@@ -275,22 +275,25 @@ JS;
$config['options'][] = $this->field($meta, 'description');
$config['options'][] = $this->field($meta, 'keywords');
}
foreach($config['buttons'] as $buttonName => $button)
{
if($button['type'] == 'htmlBlock')
$config['options'][] = $button['value'];
else if($button['type'] == 'submit')
$config['options'][] = (!empty($button['class'])) ? \yii\helpers\Html::submitButton($button['value'], ['class'=> $button['class']])
: \yii\helpers\Html::submitButton($button['value'], ['class'=> 'btn btn-success']);
else if($button['type'] == 'cancel')
$config['options'][] = \yii\helpers\Html::resetButton($button['value'], ['class'=> 'btn btn-default']);
else if($button['type'] == 'danger')
$config['options'][] = \yii\helpers\Html::button($button['value'], ['class'=> 'btn btn-danger', 'id' => $buttonName]);
else
$config['options'][] = \yii\helpers\Html::button($button['value'], ['class'=> 'btn btn-info', 'id' => $buttonName]);
$config['options'][] = ' ';
}
if ($config['buttons']){
foreach($config['buttons'] as $buttonName => $button)
{
if($button['type'] == 'htmlBlock')
$config['options'][] = $button['value'];
else if($button['type'] == 'submit')
$config['options'][] = (!empty($button['class'])) ? \yii\helpers\Html::submitButton($button['value'], ['class'=> $button['class']])
: \yii\helpers\Html::submitButton($button['value'], ['class'=> 'btn btn-success']);
else if($button['type'] == 'cancel')
$config['options'][] = \yii\helpers\Html::resetButton($button['value'], ['class'=> 'btn btn-default']);
else if($button['type'] == 'danger')
$config['options'][] = \yii\helpers\Html::button($button['value'], ['class'=> 'btn btn-danger', 'id' => $buttonName]);
else
$config['options'][] = \yii\helpers\Html::button($button['value'], ['class'=> 'btn btn-info', 'id' => $buttonName]);
$config['options'][] = ' ';
}
}
unset($config['buttons']);
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
public function rules()
{
return array(
array('item_name, user_id', 'required'),
array('item_name, user_id', 'string', 'max' => 64),
return [
[['item_name', 'user_id'], 'required'],
[['item_name'], 'string', 'max' => 64],
[['user_id'], 'integer'],
//array('user_id', 'unique'),
array('created_at, updated_at', 'safe'),
[['created_at'], 'safe'],
//array('item_name, user_id', 'safe', 'on' => 'search'),
);
];
}
......@@ -67,6 +68,13 @@ class AuthAssignment extends \common\components\ActiveRecordModel
));
}
public function behaviors()
{
return [
];
}
public static function updateuser_idRole($user_id, $role)
{
......
......@@ -2,11 +2,15 @@
namespace common\modules\school\controllers;
use Yii;
use common\components\BaseController;
use common\modules\school\models\Courses;
use common\modules\school\models\SearchCourses;
use common\modules\school\models\SearchLessons;
use common\modules\users\models\User;
use \common\modules\rbac\models\AuthAssignment;
class CourseController extends BaseController
{
......
<?php
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 {
const ERROR_PASSWORD_RECOVER_AUTH = 'Вы не можете восстановить пароль будучи авторизованным!';
public $cats;
......@@ -104,43 +109,35 @@ class UserController extends \common\components\BaseController {
public function actionRegistration() {
die('');
$model = new User();
$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'])) {
$model->attributes = $_POST['User'];
if ($model->validate()) {
$password = $model->password;
$model->password = md5($model->password);
$model->activate_code = md5($model->password . 'xdf5sf');
$model->save(false);
$assignment = new AuthAssignment();
$assignment->itemname = 'user';
$assignment->userid = $model->id;
$assignment->item_name = 'user';
$assignment->user_id = $model->id;
$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 {
if ($user===null)
$activate_error = 'Неверные данные активации аккаунта!';
else {
else {
if (strtotime($user->date_create) + 24 * 3600 > time()) {
$user->activate_date = null;
$user->activate_code = null;
......@@ -161,7 +158,7 @@ class UserController extends \common\components\BaseController {
} else
$activate_error = 'С момента регистрации прошло больше суток!';
}
$this->render('activateAccount', array(
'activate_error' => isset($activate_error) ? $activate_error : null,
'message' => isset($message) ? $message : null
......
<?php
use yii\helpers\Url;
use common\modules\users\models\User;
$elements = [
'errors_reg' => '<div class="errors-reg"></div>',
'name' => ['type' => 'text', 'placeholder'=>"Ваше имя*", 'options'=>['label'=>false],
'inputOptions'=>['class'=>'input_st field-input required alphanumeric']],
'email' => ['type' => 'text', 'placeholder'=>"E-mail*", 'options'=>['label'=>false],
......@@ -25,6 +23,11 @@ $elements = [
'empty'=>'Чем вы занимаетесь',
'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 [
'activeForm'=>[
'id' => 'sh_reg_form',
'options' => [
//'onsubmit'=>"ajaxSubmit(url: ".Url::toRoute(['/users/user/registration']).")";
'enctype' => 'multipart/form-data'
],
],
'elements' => $elements,
'buttons' => [
/*'buttons' => [
'submit' => ['type' => 'submit', 'value' => 'Записаться', 'class'=>"save-button sh_bt_send"]
]
]*/
];
......@@ -15,57 +15,57 @@ use \common\modules\rbac\models\AuthAssignment;
class User extends \common\components\ActiveRecordModel implements IdentityInterface
{
const PAGE_SIZE = 10;
const PAGE_SIZE = 10;
const OCCUPATION_CHIEF_IT = 1;
const OCCUPATION_MANAGER_IT = 2;
const OCCUPATION_CREATOR = 3;
const OCCUPATION_NOT_IT = 4;
const STATUS_ACTIVE = 'active';
const STATUS_NEW = 'new';
const STATUS_BLOCKED = 'blocked';
const GENDER_MAN = "man";
const GENDER_WOMAN = "woman";
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_SINGLE = 'change_password_request_mail_body_single';
const SETTING_ACTIVATE_REQUEST_DONE_MESSAGE = 'activate_request_done_message';
const SETTING_REGISTRATION_MAIL_SUBJECT = 'registration_mail_subject';
const SETTING_REGISTRATION_DONE_MESSAGE = 'registration_done_message';
const SETTING_REGISTRATION_MAIL_BODY = 'registration_mail_body';
const SCENARIO_CHANGE_PASSWORD_REQUEST = 'ChangePasswordRequest';
const SCENARIO_SEND_NEW_PASSWORD = 'SendNewPassword';
const SCENARIO_ACTIVATE_REQUEST = 'ActivateRequest';
const SCENARIO_CHANGE_PASSWORD = 'ChangePassword';
const SCENARIO_REGISTRATION = 'Registration';
const SCENARIO_UPDATE = 'Update';
const SCENARIO_CREATE = 'Create';
const SCENARIO_LOGIN = 'Login';
const SCENARIO_DELETE = 'Delete';
const SCENARIO_SEARCH = 'Search';
const SCENARIO_CSV_IMPORT = 'CSV_IMPORT';
const SCENARIO_RECOVER_PASSWORD = 'RecoverPassword';
const STATUS_ACTIVE = 'active';
const STATUS_NEW = 'new';
const STATUS_BLOCKED = 'blocked';
const GENDER_MAN = "man";
const GENDER_WOMAN = "woman";
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_SINGLE = 'change_password_request_mail_body_single';
const SETTING_ACTIVATE_REQUEST_DONE_MESSAGE = 'activate_request_done_message';
const SETTING_REGISTRATION_MAIL_SUBJECT = 'registration_mail_subject';
const SETTING_REGISTRATION_DONE_MESSAGE = 'registration_done_message';
const SETTING_REGISTRATION_MAIL_BODY = 'registration_mail_body';
const SCENARIO_CHANGE_PASSWORD_REQUEST = 'ChangePasswordRequest';
const SCENARIO_SEND_NEW_PASSWORD = 'SendNewPassword';
const SCENARIO_ACTIVATE_REQUEST = 'ActivateRequest';
const SCENARIO_CHANGE_PASSWORD = 'ChangePassword';
const SCENARIO_REGISTRATION = 'Registration';
const SCENARIO_UPDATE = 'Update';
const SCENARIO_CREATE = 'Create';
const SCENARIO_LOGIN = 'Login';
const SCENARIO_DELETE = 'Delete';
const SCENARIO_SEARCH = 'Search';
const SCENARIO_CSV_IMPORT = 'CSV_IMPORT';
const SCENARIO_RECOVER_PASSWORD = 'RecoverPassword';
// public $email;
public $role;
public $password_c;
public $captcha;
public $remember_me = false;
public $activate_error;
public $role;
public $password_c;
public $captcha;
public $remember_me = false;
public $activate_error;
// public $activate_code;
// public $checked;
public $csv_file;
public $send_email;
public $generate_new;
public $csv_file;
public $send_email;
public $generate_new;
// public $fio;
// public $phone;
// public $mobile_phone;
// public $skype;
public $tmp; //for external using. no delete!
public $tmp; //for external using. no delete!
// public $post;
......@@ -76,19 +76,19 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
self::OCCUPATION_NOT_IT => 'Не работаю в IT',
];
public function behaviors()
{
return [
'eavAttributes' => [
'class' => '\lagman\eav\EavBehavior',
'valueClass' => 'User',
],
'sort' => [
'class' => SortableGridBehavior::className(),
'sortableAttribute' => 'sort'
],
];
}
public function behaviors()
{
return [
'eavAttributes' => [
'class' => '\lagman\eav\EavBehavior',
'valueClass' => 'User',
],
'sort' => [
'class' => SortableGridBehavior::className(),
'sortableAttribute' => 'sort'
],
];
}
public function attributeLabels()
{
......@@ -126,11 +126,12 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
], 'message' => 'Пожалуйста, укажите корректный e-mail адрес'],
[['send_email'], 'safe'],
[['fio','name', 'surname'], 'safe', 'on' => [
self::SCENARIO_REGISTRATION,
self::SCENARIO_CREATE,
], 'message' => 'Пожалуйста, укажите Ваше имя'],
[['phone'], 'required', 'on' => [
[['name'], 'required', 'on' => [
self::SCENARIO_REGISTRATION,
], 'message' => 'Пожалуйста, укажите Ваше имя'],
[['phone'], 'required', 'on' => [
self::SCENARIO_CREATE,
], 'message' => 'Пожалуйста, укажите Ваш номер телефона'],
[['phone'], 'string', 'max'=> 50],
......
......@@ -8827,7 +8827,8 @@ a.kurs_bt:active {
color: #908505;
border: none;
border-bottom: 4px solid #D2BF00;
margin: 0 auto;
padding-top: 20px;
/* margin: 0 auto;*/
}
.sh_bt_send:hover, .sh_bt_send:focus {
background-image: linear-gradient(to top, #fde654 0%, #fef77d 100%);
......@@ -11464,4 +11465,11 @@ h6 {
margin-bottom: 15px;
color: #698387;
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(){
// prepare the form when the DOM is ready
$(document).ready(function() {
var options = {
//target: '#output2', // target element(s) to be updated with server response
beforeSubmit: showRequest, // pre-submit callback
success: showResponse, // post-submit callback
// other available options:
url: '/users/user/registration' // override for form's 'action' attribute
//type: type // 'get' or 'post', override for form's 'method' attribute
//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
url: '/users/user/registration', // override for form's 'action' attribute
dataType: 'json' // 'xml', 'script', or 'json' (expected server response type)
};
// bind to the form's submit event
$('#sh_reg_form').submit(function() {
// inside event callbacks 'this' is the DOM element so we first
// wrap it in a jQuery object and then invoke ajaxSubmit
$('.errors-reg').append('');
$(this).ajaxSubmit(options);
// !!! Important !!!
// always return false to prevent standard browser submit and page navigation
return false;
});
$(".submit_form_reg").on('click', function () {
$('#sh_reg_form').ajaxSubmit(options);
return false;
});
});
// pre-submit callback
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);
// 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;
}
// post-submit callback
function showResponse(responseText, statusText, xhr, $form) {
// for normal html responses, the first argument to the success callback
// is the XMLHttpRequest object's responseText property
// if the ajaxSubmit method was passed an Options Object with the dataType
// property set to 'xml' then the first argument to the success callback
// is the XMLHttpRequest object's responseXML property
// if the ajaxSubmit method was passed an Options Object with the dataType
// property set to 'json' then the first argument to the success callback
// 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.');
if (responseText.errors){
$.each(responseText.errors, function(key,value) {
$('.errors-reg').append(value+'<br>');
$('.field-user-'+key).addClass('has-error');
});
}
else{
console.log(responseText.success);
$('#sh_reg_form').html('Регистрация успешно завершена. Вам отправлено письмо для активации аккаунта.');
}
}
\ 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