mirror of
https://github.com/simple-login/app.git
synced 2025-12-11 23:46:56 +08:00
handle "next" for "sign up with github" too
This commit is contained in:
parent
f21f16e3f2
commit
aab2244881
3 changed files with 28 additions and 25 deletions
|
|
@ -64,11 +64,13 @@
|
||||||
<div class="card-body p-6">
|
<div class="card-body p-6">
|
||||||
<div class="card-title">Social sign up</div>
|
<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
|
<i class="fa fa-github"></i> Sign up with Github
|
||||||
</a>
|
</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
|
<i class="fa fa-google"></i> Sign up with Google
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -29,38 +29,39 @@ def register():
|
||||||
return redirect(url_for("dashboard.index"))
|
return redirect(url_for("dashboard.index"))
|
||||||
|
|
||||||
form = RegisterForm(request.form)
|
form = RegisterForm(request.form)
|
||||||
|
next_url = request.args.get("next")
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
user = User.filter_by(email=form.email.data).first()
|
user = User.filter_by(email=form.email.data).first()
|
||||||
|
|
||||||
if user:
|
if user:
|
||||||
flash(f"Email {form.email.data} already exists", "warning")
|
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)
|
# by default new user will be trial period
|
||||||
user = User.create(email=form.email.data, name=form.name.data)
|
user.plan = PlanEnum.trial
|
||||||
user.set_password(form.password.data)
|
user.plan_expiration = arrow.now().shift(days=+15)
|
||||||
|
db.session.flush()
|
||||||
|
|
||||||
# by default new user will be trial period
|
# create a first alias mail to show user how to use when they login
|
||||||
user.plan = PlanEnum.trial
|
GenEmail.create_new_gen_email(user_id=user.id)
|
||||||
user.plan_expiration = arrow.now().shift(days=+15)
|
db.session.commit()
|
||||||
db.session.flush()
|
|
||||||
|
|
||||||
# create a first alias mail to show user how to use when they login
|
send_activation_email(user, next_url)
|
||||||
GenEmail.create_new_gen_email(user_id=user.id)
|
notify_admin(
|
||||||
db.session.commit()
|
f"new user signs up {user.email}",
|
||||||
|
f"{user.name} signs up at {arrow.now()}",
|
||||||
|
)
|
||||||
|
|
||||||
send_activation_email(user)
|
return render_template("auth/register_waiting_activation.html")
|
||||||
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.html", form=form, next_url=next_url)
|
||||||
|
|
||||||
return render_template("auth/register.html", form=form)
|
|
||||||
|
|
||||||
|
|
||||||
def send_activation_email(user):
|
def send_activation_email(user, next_url):
|
||||||
# the activation code is valid for 1h
|
# the activation code is valid for 1h
|
||||||
activation = ActivationCode.create(
|
activation = ActivationCode.create(
|
||||||
user_id=user.id, code=random_string(30), expired=arrow.now().shift(hours=1)
|
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
|
# Send user activation email
|
||||||
activation_link = f"{URL}/auth/activate?code={activation.code}"
|
activation_link = f"{URL}/auth/activate?code={activation.code}"
|
||||||
if "next" in request.args:
|
if next_url:
|
||||||
LOG.d("redirect user to %s after activation", request.args["next"])
|
LOG.d("redirect user to %s after activation", next_url)
|
||||||
activation_link = activation_link + "&next=" + encode_url(request.args["next"])
|
activation_link = activation_link + "&next=" + encode_url(next_url)
|
||||||
|
|
||||||
email_utils.send(
|
email_utils.send(
|
||||||
user.email,
|
user.email,
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ def resend_activation():
|
||||||
"An activation email is on its way, please check your inbox/spam folder",
|
"An activation email is on its way, please check your inbox/spam folder",
|
||||||
"warning",
|
"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/register_waiting_activation.html")
|
||||||
|
|
||||||
return render_template("auth/resend_activation.html", form=form)
|
return render_template("auth/resend_activation.html", form=form)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue