mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2025-01-31 21:06:10 +01:00
Set password from bootbox
This commit is contained in:
parent
b1c5836b9b
commit
39d78b92e6
@ -312,27 +312,65 @@
|
|||||||
|
|
||||||
{% block js %}
|
{% block js %}
|
||||||
<script>
|
<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=''>\
|
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">
|
<div class="form-group">
|
||||||
<label for="new_password">New Password</label>
|
<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>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="confirm_password">Confirm Password</label>
|
<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>
|
</div>
|
||||||
</form>`, function(result) {
|
</form>`, async function(result) {
|
||||||
if(result)
|
if(result){
|
||||||
$('#infos').submit();
|
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(){
|
$(".edit_user").on("click", function(){
|
||||||
|
const token = getCookie("_xsrf");
|
||||||
let username = $(this).data('name');
|
let username = $(this).data('name');
|
||||||
|
let user_id = $(this).data('id');
|
||||||
bootbox.confirm(`<form class="form" id='infos' action=''>\
|
bootbox.confirm(`<form class="form" id='infos' action=''>\
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="username">Username</label>
|
<label for="username">Username</label>
|
||||||
|
@ -71,6 +71,7 @@ data['lang']) }}{% end %}
|
|||||||
data['lang']) }}</h4>
|
data['lang']) }}</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
{% if data['new_user'] %}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="form-label" for="username">{{ translate('userConfig', 'userName', data['lang'])
|
<label class="form-label" for="username">{{ translate('userConfig', 'userName', data['lang'])
|
||||||
}}<small class="text-muted ml-1"> - {{ translate('userConfig', 'userNameDesc', 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-content="{{ translate('panelConfig', 'match', data['lang']) }}" ,
|
||||||
data-placement="right"></span>
|
data-placement="right"></span>
|
||||||
</div>
|
</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">
|
<div class="form-group">
|
||||||
<label class="form-label" for="email">{{ translate('userConfig', 'gravEmail', data['lang'])
|
<label class="form-label" for="email">{{ translate('userConfig', 'gravEmail', data['lang'])
|
||||||
}}<small class="text-muted ml-1"> - {{ translate('userConfig', 'gravDesc', 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')
|
const userId = new URLSearchParams(document.location.search).get('id')
|
||||||
$("#user_form").on("submit", async function (e) {
|
$("#user_form").on("submit", async function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let password = validateForm();
|
let password = null;
|
||||||
if (!password){
|
if(!userId){
|
||||||
return;
|
password = validateForm();
|
||||||
}
|
}
|
||||||
|
if (!password){
|
||||||
|
return;
|
||||||
|
}
|
||||||
const token = getCookie("_xsrf")
|
const token = getCookie("_xsrf")
|
||||||
let userForm = document.getElementById("user_form");
|
let userForm = document.getElementById("user_form");
|
||||||
|
|
||||||
@ -427,9 +440,11 @@ data['lang']) }}{% end %}
|
|||||||
if ($("#permissions").length){
|
if ($("#permissions").length){
|
||||||
formDataObject.permissions = permissions;
|
formDataObject.permissions = permissions;
|
||||||
}
|
}
|
||||||
if(typeof password === "string"){
|
if (userId === null){
|
||||||
|
if(typeof password === "string"){
|
||||||
formDataObject.password = password;
|
formDataObject.password = password;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
formDataObject.enabled = $("#enabled").is(":checked");
|
formDataObject.enabled = $("#enabled").is(":checked");
|
||||||
if ($("#superuser").is(":enabled")){
|
if ($("#superuser").is(":enabled")){
|
||||||
formDataObject.superuser = $("#superuser").is(":checked");
|
formDataObject.superuser = $("#superuser").is(":checked");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user