Skip to content

Commit

Permalink
Merge pull request #3053 from zotonic/signup-confirm-submit
Browse files Browse the repository at this point in the history
mod_signup: always press a button to confirm.
  • Loading branch information
robvandenbogaard committed Jul 14, 2022
2 parents e517080 + 3ae2294 commit 2d37faf
Show file tree
Hide file tree
Showing 5 changed files with 263 additions and 171 deletions.
32 changes: 11 additions & 21 deletions modules/mod_signup/controllers/controller_signup_confirm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,43 +40,33 @@ charsets_provided(ReqData, Context) ->
content_types_provided(ReqData, Context) ->
{[{"text/html", provide_content}], ReqData, Context}.


provide_content(ReqData, Context) ->
Context1 = ?WM_REQ(ReqData, Context),
Context2 = z_context:ensure_all(Context1),
z_context:lager_md(Context2),
Key = z_context:get_q(key, Context2, []),
{Vars, ContextConfirm} = case Key of
[] ->
{[], Context2};
_ ->
case confirm(Key, Context2) of
{ok, UserId} ->
{ok, ContextUser} = z_auth:logon(UserId, Context2),
Location = confirm_location(UserId, ContextUser),
{[{user_id, UserId}, {location,Location}], ContextUser};
{error, _Reason} ->
{[{error, true}], Context2}
end
end,
Rendered = z_template:render("signup_confirm.tpl", Vars, ContextConfirm),
{Output, OutputContext} = z_context:output(Rendered, ContextConfirm),
Rendered = z_template:render("signup_confirm.tpl", [], Context2),
{Output, OutputContext} = z_context:output(Rendered, Context2),
?WM_REPLY(Output, OutputContext).


%% @doc Handle the submit of the signup form.
event(#submit{}, Context) ->
Key = z_context:get_q(key, Context, []),
case confirm(Key, Context) of
{ok, UserId} ->
{ok, ContextUser} = z_auth:logon(UserId, Context),
Location = confirm_location(UserId, ContextUser),
z_render:wire({redirect, [{location, Location}]}, ContextUser);
z_render:wire([
{hide, [{target, "confirm_form"}]},
{show, [{target, "confirm_ok"}]},
{redirect, [{location, Location}]}
], ContextUser);
{error, _Reason} ->
z_render:wire({show, [{target,"confirm_error"}]}, Context)
z_render:wire([
{show, [{target,"confirm_error"}]},
{show, [{target,"confirm_key"}]}
], Context)
end.


confirm(Key, Context) ->
case m_identity:lookup_by_verify_key(Key, Context) of
undefined ->
Expand Down
38 changes: 19 additions & 19 deletions modules/mod_signup/templates/signup_confirm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@

{% block content %}

{% if user_id %}
<h1>{_ Welcome _} {{ m.rsc[user_id].title }}</h1>
<h1>{_ Confirm my account _}</h1>

<p>{_ Your account is confirmed. You can now continue on our site. _}</p>

<p><a href="{{ location|default:m.rsc[user_id].page_url }}">{_ Bring me to my profile page _}</a>.</p>

{% else %}
<h1>{_ Confirm my account _}</h1>

<p>{_ In your e-mail you received a confirmation key. Please copy it in the input field below. _}</p>

<p id="confirm_error" class="error" {% if not error %}style="display: none"{% endif %}>
{_ Sorry, I don't know that confirmation code. Did you copy it correctly? _}
</p>
<div id="confirm_form">
<div id="confirm_error" class="error" style="display: none">
<p>
{_ Sorry, this confirmation key is unknown or already used. Did you copy it correctly? _}<br>
{_ Your account might have been confirmed already. _} <a href="{% url logon %}">{_ Try to log on _}</a>
</p>
</div>

<form class="setcookie" id="signup_confirm_form" method="post" action="postback">
<div class="form-group" id="confirm_key" {% if q.key %}style="display: none"{% endif %}>
<p>{_ In your e-mail you received a confirmation key. Please copy it in the input field below. _}</p>

<p id="confirm_key">
<label for="key">{_ Confirm key _}</label>
<input class="form-control" type="text" id="key" name="key" value="{{ q.key|escape }}" />
</p>
<button>{_ Confirm my account _}</button>
</div>
<button class="btn btn-primary" type="submit">{_ Confirm my account _}</button>
</form>
{% endif %}
</div>

<div id="confirm_ok" style="display: none">
<p>{_ Your account is confirmed and you are logged on. _}</p>

<p><a href="{{ location|default:m.rsc[user_id].page_url }}">{_ Bring me to my profile page _}</a>.</p>
</div>

{% endblock %}

0 comments on commit 2d37faf

Please sign in to comment.