Skip to content
This repository has been archived by the owner on Jul 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #786 from nidico/feature-overlays-join-validate
Browse files Browse the repository at this point in the history
Intermediate show and validate pages
  • Loading branch information
Nicolas Dietrich committed Mar 4, 2014
2 parents e2caab3 + c35a0f4 commit 7a4de5e
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 71 deletions.
3 changes: 3 additions & 0 deletions src/adhocracy/config/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def make_map(config):
'revert': 'GET',
'reset': 'GET',
'activate': 'GET',
'ask_activate': 'GET',
'pending_activate': 'GET',
'resend': 'GET',
'set_password': 'POST',
'generate_welcome_link': 'POST'},
Expand Down Expand Up @@ -462,6 +464,7 @@ def make_map(config):
conditions=dict(method=['POST']))

map.resource('instance', 'instance', member={'join': 'GET',
'ask_join': 'GET',
'leave': 'POST',
'filter': 'GET',
'ask_leave': 'GET',
Expand Down
6 changes: 6 additions & 0 deletions src/adhocracy/controllers/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,12 @@ def delete(self, id, format='html'):
c.page_instance.label,
force_path='/')

@RequireInstance
def ask_join(self, id, format='html'):
c.page_instance = self._get_current_instance(id)
require.instance.join(c.page_instance)
return render('/instance/ask_join.html')

@RequireInstance
@csrf.RequireInternalRequest()
def join(self, id, format='html'):
Expand Down
53 changes: 48 additions & 5 deletions src/adhocracy/controllers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,13 +726,25 @@ def activate(self, id):
instance_filter=False)
code = self.form_result.get('c')

# If activate_came_from is set, we assume that we've tried to do
# validate email address during doing some other action.
activate_came_from = session.get('activate_came_from')
if activate_came_from:
c.came_from = activate_came_from
del session['activate_came_from']
success_url = activate_came_from
no_success_url = h.validate_redirect_url()
else:
success_url = h.entity_url(c.page_user)
no_success_url = h.entity_url(c.page_user)

if c.page_user.activation_code != code:
h.flash(_("The activation code is invalid. Please have it "
"resent."), 'error')
redirect(h.entity_url(c.page_user))
redirect(no_success_url)
if c.page_user.activation_code is None:
h.flash(_(u'Thank you, The address is already activated.'))
redirect(h.entity_url(c.page_user))
redirect(success_url)

c.page_user.activation_code = None
model.meta.Session.commit()
Expand All @@ -751,9 +763,33 @@ def activate(self, id):
redirect(h.user.post_register_url(c.page_user))
else:
h.flash(_("Your email has been confirmed."), 'success')
redirect(h.entity_url(c.page_user))
redirect(success_url)

redirect(h.entity_url(c.page_user))
redirect(success_url)

def ask_activate(self, id):
c.page_user = get_entity_or_abort(model.User, id,
instance_filter=False)
if c.page_user.is_email_activated():
if c.came_from:
redirect(c.came_from)
else:
redirect(h.entity_url(c.page_user))

c.hide_activate_attention_getter = True
return render('/user/ask_activate.html')

def pending_activate(self, id):
c.page_user = get_entity_or_abort(model.User, id,
instance_filter=False)
if c.page_user.is_email_activated():
if c.came_from:
redirect(c.came_from)
else:
redirect(h.entity_url(c.page_user))

c.hide_activate_attention_getter = True
return render('/user/pending_activate.html')

@RequireInternalRequest()
def resend(self, id):
Expand All @@ -762,11 +798,18 @@ def resend(self, id):
require.user.edit(c.page_user)
libmail.send_activation_link(c.page_user)

if c.came_from:
session['activate_came_from'] = c.came_from
force_path = h.entity_url(c.page_user, member='pending_activate',
query={'came_from': c.came_from})
else:
force_path = None

ret_success(
message=_("The activation link has been re-sent to your email "
"address."), category='success',
entity=c.page_user, member='settings/notifications',
format=None, force_path=c.came_from)
format=None, force_path=force_path)

@staticmethod
def _get_profile_nav(user, active_key):
Expand Down
10 changes: 9 additions & 1 deletion src/adhocracy/lib/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,19 @@ def check(self, *a, **kw):
return self.closure()
else:
return auth_check
elif auth_check.need_login():
elif auth_check.propose_login():
# Authentication might help
from adhocracy.lib.helpers import login_redirect_url
from pylons.controllers.util import redirect
redirect(login_redirect_url())
elif auth_check.propose_join():
from adhocracy.lib.helpers import join_redirect_url
from pylons.controllers.util import redirect
redirect(join_redirect_url())
elif auth_check.propose_validate_email():
from adhocracy.lib.helpers import validate_redirect_url
from pylons.controllers.util import redirect
redirect(validate_redirect_url())
else:
from adhocracy.lib.templating import ret_abort
log.debug("Aborting due to authorisation error: %s" %
Expand Down
9 changes: 9 additions & 0 deletions src/adhocracy/lib/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ def register_redirect_url(entity=None, **kwargs):
return get_redirect_url(u'register', entity, **kwargs)


def join_redirect_url(entity=None, **kwargs):
return get_redirect_url(u'instance/%s/ask_join' % c.instance.key, **kwargs)


def validate_redirect_url(entity=None, **kwargs):
return get_redirect_url(u'user/%s/ask_activate' % c.user.user_name, entity,
**kwargs)


def entity_url(entity, **kwargs):
if isinstance(entity, model.User):
return user.url(entity, **kwargs)
Expand Down
6 changes: 6 additions & 0 deletions src/adhocracy/lib/helpers/user_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,9 @@ def can_change_password(user):
return asbool(config.get('adhocracy.allow_password_change', 'false'))
else:
return True


def activation_url():
from adhocracy.lib.auth.csrf import url_token
from adhocracy.lib.helpers import base_url
return base_url('/user/%s/resend?%s' % (c.user.user_name, url_token()))
138 changes: 74 additions & 64 deletions src/adhocracy/templates/components.html
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
<legend>${_('Proposal Category')}</legend>
%if selected:
<% (cat_id, key) = selected %>
<input type="hidden" name="category" value="${cat_id}">
<input type="hidden" name="category" value="${cat_id}" />
<select disabled="disabled">
<option value="${cat_id}">${key}</option>
</select>
Expand Down Expand Up @@ -404,67 +404,77 @@


<%def name="attention_getter()">
%if not h.config.get_bool(u'adhocracy.readonly') and c.instance is not None and (c.user is None or can.instance.join(c.instance) or (c.instance.requires_valid_email() and c.user and not c.user.is_email_activated()) or (h.config.get('adhocracy.propose_optional_attributes') and c.user.optional_attributes is None)):
<%doc>add an attention getter on instances</%doc>
<div id="flash_message">
<div class="page_wrapper">
<div class="message">
%if c.user is None:
<div class="register">
%if h.allow_user_registration():
<a href="${h.register_redirect_url()}"
## rel="#overlay-url" FIXME: reactivate when ready.
class="button">${_('Register')}</a>
${_("or")}
%endif
<a href="${h.login_redirect_url()}"
## rel="#overlay-url" FIXME: reactivate.
class="more_uppercase">${_('Login')}</a>
</div>
<p class="register_msg">
%if h.allow_user_registration():
${_('Get an account to participate in the discussion.')}
%else:
${_('Log in to participate in the discussion.')}
%endif
</p>
%elif can.instance.join(c.instance):
<div class="register">
<a class="button" href="${h.entity_url(c.instance, member='join')}?${h.url_token()}">${_("join")}</a>
</div>
<p>
${_('Join this instance to start contributing.')}
</p>
%elif c.instance.require_valid_email and c.user and not c.user.is_email_activated():
%if c.user.email is None:
<div class="register">
<a class="button" href="${h.entity_url(c.user, instance=c.instance, member='edit')}">${_("Edit profile")}</a>
</div>
<p>
${_('You need to set an email in your profile in order to contribute to this instance.')}
</p>
%else:
<div class="register">
<a class="button large" href="${h.base_url('/user/%s/resend?%s' % (c.user.user_name, h.url_token()))}" title="${_('Resend validation email to %s')%c.user.email}">${_('Send activation link')}</a>
${_("or")}
<a class="more_uppercase" href="${h.entity_url(c.user, instance=c.instance, member='edit')}">${_("Edit profile")}</a>
</div>
<p>
${_('Please validate your email address in order to contribute to this instance.')}<br />
${_('Your registered email address is:')} <em>${c.user.email}</em>
</p>
%endif
%else: # h.config.get('adhocracy.propose_optional_attributes') and c.user.optional_attributes is None)):
<div class="register">
<a class="button" href="${h.entity_url(c.user, instance=c.instance, member='settings/optional')}">${_("Provide information")}</a>
</div>
<p>
${_(u'Please provide statistical information to help scientific evaluation!')}<br />
</p>
</div>
%endif
</div>
</div>
</div>
%endif
<% show_attention_getter = (
not h.config.get_bool(u'adhocracy.readonly')
and c.instance is not None
and (c.user is None
or can.instance.join(c.instance)
or (c.instance.requires_valid_email()
and c.user
and not c.user.is_email_activated()
and not c.hide_activate_attention_getter)
or (h.config.get('adhocracy.propose_optional_attributes')
and c.user.optional_attributes is None))) %>

%if show_attention_getter:
<div id="flash_message">
<div class="page_wrapper">
<div class="message">
%if c.user is None:
<div class="register">
%if h.allow_user_registration():
<a href="${h.register_redirect_url()}"
## rel="#overlay-url" FIXME: reactivate when ready.
class="button">${_('Register')}</a>
${_("or")}
%endif
<a href="${h.login_redirect_url()}"
## rel="#overlay-url" FIXME: reactivate.
class="more_uppercase">${_('Login')}</a>
</div>
<p class="register_msg">
%if h.allow_user_registration():
${_('Get an account to participate in the discussion.')}
%else:
${_('Log in to participate in the discussion.')}
%endif
</p>
%elif can.instance.join(c.instance):
<div class="register">
<a class="button" href="${h.entity_url(c.instance, member='join')}?${h.url_token()}">${_("join")}</a>
</div>
<p>
${_('Join this instance to start contributing.')}
</p>
%elif c.instance.require_valid_email and c.user and not c.user.is_email_activated():
%if c.user.email is None:
<div class="register">
<a class="button" href="${h.entity_url(c.user, instance=c.instance, member='edit')}">${_("Edit profile")}</a>
</div>
<p>
${_('You need to set an email in your profile in order to contribute to this instance.')}
</p>
%else:
<div class="register">
<a class="button large" href="${h.base_url('/user/%s/resend?%s' % (c.user.user_name, h.url_token()))}" title="${_('Resend validation email to %s')%c.user.email}">${_('Send activation link')}</a>
${_("or")}
<a class="more_uppercase" href="${h.entity_url(c.user, instance=c.instance, member='edit')}">${_("Edit profile")}</a>
</div>
<p>
${_('Please validate your email address in order to contribute to this instance.')}<br />
${_('Your registered email address is:')} <em>${c.user.email}</em>
</p>
%endif
%else: # h.config.get('adhocracy.propose_optional_attributes') and c.user.optional_attributes is None)):
<div class="register">
<a class="button" href="${h.entity_url(c.user, instance=c.instance, member='settings/optional')}">${_("Provide information")}</a>
</div>
<p>
${_(u'Please provide statistical information to help scientific evaluation!')}
</p>
%endif
</div>
</div>
</div>
%endif
</%def>
21 changes: 21 additions & 0 deletions src/adhocracy/templates/instance/ask_join.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<%inherit file="/template.html" />
<%namespace name="components" file="/components.html"/>
<%def name="title()">${_(u'Join %s' % c.instance.label)}</%def>

<%def name="breadcrumbs()">
${h.instance.breadcrumbs(c.page_instance)|n} ${_(u'Join')}
</%def>

<%block name="headline">
<h3>${_(u'Join instance')}</h3>
</%block>

<%block name="main_content">
<form name="ask_join" class="inplace" method="GET"
action="${h.entity_url(c.page_instance, member='join')}">
${h.field_token()|n}
<input type="hidden" name="came_from" value="${c.came_from}" />
${_(u'In order to perform the requested action, you need to join this instance.')}
${components.savebox(cancel_url=None, save_text=u'Join')}
</form>
</%block>
2 changes: 1 addition & 1 deletion src/adhocracy/templates/root.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<p class="patch_description">
${_('Validate email to start contributing.')}
</p>
<a class="button large patch_camefrom" href="${h.base_url('/user/%s/resend?%s' % (c.user.user_name, h.url_token()))}" title="${_('Resend validation email to %s')%c.user.email}">${_('Send activation link')}</a>
<a class="button large patch_camefrom" href="${h.user.activation_url()}" title="${_('Resend validation email to %s')%c.user.email}">${_('Send activation link')}</a>
${_("or")}
<a class="more_uppercase" href="${h.entity_url(c.user, instance=c.instance, member='edit')}">${_("Edit profile")}</a>
</div>
Expand Down
25 changes: 25 additions & 0 deletions src/adhocracy/templates/user/ask_activate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%inherit file="/template.html" />
<%namespace name="components" file="/components.html"/>
<%def name="title()">${_(u'Validate email address')}</%def>

<%def name="breadcrumbs()">
${h.instance.breadcrumbs(c.page_user)|n} ${_(u'Validate email address')}
</%def>

<%block name="headline">
<h3>${_(u'Validate email address')}</h3>
</%block>

<%block name="main_content">
<form name="ask_activate" class="inplace" method="GET"
action="${h.user.activation_url()}">
${h.field_token()|n}
<input type="hidden" name="came_from" value="${c.came_from}" />

<p>${_(u'You have not yet validated your email address.')}</p>
<p>${_(u'An email with a validation link has been sent to your email address (%s) right after registration. Please follow that link in order to proceed.' % c.user.email)}</p>
<p>${_(u'If you click on the button below, the validation link will be resent to you.')}</p>

${components.savebox(cancel_url=None, save_text=u'Resend activation link')}
</form>
</%block>
16 changes: 16 additions & 0 deletions src/adhocracy/templates/user/pending_activate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%inherit file="/template.html" />
<%namespace name="components" file="/components.html"/>
<%def name="title()">${_(u'Validate email address')}</%def>

<%def name="breadcrumbs()">
${h.instance.breadcrumbs(c.page_user)|n} ${_(u'Validate email address')}
</%def>

<%block name="headline">
<h3>${_(u'Validation email sent')}</h3>
</%block>

<%block name="main_content">
${_(u'An email has been sent to you. Please click on the validation link in this email in order to proceed.')}
</%block>

0 comments on commit 7a4de5e

Please sign in to comment.