fix login api
This commit is contained in:
@@ -5,3 +5,5 @@ CELERY_BROKER_URL = 'redis://redis:6379/0'
|
||||
CELERY_ACCEPT_CONTENT = ['json']
|
||||
CELERY_TASK_SERIALIZER = 'json'
|
||||
CELERY_TIMEZONE = settings.TIME_ZONE
|
||||
|
||||
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
||||
|
||||
3
core/apps/accounts/cache/user.py
vendored
3
core/apps/accounts/cache/user.py
vendored
@@ -8,12 +8,11 @@ r = redis.StrictRedis.from_url(env.str('REDIS_URL'))
|
||||
|
||||
|
||||
def cache_user_credentials(phone_number, password, time):
|
||||
hashed_password = make_password(password)
|
||||
key = f"user_credentials:{phone_number}"
|
||||
|
||||
r.hmset(key, {
|
||||
"phone": phone_number,
|
||||
"password": hashed_password
|
||||
"password": password
|
||||
})
|
||||
|
||||
r.expire(key, time)
|
||||
|
||||
@@ -19,9 +19,8 @@ class LoginSerializer(serializers.Serializer):
|
||||
user = User.objects.get(phone=data.get('phone'))
|
||||
except User.DoesNotExist:
|
||||
raise serializers.ValidationError({'detail': 'User not found'})
|
||||
else:
|
||||
if not user.check_password(data.get('password')):
|
||||
raise serializers.ValidationError({'detail': 'User not found'})
|
||||
raise serializers.ValidationError({'detail': 'User not found, password'})
|
||||
data['user'] = user
|
||||
return data
|
||||
|
||||
|
||||
@@ -56,7 +56,9 @@ class ConfirUserApiView(generics.GenericAPIView):
|
||||
data = get_user_creadentials(phone)
|
||||
if not data:
|
||||
return error_message("Not found", 404)
|
||||
user = User.objects.create_user(phone=data['phone'], password=data['password'])
|
||||
user = User.objects.create_user(phone=data['phone'])
|
||||
user.set_password(data['password'])
|
||||
user.save()
|
||||
confirmation.is_verify = True
|
||||
confirmation.save()
|
||||
token = RefreshToken.for_user(user)
|
||||
|
||||
Reference in New Issue
Block a user