Skip to content

Commit d124fdd

Browse files
committed
removes the usage of password from appwrite payload
1 parent 7752ae0 commit d124fdd

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

django_appwrite/middleware.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from django.contrib.auth import authenticate, login
1+
import random
2+
import string
3+
from django.contrib.auth import authenticate
24
from django.contrib.auth import get_user_model
35
from django.conf import settings
46
from appwrite.client import Client
@@ -8,6 +10,11 @@
810
User = get_user_model()
911

1012

13+
def get_random_string(length):
14+
characters = string.ascii_letters + string.digits + string.punctuation
15+
return ''.join(random.choice(characters) for i in range(length))
16+
17+
1118
class AppwriteMiddleware(MiddlewareMixin):
1219
def __init__(self, get_response):
1320
self.get_response = get_response
@@ -57,12 +64,22 @@ def __call__(self, request, *args, **kwargs):
5764
# Get the Django user by its email
5865
user = User.objects.filter(username=user_info['email']).first()
5966

67+
# Generate a random password for the user
68+
password = get_random_string(16)
69+
6070
# If the user doesn't exist, create it
6171
if not user:
62-
user = User.objects.create_user(username=user_info['email'], password=user_info['password'], email=user_info['email'])
72+
user = User.objects.create_user(
73+
username=user_info['email'],
74+
password=password,
75+
email=user_info['email'])
76+
77+
# Set the user's password to the random password and save it
78+
user.set_password(password)
79+
user.save()
6380

6481
# Authenticate the user using the email as the username
65-
user = authenticate(request, username=user_info['email'], password=user_info['password'])
82+
user = authenticate(request, username=user_info['email'], password=password)
6683

6784
# If the authentication was successful, log the user in
6885
if user:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name='django-appwrite',
9-
version='1.0.0',
9+
version='1.0.1',
1010
description='Django Middleware to authenticate users with Appwrite',
1111
long_description=long_description,
1212
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)