mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-11 07:46:10 +01:00
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:
@@ -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')
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
|
# Only update password if a new one is provided
|
||||||
|
if 'passwordByPass' in data and data['passwordByPass'] and data['passwordByPass'].strip():
|
||||||
token = hashPassword.generateToken(accountUsername, data['passwordByPass'])
|
token = hashPassword.generateToken(accountUsername, data['passwordByPass'])
|
||||||
password = hashPassword.hash_password(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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user