2022-05-04 23:09:46 +00:00
|
|
|
import time
|
|
|
|
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.classes import *
|
2022-12-11 23:44:34 +00:00
|
|
|
from files.helpers.config.const import *
|
2022-05-25 22:26:03 +00:00
|
|
|
from files.helpers.get import *
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.helpers.mail import *
|
2022-11-01 23:46:56 +00:00
|
|
|
from files.helpers.useractions import *
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.routes.wrappers import *
|
2023-02-02 20:42:56 +00:00
|
|
|
from files.routes.users import claim_rewards
|
2022-10-08 00:44:02 +00:00
|
|
|
from files.__main__ import app, limiter
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
@app.post("/verify_email")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-02-26 08:41:04 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT)
|
2023-02-26 01:42:39 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
|
2022-05-04 23:09:46 +00:00
|
|
|
@auth_required
|
2022-08-11 04:05:23 +00:00
|
|
|
def verify_email(v):
|
2023-02-27 00:47:51 +00:00
|
|
|
if v.is_activated:
|
|
|
|
abort(400, "Email already verified!")
|
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
send_verification_email(v)
|
2023-01-27 11:57:29 +00:00
|
|
|
return {"message": "Email has been sent. Check your spam folder if you can't find it!"}
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.get("/activate")
|
2023-02-26 08:41:04 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT)
|
2023-01-21 04:39:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
|
2022-05-04 23:09:46 +00:00
|
|
|
@auth_required
|
2022-11-26 21:00:03 +00:00
|
|
|
def activate(v:User):
|
2022-05-04 23:09:46 +00:00
|
|
|
email = request.values.get("email", "").strip().lower()
|
|
|
|
|
|
|
|
if not email_regex.fullmatch(email):
|
2022-11-16 05:32:57 +00:00
|
|
|
abort(400, "Invalid email")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
id = request.values.get("id", "").strip()
|
|
|
|
timestamp = int(request.values.get("time", "0"))
|
|
|
|
token = request.values.get("token", "").strip()
|
|
|
|
|
|
|
|
if int(time.time()) - timestamp > 3600:
|
2023-01-27 11:57:29 +00:00
|
|
|
abort(410, "This email verification link has expired. Visit your settings to send yourself a new one!")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-05-25 22:26:03 +00:00
|
|
|
user = get_account(id)
|
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
if not validate_hash(f"{email}+{id}+{timestamp}", token):
|
|
|
|
abort(403)
|
|
|
|
|
|
|
|
if user.is_activated and user.email == email:
|
2022-11-29 05:25:17 +00:00
|
|
|
abort(400, "Email already verified!")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
user.email = email
|
|
|
|
user.is_activated = True
|
2023-02-02 20:42:56 +00:00
|
|
|
claim_rewards(user)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-06-15 19:33:21 +00:00
|
|
|
badge_grant(user=user, badge_id=2)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(user)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-01-27 11:57:29 +00:00
|
|
|
return render_template("message_success.html", v=v, title="Email verified!", message=f"Your email {email} has been verified. Thank you!")
|