def signup(req):
if any(map(lambda key: key not in req.json, ["name", "email", "password"])):
logger.debug(f"Request is {req.json} but some arguments are missing.")
raise InvalidUsage("Missing argument")
if not await User.is_free(req.json["name"], req.json["email"]):
logger.debug(f"Request is {req.json} but name or email is already taken")
raise InvalidUsage("Username or email already taken")
guest = Guest(req.json["name"], req.json["email"], User.hashpwd(req.json["password"]))
chlg = await challenges.create_for(guest)
logger.info(f"Guest signed up with name: {guest.name} and email: {guest.email}. Challenge generated: {chlg}")
with open("mails" + sep + "challenge.txt") as mailtext:
mail = EmailMessage()
mail.set_content(mailtext.read().format(domain=req.app.config.domain,
scheme="https" if req.app.config.schemessl else "http",
challenge=chlg))
mail["Subject"] = "WebGames Registration Challenge"
mail["From"] = req.app.config.smtpuser
mail["To"] = guest.email
with SMTP(req.app.config.smtphost, req.app.config.smtpport) as smtp:
if req.app.config.smtpssl:
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
else:
smtp.helo()
smtp.login(req.app.config.smtpuser, req.app.config.smtppwd)
smtp.send_message(mail)
return text(f"Challenge sent to {guest.email}")
评论列表
文章目录