Skip to content

Commit

Permalink
Add admin function to resend activation email
Browse files Browse the repository at this point in the history
  • Loading branch information
stefankoegl committed Aug 15, 2018
1 parent 77c5314 commit 6a53bdd
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
1 change: 1 addition & 0 deletions mygpo/administration/templates/admin/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ <h1>{% trans "Admin Area" %}</h1>
<li><i class="icon-bar-chart"></i> <a href="{% url "useragents" %}">{% trans "User-Agent Stats" %}</a></li>
<li><i class="icon-signal"></i> <a href="{% url "stats" %}">{% trans "General Stats" %}</a> (<a href="{% url "stats-json" %}">{% trans "JSON" %}</a>)</li>
<li><i class="icon-certificate"></i> <a href="{% url "admin-activate-user" %}">{% trans "Activate User" %}</a></li>
<li><i class="icon-certificate"></i> <a href="{% url "admin-resend-activation" %}">{% trans "Resend Activation Email" %}</a></li>
<li><i class="icon-user"></i> <a href="{% url "admin-make-publisher-input" %}">{% trans "Assign Publisher Permissions" %}</a></li>
</ul>

Expand Down
41 changes: 41 additions & 0 deletions mygpo/administration/templates/admin/resend-acivation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% extends "base.html" %}
{% load i18n %}
{% load podcasts %}

{% load menu %}
{% block mainmenu %}{{ "/admin/"|main_menu }}{% endblock %}
{% block sectionmenu %}{{ "/admin/"|section_menu:"Admin" }}{% endblock %}

{% block title %}{% trans "Activate User" %}{% endblock %}

{% block header %}
<h1>{% trans "Resend Activation email" %}</h1>
{% endblock %}

{% block content %}
<form class="form-horizontal" method="post" action="{% url "admin-resend-activation" %}">
{% csrf_token %}

<div class="control-group">
<label class="control-label" for="username">{% trans "Username" %}</label>
<div class="controls">
<input name="username" type="text" id="username" placeholder="Username">
</div>
</div>

<div class="control-group">
<label class="control-label" for="email">{% trans "Email" %}</label>
<div class="controls">
<input name="email" type="text" id="email" placeholder="Email">
</div>
</div>

<div class="control-group">
<div class="controls">
<button type="submit" class="btn">{% trans "Resend" %}</button>
</div>
</div>
</form>

{% endblock %}

4 changes: 4 additions & 0 deletions mygpo/administration/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
views.ActivateUserView.as_view(),
name='admin-activate-user'),

path('resend-activation-email',
views.ResendActivationEmail.as_view(),
name='admin-resend-activation'),

path('make-publisher/input',
views.MakePublisherInput.as_view(),
name='admin-make-publisher-input'),
Expand Down
39 changes: 38 additions & 1 deletion mygpo/administration/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from mygpo.administration.group import PodcastGrouper
from mygpo.maintenance.merge import PodcastMerger, IncorrectMergeException
from mygpo.administration.clients import UserAgentStats, ClientStats
from mygpo.users.views.registration import send_activation_email
from mygpo.administration.tasks import merge_podcasts
from mygpo.utils import get_git_head
from mygpo.data.models import PodcastUpdateResult
Expand Down Expand Up @@ -330,7 +331,7 @@ def post(self, request):
return HttpResponseRedirect(reverse('admin-activate-user'))

try:
user = UserProxy.objects.by_username_or_email(username, email)
user = UserProxy.objects.all().by_username_or_email(username, email)
except UserProxy.DoesNotExist:
messages.error(request, _('No user found'))
return HttpResponseRedirect(reverse('admin-activate-user'))
Expand All @@ -342,6 +343,42 @@ def post(self, request):
return HttpResponseRedirect(reverse('admin-activate-user'))


class ResendActivationEmail(AdminView):
""" Resends the users activation email """

template_name = 'admin/resend-acivation.html'

def get(self, request):
return self.render_to_response({})

def post(self, request):

username = request.POST.get('username')
email = request.POST.get('email')

if not (username or email):
messages.error(request,
_('Provide either username or email address'))
return HttpResponseRedirect(reverse('admin-resend-activation'))

try:
user = UserProxy.objects.all().by_username_or_email(username, email)
except UserProxy.DoesNotExist:
messages.error(request, _('No user found'))
return HttpResponseRedirect(reverse('admin-resend-activation'))

if user.is_active:
messages.success(request, 'User {username} is already activated')

else:
send_activation_email(user, request)
messages.success(request,
_('Email for {username} ({email}) resent'.format(
username=user.username, email=user.email)))

return HttpResponseRedirect(reverse('admin-resend-activation'))



class MakePublisherInput(AdminView):
""" Get all information necessary for making someone publisher """
Expand Down

0 comments on commit 6a53bdd

Please sign in to comment.