diff options
author | Andrew Godwin | 2022-11-17 19:36:25 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-17 19:36:25 -0700 |
commit | adf2449d373bcd07e2b0ce557beeb1f49d1894e4 (patch) | |
tree | f9178fded8a38d02546b098ebb71b3797eb18964 /users | |
parent | 6adfdbabe0d44c17f32abc9d48a6e252e2a0792e (diff) | |
download | takahe-adf2449d373bcd07e2b0ce557beeb1f49d1894e4.tar.gz takahe-adf2449d373bcd07e2b0ce557beeb1f49d1894e4.tar.bz2 takahe-adf2449d373bcd07e2b0ce557beeb1f49d1894e4.zip |
Add the user settings page too
Diffstat (limited to 'users')
-rw-r--r-- | users/views/auth.py | 35 | ||||
-rw-r--r-- | users/views/settings.py | 27 |
2 files changed, 54 insertions, 8 deletions
diff --git a/users/views/auth.py b/users/views/auth.py index 7d4040b..7f51d45 100644 --- a/users/views/auth.py +++ b/users/views/auth.py @@ -44,9 +44,38 @@ class Signup(FormView): ) -class Reset(FormView): +class TriggerReset(FormView): - template_name = "auth/reset.html" + template_name = "auth/trigger_reset.html" + + class form_class(forms.Form): + + email = forms.EmailField( + help_text="We will send a reset link to this email", + ) + + def clean_email(self): + email = self.cleaned_data.get("email").lower() + if not email: + return + if not User.objects.filter(email=email).exists(): + raise forms.ValidationError("This email does not have an account") + return email + + def form_valid(self, form): + PasswordReset.create_for_user( + User.objects.get(email=form.cleaned_data["email"]) + ) + return render( + self.request, + "auth/trigger_reset_success.html", + {"email": form.cleaned_data["email"]}, + ) + + +class PerformReset(FormView): + + template_name = "auth/perform_reset.html" class form_class(forms.Form): @@ -81,7 +110,7 @@ class Reset(FormView): self.reset.delete() return render( self.request, - "auth/reset_success.html", + "auth/perform_reset_success.html", {"email": self.reset.user.email}, ) diff --git a/users/views/settings.py b/users/views/settings.py index d823676..fd138c2 100644 --- a/users/views/settings.py +++ b/users/views/settings.py @@ -126,6 +126,7 @@ class ProfilePage(FormView): """ template_name = "settings/profile.html" + extra_context = {"section": "profile"} class form_class(forms.Form): name = forms.CharField(max_length=500) @@ -150,11 +151,6 @@ class ProfilePage(FormView): "image": self.request.identity.image.url, } - def get_context_data(self): - context = super().get_context_data() - context["section"] = "profile" - return context - def form_valid(self, form): # Update identity name and summary self.request.identity.name = form.cleaned_data["name"] @@ -174,3 +170,24 @@ class ProfilePage(FormView): self.request.identity.image = image self.request.identity.save() return redirect(".") + + +@method_decorator(identity_required, name="dispatch") +class SecurityPage(FormView): + """ + Lets the identity's profile be edited + """ + + template_name = "settings/login_security.html" + extra_context = {"section": "security"} + + class form_class(forms.Form): + email = forms.EmailField( + disabled=True, + help_text="Your email address cannot be changed yet.", + ) + + def get_initial(self): + return {"email": self.request.user.email} + + template_name = "settings/login_security.html" |