fix user password bug
This commit is contained in:
@@ -14,6 +14,7 @@ from apps.core.mixins.search_mixin import DynamicSearchMixin
|
|||||||
from apps.core.pagination import CustomPageNumberPagination
|
from apps.core.pagination import CustomPageNumberPagination
|
||||||
from apps.authorization.api.v1 import api as authorize_view
|
from apps.authorization.api.v1 import api as authorize_view
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
from django.contrib.auth.hashers import make_password
|
||||||
from apps.authentication.tools import get_token_jti
|
from apps.authentication.tools import get_token_jti
|
||||||
from common.helpers import get_organization_by_user
|
from common.helpers import get_organization_by_user
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
@@ -57,7 +58,7 @@ class UserViewSet(ModelViewSet):
|
|||||||
Customizing create user & bank account information with
|
Customizing create user & bank account information with
|
||||||
permission levels
|
permission levels
|
||||||
"""
|
"""
|
||||||
|
request.data.update({'password': make_password(request.data['password'])})
|
||||||
serializer = self.serializer_class(data=request.data)
|
serializer = self.serializer_class(data=request.data)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
user = serializer.save()
|
user = serializer.save()
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from apps.authentication.models import (
|
|||||||
BankAccountInformation
|
BankAccountInformation
|
||||||
)
|
)
|
||||||
from apps.authorization import models as authorize_models
|
from apps.authorization import models as authorize_models
|
||||||
|
from django.contrib.auth.hashers import make_password
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
|
||||||
@@ -133,8 +134,10 @@ class UserSerializer(serializers.ModelSerializer):
|
|||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
""" update user instance """
|
""" update user instance """
|
||||||
instance.username = validated_data.get('username', instance.username)
|
instance.username = validated_data.get('username', instance.username)
|
||||||
|
|
||||||
|
# control password
|
||||||
if validated_data.get('password'):
|
if validated_data.get('password'):
|
||||||
instance.password = validated_data.get('password', instance.password)
|
instance.password = make_password(validated_data.get('password', instance.password))
|
||||||
instance.first_name = validated_data.get('first_name')
|
instance.first_name = validated_data.get('first_name')
|
||||||
instance.last_name = validated_data.get('last_name')
|
instance.last_name = validated_data.get('last_name')
|
||||||
instance.is_active = validated_data.get('is_active')
|
instance.is_active = validated_data.get('is_active')
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ class User(AbstractUser, BaseModel):
|
|||||||
return f'{self.username} {self.last_name}-{self.last_login}'
|
return f'{self.username} {self.last_name}-{self.last_login}'
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.password = make_password(self.password)
|
|
||||||
super(User, self).save(*args, **kwargs)
|
super(User, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user