Skip to content

Commit

Permalink
fix logout form
Browse files Browse the repository at this point in the history
  • Loading branch information
sgmdlt committed Dec 27, 2024
1 parent 514047a commit 6da2a17
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
38 changes: 20 additions & 18 deletions contributors/views/user_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,37 @@ class ChangeTokenView(
):
"""Changing user git_hub token page view."""

template_name = 'user_settings.html'
not_auth_msg = _('Please log in with your GitHub')
no_permission_msg = (
_("You haven't got permission to access this section")
)
redirect_url = reverse_lazy('contributors:home')
template_name = "contributor/user_settings.html"
not_auth_msg = _("Please log in with your GitHub")
no_permission_msg = _("You haven't got permission to access this section")
redirect_url = reverse_lazy("contributors:home")

def get_context_data(self, **kwargs):
"""Add additional context for the settings."""
context = super().get_context_data(**kwargs)
context['user'] = self.request.user
context["user"] = self.request.user
return context

def post(self, request, *args, **kwargs):
"""Handle form submission."""
form = UserTokenForm(request.POST)
if form.is_valid():
user = request.user
github_token = form.cleaned_data['github_token']
github_token = form.cleaned_data["github_token"]
user.github_token = github_token
user.save()
messages.success(request, _('GitHub token changed successfully'))
return redirect(reverse_lazy(
'contributors:user_settings',
kwargs={'slug': kwargs.get('slug')},
))
messages.success(request, _("GitHub token changed successfully"))
return redirect(
reverse_lazy(
"contributors:user_settings",
kwargs={"slug": kwargs.get("slug")},
)
)

messages.error(request, _('An error occurred. Please try again'))
return redirect(reverse_lazy(
'contributors:user_settings',
kwargs={'slug': kwargs.get('slug')},
))
messages.error(request, _("An error occurred. Please try again"))
return redirect(
reverse_lazy(
"contributors:user_settings",
kwargs={"slug": kwargs.get("slug")},
)
)
5 changes: 4 additions & 1 deletion templates/components/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@
{% if user.contributor %}
<a class="dropdown-item" href="{% url 'contributors:user_settings' slug=user.contributor.login %}">{% trans "Settings" %}</a>
{% endif %}
<a class="dropdown-item" href="{% url 'logout' %}">{% trans "Log out" %}</a>
<form class="dropdown-item" method="post" action="{% url 'logout' %}">
{% csrf_token %}
<button type="submit">{% trans "Log out" %}</button>
</form>
</div>
</li>
{% else %}
Expand Down

0 comments on commit 6da2a17

Please sign in to comment.