handle "next" for "sign up with github" too

This commit is contained in:
Son NK 2019-07-08 19:43:33 +02:00 committed by Son NK
parent f21f16e3f2
commit aab2244881
3 changed files with 28 additions and 25 deletions

View File

@ -64,11 +64,13 @@
<div class="card-body p-6">
<div class="card-title">Social sign up</div>
<a href="{{ url_for('auth.github_login') }}" class="btn btn-block btn-social btn-github">
<a href="{{ url_for('auth.github_login', next=next_url) }}"
class="btn btn-block btn-social btn-github">
<i class="fa fa-github"></i> Sign up with Github
</a>
<a href="{{ url_for('auth.google_login') }}" class="btn btn-block btn-social btn-google">
<a href="{{ url_for('auth.google_login', next=next_url) }}"
class="btn btn-block btn-social btn-google">
<i class="fa fa-google"></i> Sign up with Google
</a>
</div>

View File

@ -29,38 +29,39 @@ def register():
return redirect(url_for("dashboard.index"))
form = RegisterForm(request.form)
next_url = request.args.get("next")
if form.validate_on_submit():
user = User.filter_by(email=form.email.data).first()
if user:
flash(f"Email {form.email.data} already exists", "warning")
return render_template("auth/register.html", form=form)
else:
LOG.debug("create user %s", form.email.data)
user = User.create(email=form.email.data, name=form.name.data)
user.set_password(form.password.data)
LOG.debug("create user %s", form.email.data)
user = User.create(email=form.email.data, name=form.name.data)
user.set_password(form.password.data)
# by default new user will be trial period
user.plan = PlanEnum.trial
user.plan_expiration = arrow.now().shift(days=+15)
db.session.flush()
# by default new user will be trial period
user.plan = PlanEnum.trial
user.plan_expiration = arrow.now().shift(days=+15)
db.session.flush()
# create a first alias mail to show user how to use when they login
GenEmail.create_new_gen_email(user_id=user.id)
db.session.commit()
# create a first alias mail to show user how to use when they login
GenEmail.create_new_gen_email(user_id=user.id)
db.session.commit()
send_activation_email(user, next_url)
notify_admin(
f"new user signs up {user.email}",
f"{user.name} signs up at {arrow.now()}",
)
send_activation_email(user)
notify_admin(
f"new user signs up {user.email}", f"{user.name} signs up at {arrow.now()}"
)
return render_template("auth/register_waiting_activation.html")
return render_template("auth/register_waiting_activation.html")
return render_template("auth/register.html", form=form)
return render_template("auth/register.html", form=form, next_url=next_url)
def send_activation_email(user):
def send_activation_email(user, next_url):
# the activation code is valid for 1h
activation = ActivationCode.create(
user_id=user.id, code=random_string(30), expired=arrow.now().shift(hours=1)
@ -69,9 +70,9 @@ def send_activation_email(user):
# Send user activation email
activation_link = f"{URL}/auth/activate?code={activation.code}"
if "next" in request.args:
LOG.d("redirect user to %s after activation", request.args["next"])
activation_link = activation_link + "&next=" + encode_url(request.args["next"])
if next_url:
LOG.d("redirect user to %s after activation", next_url)
activation_link = activation_link + "&next=" + encode_url(next_url)
email_utils.send(
user.email,

View File

@ -33,7 +33,7 @@ def resend_activation():
"An activation email is on its way, please check your inbox/spam folder",
"warning",
)
send_activation_email(user)
send_activation_email(user, request.args.get("next"))
return render_template("auth/register_waiting_activation.html")
return render_template("auth/resend_activation.html", form=form)