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