Compare commits
2 Commits
c6edcc73e8
...
99bf585d9d
Author | SHA1 | Date | |
---|---|---|---|
99bf585d9d | |||
60dbab0370 |
Binary file not shown.
@ -1,4 +1,5 @@
|
||||
import os
|
||||
from os.path import isdir
|
||||
import secrets
|
||||
import sqlite3
|
||||
import flask
|
||||
@ -14,11 +15,13 @@ app.config["SESSION_TYPE"] = "filesystem"
|
||||
def register_mail() -> flask.Response:
|
||||
try:
|
||||
mail = flask.request.form["mail"]
|
||||
flask.session["password"] = flask.request.form["password"]
|
||||
except KeyError:
|
||||
return flask.Response(f"mail is missing, lol", 422)
|
||||
return flask.Response(f"mail or password is missing", 422)
|
||||
try:
|
||||
utils.MailHandler.send_code(mail)
|
||||
except:
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return flask.Response("Something went wrong, check mail or try again later", 404)
|
||||
response = flask.Response()
|
||||
response.set_cookie("mail", mail)
|
||||
@ -28,14 +31,16 @@ def register_mail() -> flask.Response:
|
||||
@app.post("/verify-mail-code")
|
||||
def confirm_mail_code() -> flask.Response:
|
||||
try:
|
||||
print(flask.request.form)
|
||||
mail = flask.request.cookies["mail"]
|
||||
token = flask.request.form["token"]
|
||||
except KeyError:
|
||||
except KeyError as e:
|
||||
print("\n\n\n", e)
|
||||
return flask.Response("Token missing or /register_mail not called", 422)
|
||||
try:
|
||||
success = utils.MailHandler.verify_code(mail, token)
|
||||
except:
|
||||
return flask.Response("Something went wrong, check mail or try again later", 404)
|
||||
except KeyError:
|
||||
return flask.Response("Register mail not called. Try again", 404)
|
||||
if success:
|
||||
flask.session["mail"] = mail
|
||||
response = flask.Response(str(success))
|
||||
@ -47,6 +52,7 @@ def confirm_mail_code() -> flask.Response:
|
||||
def register_leader() -> flask.Response:
|
||||
try:
|
||||
mail = flask.session["mail"]
|
||||
password = flask.session["password"]
|
||||
except KeyError:
|
||||
return flask.Response("mail not registered", 428)
|
||||
try:
|
||||
@ -58,16 +64,16 @@ def register_leader() -> flask.Response:
|
||||
mail=mail,
|
||||
team_id=team_id,
|
||||
team_leader=1,
|
||||
password=password,
|
||||
**request_data,
|
||||
))
|
||||
user_id = utils.UserHandler.get_user_by_mail(mail).user_id
|
||||
flask.session.pop("mail")
|
||||
flask.session["user_id"] = user_id
|
||||
except (TypeError, KeyError) as e:
|
||||
print(e)
|
||||
except (TypeError, KeyError):
|
||||
return flask.Response("Something is missing", 422)
|
||||
except sqlite3.IntegrityError:
|
||||
return flask.Response("Mail already registered or phone number or pin code is not correct", 428)
|
||||
return flask.Response("Mail or phone number already registered or phone number or pin code is not correct", 428)
|
||||
except ValueError:
|
||||
return flask.Response("There is text where number is supposed to be there", 400)
|
||||
try:
|
||||
@ -94,10 +100,10 @@ def login() -> flask.Response:
|
||||
return flask.Response("Wrong password", 422)
|
||||
|
||||
|
||||
@app.post("/get-id")
|
||||
@app.post("/get-mail")
|
||||
def get_id() -> flask.Response:
|
||||
try:
|
||||
return flask.Response(str(flask.session["user_id"]))
|
||||
return flask.Response(utils.UserHandler.get_user_by_id(flask.session["user_id"]).mail)
|
||||
except KeyError:
|
||||
return flask.Response("Not logged in", 428)
|
||||
|
||||
@ -114,6 +120,7 @@ def logout() -> flask.Response:
|
||||
|
||||
@app.post("/register-teammate")
|
||||
def register() -> flask.Response:
|
||||
print(flask.request.form)
|
||||
try:
|
||||
user_id = flask.session["user_id"]
|
||||
except KeyError:
|
||||
@ -209,5 +216,6 @@ def get_info() -> flask.Response:
|
||||
for team_member in team_members:
|
||||
info["team_members"].append(utils.UserHandler.get_user_by_id(team_member).to_dict())
|
||||
info["project_details"] = vars(utils.TeamHandler.get_project(team_id))
|
||||
info["project_files"] = os.listdir(f"./data/project-files/{team_id}")
|
||||
if os.path.isdir(f"./data/project-files/{team_id}"):
|
||||
info["project_files"] = os.listdir(f"./data/project-files/{team_id}")
|
||||
return flask.jsonify(info)
|
||||
|
@ -6,21 +6,28 @@ from email.mime.multipart import MIMEMultipart
|
||||
|
||||
|
||||
class MailHandler:
|
||||
__smtp = smtplib.SMTP('smtp.gmail.com', 587)
|
||||
__smtp.starttls()
|
||||
__smtp: smtplib.SMTP
|
||||
__password = os.environ.get("MAIL_PASSWORD")
|
||||
__smtp.login("ssth@sahyadri.edu.in", __password if __password else "")
|
||||
|
||||
__login_codes: dict[str, str] = {}
|
||||
|
||||
@classmethod
|
||||
def __init(cls):
|
||||
cls.__smtp = smtplib.SMTP('smtp.gmail.com', 587)
|
||||
cls.__smtp.starttls()
|
||||
cls.__smtp.login("ssth@sahyadri.edu.in", cls.__password if cls.__password else "")
|
||||
|
||||
@classmethod
|
||||
def __close(cls):
|
||||
cls.__smtp.close()
|
||||
|
||||
@classmethod
|
||||
def send_code(cls, mail: str) -> None:
|
||||
cls.__login_codes[mail] = secrets.token_hex(6)
|
||||
cls.__init()
|
||||
message = MIMEMultipart("alternative")
|
||||
message["Subject"] = "multipart test"
|
||||
message["From"] = "ssth@sahyadri.edu.in"
|
||||
message["To"] = mail
|
||||
|
||||
html = f"""
|
||||
<html>
|
||||
<body>
|
||||
@ -34,14 +41,10 @@ class MailHandler:
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
# Turn these into plain/html MIMEText objects
|
||||
part2 = MIMEText(html, "html")
|
||||
|
||||
# Add HTML/plain-text parts to MIMEMultipart message
|
||||
# The email client will try to render the last part first
|
||||
message.attach(part2)
|
||||
cls.__smtp.sendmail("ssth@sahyadri.edu.in", mail, message.as_string())
|
||||
cls.__close()
|
||||
|
||||
|
||||
@classmethod
|
||||
@ -53,11 +56,11 @@ class MailHandler:
|
||||
|
||||
@classmethod
|
||||
def send_success_mail(cls, mail: str) -> None:
|
||||
cls.__init()
|
||||
message = MIMEMultipart("alternative")
|
||||
message["Subject"] = "multipart test"
|
||||
message["From"] = "ssth@sahyadri.edu.in"
|
||||
message["To"] = mail
|
||||
|
||||
html = f"""
|
||||
<html>
|
||||
<body>
|
||||
@ -71,17 +74,14 @@ class MailHandler:
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
# Turn these into plain/html MIMEText objects
|
||||
part2 = MIMEText(html, "html")
|
||||
|
||||
# Add HTML/plain-text parts to MIMEMultipart message
|
||||
# The email client will try to render the last part first
|
||||
message.attach(part2)
|
||||
cls.__smtp.sendmail("ssth@sahyadri.edu.in", mail, message.as_string())
|
||||
cls.__close()
|
||||
|
||||
@classmethod
|
||||
def send_warning_mail(cls, mail: str) -> None:
|
||||
cls.__init()
|
||||
message = MIMEMultipart("alternative")
|
||||
message["Subject"] = "multipart test"
|
||||
message["From"] = "ssth@sahyadri.edu.in"
|
||||
@ -100,11 +100,7 @@ class MailHandler:
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
# Turn these into plain/html MIMEText objects
|
||||
part2 = MIMEText(html, "html")
|
||||
|
||||
# Add HTML/plain-text parts to MIMEMultipart message
|
||||
# The email client will try to render the last part first
|
||||
message.attach(part2)
|
||||
cls.__smtp.sendmail("ssth@sahyadri.edu.in", mail, message.as_string())
|
||||
cls.__close()
|
||||
|
2
frontend
2
frontend
@ -1 +1 @@
|
||||
Subproject commit a2730e36488c52ac6478de0fa0944ae7f709b9ce
|
||||
Subproject commit f144157634f8c4571e569b8f49cf8e115d6e36e0
|
Loading…
x
Reference in New Issue
Block a user