-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Password resetting #74
Merged
corp-0
merged 47 commits into
unitystation:develop
from
MaxIsJoe:forgetmepasswordackackackack
Jan 23, 2024
+180
−1
Merged
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
5fe0244
god help me
MaxIsJoe e7607bf
Update src/accounts/api/views.py
MaxIsJoe 4b83cfa
fix save error
MaxIsJoe 8d95ffb
remove account identifier from url
MaxIsJoe 1234969
Update views.py
MaxIsJoe 105cddf
fixes multiple arguments error
MaxIsJoe f20604b
random token
MaxIsJoe 6264445
cacwka
MaxIsJoe c06af96
password resting works, woohoo!
MaxIsJoe 833e69e
Update views.py
MaxIsJoe 88614c8
token time lifespan
MaxIsJoe cab7dff
Update serializers.py
MaxIsJoe 42b6a81
Update serializers.py
MaxIsJoe ad6fef7
Update models.py
MaxIsJoe edffbae
Update models.py
MaxIsJoe fd41b67
hour
MaxIsJoe 395f686
view request changes
MaxIsJoe e9feb9f
name changes
MaxIsJoe 498df54
remove some logs
MaxIsJoe 4b60944
Update urls.py
MaxIsJoe eead438
Update urls.py
MaxIsJoe 9c59243
Update urls.py
MaxIsJoe d8faa5e
precommit
MaxIsJoe 69b8684
Update urls.py
MaxIsJoe 34743a4
Update serializers.py
MaxIsJoe bde9f50
Update models.py
MaxIsJoe d32bef7
Update models.py
MaxIsJoe 647c29a
e
MaxIsJoe ab501dc
email
MaxIsJoe 7cb9285
Update views.py
MaxIsJoe 6d03d36
Update views.py
MaxIsJoe 341bf19
Update serializers.py
MaxIsJoe d83f73a
ee
MaxIsJoe 95e1694
Update views.py
MaxIsJoe e0b3115
link correct
MaxIsJoe ada8c01
get email
MaxIsJoe 27027ce
Update serializers.py
MaxIsJoe 010ce67
password request
MaxIsJoe eed561a
Update views.py
MaxIsJoe c16d236
Update views.py
MaxIsJoe 1cdbe5d
fixes an error with subscriptables
MaxIsJoe 07fc838
Update src/accounts/api/serializers.py
MaxIsJoe 1ccc17e
Merge remote-tracking branch 'upstream/develop' into forgetmepassword…
MaxIsJoe da3cef4
email working
MaxIsJoe 9fcc842
Update serializers.py
MaxIsJoe 7a04f96
Create 0001_squashed_0002_passwordresetrequest.py
MaxIsJoe f89154c
chore: make a single migration for the new model
corp-0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,6 +8,14 @@ | |||||
from rest_framework.permissions import AllowAny | ||||||
from rest_framework.response import Response | ||||||
from rest_framework.serializers import ValidationError | ||||||
from django.shortcuts import get_object_or_404 | ||||||
from django.contrib.auth.models import User | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
use our Account class instead of the base User class. |
||||||
from django.contrib.auth.tokens import default_token_generator | ||||||
from django.utils.encoding import force_text | ||||||
from django.utils.http import urlsafe_base64_decode | ||||||
from django.contrib.auth.views import PasswordResetConfirmView | ||||||
from django.contrib.auth.forms import SetPasswordForm | ||||||
from django.http import HttpResponse | ||||||
|
||||||
from ..exceptions import MissingMailConfirmationError | ||||||
from ..models import Account | ||||||
|
@@ -17,6 +25,8 @@ | |||||
RegisterAccountSerializer, | ||||||
UpdateAccountSerializer, | ||||||
VerifyAccountSerializer, | ||||||
ChangePasswordSerializer, | ||||||
ChangePasswordRequestSerializer, | ||||||
) | ||||||
|
||||||
|
||||||
|
@@ -181,3 +191,34 @@ def post(self, request): | |||||
public_data = PublicAccountDataSerializer(account).data | ||||||
|
||||||
return Response(public_data, status=status.HTTP_200_OK) | ||||||
|
||||||
class ChangePasswordView(GenericAPIView): | ||||||
corp-0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
permission_classes = (AllowAny,) | ||||||
serializer_class = ChangePasswordSerializer | ||||||
|
||||||
def get(self, unique_identifier, token): | ||||||
try: | ||||||
account = Account.objects.get(unique_identifier) | ||||||
except (TypeError, ValueError, OverflowError, User.DoesNotExist): | ||||||
return Response({'detail': 'Invalid link or expired.'}, status=status.HTTP_400_BAD_REQUEST) | ||||||
|
||||||
if account is not None and default_token_generator.check_token(account, token): | ||||||
return Response({'detail': 'Password reset successfully.'}, status=status.HTTP_200_OK) | ||||||
else: | ||||||
return Response({'detail': 'Invalid link or expired.'}, status=status.HTTP_400_BAD_REQUEST) | ||||||
|
||||||
class RequestPasswordResetView(GenericAPIView): | ||||||
permission_classes = (AllowAny,) | ||||||
serializer_class = ChangePasswordRequestSerializer | ||||||
|
||||||
def post(self, request): | ||||||
serializer = self.serializer_class(data=request.data) | ||||||
try: | ||||||
serializer.is_valid(raise_exception=True) | ||||||
except ValidationError as e: | ||||||
return Response(data={"error V": str(e)}, status=e.status_code) | ||||||
corp-0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
except Exception as e: | ||||||
return Response(data={"error E": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) | ||||||
serializer.create(serializer.validated_data) | ||||||
MaxIsJoe marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
#return Response(data={"sucess test" : "soup"}, status=status.HTTP_200_OK) | ||||||
return Response(data={"sucess" : str(serializer)}, status=status.HTTP_200_OK) | ||||||
MaxIsJoe marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 3.2.22 on 2024-01-13 17:03 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('accounts', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='PasswordResetRequest', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('token', models.UUIDField()), | ||
('account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 3.2.22 on 2024-01-13 18:58 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('accounts', '0002_passwordresetrequest'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='PasswordResetRequestModel', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('token', models.UUIDField()), | ||
('account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
migrations.DeleteModel( | ||
name='PasswordResetRequest', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.