Refactor user password update logic: Only update password and token if a new password is provided. Update frontend to conditionally include password in the request data, improving user experience and data handling.

Fix: https://github.com/usmannasir/cyberpanel/issues/1509
This commit is contained in:
Master3395
2025-09-21 01:07:54 +02:00
parent 13677f0d6d
commit 8dc6181de3
2 changed files with 11 additions and 5 deletions

View File

@@ -305,11 +305,15 @@ app.controller('modifyUser', function ($scope, $http) {
firstName: firstName, firstName: firstName,
lastName: lastName, lastName: lastName,
email: email, email: email,
passwordByPass: password,
securityLevel: $scope.securityLevel, securityLevel: $scope.securityLevel,
twofa: $scope.twofa twofa: $scope.twofa
}; };
// Only include password if it's provided and not empty
if (password && password.trim()) {
data.passwordByPass = password;
}
var config = { var config = {
headers: { headers: {
'X-CSRFToken': getCookie('csrftoken') 'X-CSRFToken': getCookie('csrftoken')

View File

@@ -408,14 +408,16 @@ def saveModifications(request):
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
token = hashPassword.generateToken(accountUsername, data['passwordByPass']) # Only update password if a new one is provided
password = hashPassword.hash_password(data['passwordByPass']) if 'passwordByPass' in data and data['passwordByPass'] and data['passwordByPass'].strip():
token = hashPassword.generateToken(accountUsername, data['passwordByPass'])
password = hashPassword.hash_password(data['passwordByPass'])
user.password = password
user.token = token
user.firstName = firstName user.firstName = firstName
user.lastName = lastName user.lastName = lastName
user.email = email user.email = email
user.password = password
user.token = token
user.type = 0 user.type = 0
user.twoFA = twofa user.twoFA = twofa