MCPcopy
hub / github.com/1Panel-dev/MaxKB / re_password

Method re_password

apps/users/serializers/user.py:539–556  ·  view source on GitHub ↗
(self, instance, with_valid=True)

Source from the content-addressed store, hash-verified

537 return UserInstanceSerializer(user).data
538
539 def re_password(self, instance, with_valid=True):
540 if with_valid:
541 self.is_valid(raise_exception=True)
542 encrypted_data = instance.get("encryptedData", "")
543 if encrypted_data:
544 try:
545 decrypted_raw = decrypt(encrypted_data)
546 # decrypt 可能返回非 JSON 字符串,防护解析异常
547 decrypted_data = json.loads(decrypted_raw) if decrypted_raw else {}
548 if isinstance(decrypted_data, dict):
549 instance.update(decrypted_data)
550 except Exception as e:
551 raise AppApiException(500, _("Invalid encrypted data"))
552 UserManageSerializer.RePasswordInstance(data=instance).is_valid(raise_exception=True)
553 user = User.objects.filter(id=self.data.get('id')).first()
554 user.password = password_encrypt(instance.get('password'))
555 user.save()
556 return True
557
558 def get_user_list(self, workspace_id, nick_name):
559 """

Callers 1

putMethod · 0.80

Calls 7

is_validMethod · 0.95
decryptFunction · 0.90
AppApiExceptionClass · 0.90
password_encryptFunction · 0.90
getMethod · 0.45
is_validMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected