Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send new admin a link to reset their password when they create a new instance #34

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions app/instances/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from flask import flash, redirect, render_template, current_app, url_for
from flask_wtf.csrf import generate_csrf
from flask_rq import get_queue
from flask_login import current_user, login_required
from urllib.parse import quote
from app import csrf

from . import instances
from ..utils import get_heroku_token, register_subdomain, update_subdomain
from .forms import LaunchInstanceForm, ChangeSubdomainForm
from ..models import Instance
from ..decorators import heroku_auth_required
from .. import db
from ..email import send_email

import string
import random
Expand Down Expand Up @@ -99,9 +102,14 @@ def launch():

register_subdomain(instance)

return render_template('instances/launch_status.html',
app_setup_id=app_setup_id, auth=auth,
instance=instance)
return render_template(
'instances/launch_status.html',
app_setup_id=app_setup_id,
auth=auth,
instance=instance,
email=username_in_app,
password=password_in_app,
name=url_name)

return render_template('instances/launch_form.html', form=form)

Expand All @@ -121,6 +129,21 @@ def get_status(app_setup_id, auth):
return resp.text


@csrf.exempt
@instances.route('/send-admin-email/<email>/<password>/<name>',
methods=['POST'])
def send_admin_email(email, password, name):
get_queue().enqueue(
send_email,
recipient=current_user.email,
subject='Admin Login Information',
template='instances/email/admin_login_info',
full_name=current_user.full_name(),
url_name=name,
email=current_user.email,
default_password=password)


@instances.route('/')
@login_required
def view_instances():
Expand Down
21 changes: 21 additions & 0 deletions app/templates/instances/email/admin_login_info.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Dear {{ full_name }},

<p>
You have succesfully created an instance of Maps4All!
</p>

<p> Your app is available at

<a href="{{'https://' + url_name + '.maps4all.org'}}">
{{'https://' + url_name + '.maps4all.org'}}
</a>. </p>

<p> The admin email will be: {{ email }}. We have randomized a password for your administrator account. Click here to reset the password for your account: <a href="{{'https://' + url_name + '.maps4all.org/account/reset-password'}}">
{{'https://' + url_name + '.maps4all.org/account/reset-password'}}
</a>. You will be prompted to enter your email again.

<p>Sincerely,</p>

<p>The {{ config.APP_NAME }} Team</p>

<p><small>Note: replies to this email address are not monitored.</small></p>
14 changes: 14 additions & 0 deletions app/templates/instances/email/admin_login_info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Dear {{ full_name }},

You have succesfully created an instance of Maps4All!

Your app is available at
{{'https://' + url_name + '.maps4all.org'}}.

The admin email will be {{ email }}. We have randomized a password for your administrator account. Click here to reset the password for your account: {{'https://' + url_name + '.maps4all.org/account/reset-password'}}. You will be prompted to enter your email again.

Sincerely,

The {{ config.APP_NAME }} Team

Note: replies to this email address are not monitored.
7 changes: 5 additions & 2 deletions app/templates/instances/launch_status.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ <h2 class="ui header">Please wait...</h2>
</div>
<p>Your app is available at <a href="{{'https://' + instance.url_name + '.maps4all.org'}}">
{{'https://' + instance.url_name + '.maps4all.org'}}</a>.
The admin email will be {{ instance.email }} and the admin password will be {{ instance.default_password }}.
Feel free to change this password after logging in.
The admin email will be {{ instance.email }}. A link to set your password will be sent to this email.
</p>
<p>Please write down this information!</p>
</div>
Expand All @@ -48,6 +47,10 @@ <h2 class="ui header">Please wait...</h2>
donePolling();
if (res.status === 'succeeded') {
$('#deployed-info').show();
$.ajax({
type: 'POST',
url: "{{ url_for('instances.send_admin_email', email=email, password=password, name=name)}}"
})
}
else {
alert("Something went wrong. Please share this with the developer: " + JSON.stringify(res));
Expand Down