backend change password
This commit is contained in:
parent
8322d58066
commit
dfbcdbae6e
@ -65,6 +65,28 @@ class UserCardController extends Controller
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function actionPassword($id)
|
||||||
|
{
|
||||||
|
$user_card = UserCard::findOne($id);
|
||||||
|
$model = User::findOne(['id' => $user_card->id_user]);
|
||||||
|
|
||||||
|
return $this->render('password', [
|
||||||
|
'model' => $model,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionAjax() {
|
||||||
|
if(Yii::$app->request->isAjax) {
|
||||||
|
$id = $_POST['id'];
|
||||||
|
$password = $_POST['password'];
|
||||||
|
|
||||||
|
$user_card = UserCard::findOne($id);
|
||||||
|
$user = User::findOne(['id' => $user_card->id_user]);
|
||||||
|
$user->password = $password;
|
||||||
|
$user->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays a single UserCard model.
|
* Displays a single UserCard model.
|
||||||
* @param integer $id
|
* @param integer $id
|
||||||
|
22
backend/modules/card/views/user-card/password.php
Normal file
22
backend/modules/card/views/user-card/password.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\widgets\ActiveForm;
|
||||||
|
?>
|
||||||
|
|
||||||
|
<?php $form = ActiveForm::begin([
|
||||||
|
'id' => 'password-form',
|
||||||
|
'enableClientValidation' => true,
|
||||||
|
'enableAjaxValidation' => false,
|
||||||
|
'method' => 'post',
|
||||||
|
]); ?>
|
||||||
|
|
||||||
|
<h4>Введите новый пароль</h4>
|
||||||
|
|
||||||
|
<?= Html::input('text', 'password', '', ['class' => 'form-control custom-input']) ?>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
|
||||||
|
<?php echo ' ' . Html::button('Сгенерировать', ['class' => 'btn btn-success generate']); ?>
|
||||||
|
|
||||||
|
<?php ActiveForm::end(); ?>
|
@ -12,6 +12,9 @@ $this->params['breadcrumbs'][] = 'Редактировать';
|
|||||||
?>
|
?>
|
||||||
<div class="user-card-update">
|
<div class="user-card-update">
|
||||||
|
|
||||||
|
<?php echo Html::a('Изменить пароль', ['password', 'id' => $model->id], ['class' => 'btn btn-success']);
|
||||||
|
?>
|
||||||
|
|
||||||
<?= $this->render('_form', [
|
<?= $this->render('_form', [
|
||||||
'model' => $model,
|
'model' => $model,
|
||||||
]) ?>
|
]) ?>
|
||||||
|
@ -4,4 +4,44 @@ $(function(){
|
|||||||
history.pushState({}, '', month);
|
history.pushState({}, '', month);
|
||||||
$.pjax.reload({container:"#reload"});
|
$.pjax.reload({container:"#reload"});
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(document).on("beforeSubmit", "#password-form", function (e) {
|
||||||
|
let form = $(this);
|
||||||
|
let formData = form.serialize();
|
||||||
|
let location = document.location.href;
|
||||||
|
location = location.split('=');
|
||||||
|
formData = formData.split('=');
|
||||||
|
console.log(formData[2]);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: 'ajax',
|
||||||
|
type: 'POST',
|
||||||
|
data: {
|
||||||
|
id: location[1],
|
||||||
|
password: formData[2],
|
||||||
|
},
|
||||||
|
password: formData[2],
|
||||||
|
success: function (response) {
|
||||||
|
window.location.replace('index');
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
$('.generate').on('click', function () {
|
||||||
|
$(".custom-input").val(gen_password(8));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function gen_password(len){
|
||||||
|
var password = "";
|
||||||
|
var symbols = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
|
for (var i = 0; i < len; i++){
|
||||||
|
password += symbols.charAt(Math.floor(Math.random() * symbols.length));
|
||||||
|
}
|
||||||
|
return password;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user