Set password from bootbox

This commit is contained in:
amcmanu3 2023-10-07 22:10:15 -04:00
parent b1c5836b9b
commit 39d78b92e6
2 changed files with 67 additions and 14 deletions

View File

@ -312,27 +312,65 @@
{% block js %}
<script>
$(".edit_password").on("click", function(){
function validateForm() {
let password0 = document.getElementById("password0").value;
let password1 = document.getElementById("password1").value;
if (password0 != password1) {
$('.passwords-match').popover('show');
$('.popover-body').click(function () {
$('.passwords-match').popover("hide");
});
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
$("#password0").css("outline", "1px solid red");
$("#password1").css("outline", "1px solid red");
return false;
} else {
return password1;
}
}
$(".edit_password").on("click", async function(){
const token = getCookie("_xsrf");
let user_id = $(this).data('id');
bootbox.confirm(`<form class="form" id='infos' action=''>\
<div class="form-group">
<label for="current_password">Current Password</label>
<input class="form-control" type='password' name='current_password' /><br/>\
</div>
<div class="form-group">
<label for="new_password">New Password</label>
<input class="form-control" type='password' name='new_password' /></br>\
<input class="form-control" type='password' id="password0" name='new_password' /></br>\
</div>
<div class="form-group">
<label for="confirm_password">Confirm Password</label>
<input class="form-control" type='password' name='confirm_password' />\
<input class="form-control" type='password' id="password1" name='confirm_password' />\
</div>
</form>`, function(result) {
if(result)
$('#infos').submit();
</form>`, async function(result) {
if(result){
password = validateForm();
if (!password){
return;
}
let res = await fetch(`/api/v2/users/${user_id}`, {
method: 'PATCH',
headers: {
'X-XSRFToken': token
},
body: JSON.stringify({"password": password}),
});
let responseData = await res.json();
if (responseData.status === "ok") {
console.log(responseData.data)
} else {
bootbox.alert({
title: responseData.status,
message: responseData.error
});
}
}
});
});
$(".edit_user").on("click", function(){
const token = getCookie("_xsrf");
let username = $(this).data('name');
let user_id = $(this).data('id');
bootbox.confirm(`<form class="form" id='infos' action=''>\
<div class="form-group">
<label for="username">Username</label>

View File

@ -71,6 +71,7 @@ data['lang']) }}{% end %}
data['lang']) }}</h4>
</div>
<div class="card-body">
{% if data['new_user'] %}
<div class="form-group">
<label class="form-label" for="username">{{ translate('userConfig', 'userName', data['lang'])
}}<small class="text-muted ml-1"> - {{ translate('userConfig', 'userNameDesc', data['lang'])
@ -98,6 +99,15 @@ data['lang']) }}{% end %}
data-content="{{ translate('panelConfig', 'match', data['lang']) }}" ,
data-placement="right"></span>
</div>
{% else %}
<div class="form-group">
<label class="form-label" for="username">{{ translate('userConfig', 'userName', data['lang'])
}}<small class="text-muted ml-1"> - {{ translate('userConfig', 'userNameDesc', data['lang'])
}}</small> </label>
<input type="text" class="form-control" name="username" id="username" autocomplete="off"
data-lpignore="true" value="{{ data['user']['username'] }}" placeholder="User Name" disabled>
</div>
{% end %}
<div class="form-group">
<label class="form-label" for="email">{{ translate('userConfig', 'gravEmail', data['lang'])
}}<small class="text-muted ml-1"> - {{ translate('userConfig', 'gravDesc', data['lang'])
@ -391,10 +401,13 @@ data['lang']) }}{% end %}
const userId = new URLSearchParams(document.location.search).get('id')
$("#user_form").on("submit", async function (e) {
e.preventDefault();
let password = validateForm();
if (!password){
return;
let password = null;
if(!userId){
password = validateForm();
}
if (!password){
return;
}
const token = getCookie("_xsrf")
let userForm = document.getElementById("user_form");
@ -427,9 +440,11 @@ data['lang']) }}{% end %}
if ($("#permissions").length){
formDataObject.permissions = permissions;
}
if(typeof password === "string"){
if (userId === null){
if(typeof password === "string"){
formDataObject.password = password;
}
}
formDataObject.enabled = $("#enabled").is(":checked");
if ($("#superuser").is(":enabled")){
formDataObject.superuser = $("#superuser").is(":checked");