Fixed all api calls
This commit is contained in:
parent
5cd12c3f34
commit
b2ce867b7d
Binary file not shown.
@ -21,7 +21,6 @@ def register_mail() -> flask.Response:
|
|||||||
return flask.Response("Something went wrong, check mail or try again later", 404)
|
return flask.Response("Something went wrong, check mail or try again later", 404)
|
||||||
response = flask.Response()
|
response = flask.Response()
|
||||||
response.set_cookie("mail", mail)
|
response.set_cookie("mail", mail)
|
||||||
response.headers.add('Access-Control-Allow-Origin', '*')
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@ -40,7 +39,6 @@ def confirm_mail_code() -> flask.Response:
|
|||||||
flask.session["mail"] = mail
|
flask.session["mail"] = mail
|
||||||
response = flask.Response(str(success))
|
response = flask.Response(str(success))
|
||||||
response.delete_cookie("mail")
|
response.delete_cookie("mail")
|
||||||
response.headers.add('Access-Control-Allow-Origin', '*')
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@ -51,20 +49,28 @@ def register_leader() -> flask.Response:
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
return flask.Response("mail not registered", 428)
|
return flask.Response("mail not registered", 428)
|
||||||
try:
|
try:
|
||||||
|
team_id = utils.TeamHandler.create_team(flask.request.form["team_name"])
|
||||||
|
request_data = dict(flask.request.form)
|
||||||
|
request_data.pop("team_name")
|
||||||
utils.UserHandler.create_user(utils.User(
|
utils.UserHandler.create_user(utils.User(
|
||||||
-1,
|
-1,
|
||||||
mail=mail,
|
mail=mail,
|
||||||
**flask.request.form,
|
team_id=team_id,
|
||||||
|
**request_data,
|
||||||
))
|
))
|
||||||
user_id = utils.UserHandler.get_user_by_mail(mail).user_id
|
user_id = utils.UserHandler.get_user_by_mail(mail).user_id
|
||||||
flask.session.pop("mail")
|
flask.session.pop("mail")
|
||||||
flask.session["user_id"] = user_id
|
flask.session["user_id"] = user_id
|
||||||
except TypeError:
|
except (TypeError, KeyError):
|
||||||
return flask.Response("Something is missing", 422)
|
return flask.Response("Something is missing", 422)
|
||||||
except sqlite3.IntegrityError:
|
except sqlite3.IntegrityError:
|
||||||
return flask.Response("Mail already registered or phone number or pin code is not correct", 428)
|
return flask.Response("Mail already registered or phone number or pin code is not correct", 428)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return flask.Response("There is text where number is supposed to be there", 400)
|
return flask.Response("There is text where number is supposed to be there", 400)
|
||||||
|
try:
|
||||||
|
utils.MailHandler.send_success_mail(mail)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return flask.Response()
|
return flask.Response()
|
||||||
|
|
||||||
|
|
||||||
@ -78,35 +84,31 @@ def login() -> flask.Response:
|
|||||||
try:
|
try:
|
||||||
assert utils.UserHandler.verify_password_by_mail(mail, password)
|
assert utils.UserHandler.verify_password_by_mail(mail, password)
|
||||||
flask.session["user_id"] = utils.UserHandler.get_user_by_mail(mail).user_id
|
flask.session["user_id"] = utils.UserHandler.get_user_by_mail(mail).user_id
|
||||||
response = flask.Response()
|
return flask.Response()
|
||||||
response.headers.add('Access-Control-Allow-Origin', '*')
|
|
||||||
return response
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return flask.Response("Mail doesn't exist", 404)
|
return flask.Response("Mail doesn't exist", 404)
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
return flask.Response("Wrong password", 422)
|
return flask.Response("Wrong password", 422)
|
||||||
|
|
||||||
|
|
||||||
@app.post("/get-mail")
|
@app.post("/get-id")
|
||||||
def verify_login() -> flask.Response:
|
def get_id() -> flask.Response:
|
||||||
try:
|
try:
|
||||||
assert "user_id" in flask.session
|
return flask.Response(str(flask.session["user_id"]))
|
||||||
return flask.Response(flask.session["mail"])
|
except KeyError:
|
||||||
except AssertionError:
|
|
||||||
return flask.Response("Not logged in", 428)
|
return flask.Response("Not logged in", 428)
|
||||||
|
|
||||||
|
|
||||||
@app.post("/logout")
|
@app.post("/logout")
|
||||||
def logout() -> flask.Response:
|
def logout() -> flask.Response:
|
||||||
try:
|
try:
|
||||||
|
print(flask.session)
|
||||||
flask.session.pop("user_id")
|
flask.session.pop("user_id")
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return flask.Response("Not logged in", 428)
|
return flask.Response("Not logged in", 428)
|
||||||
return flask.Response()
|
return flask.Response()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/register-teammate")
|
@app.post("/register-teammate")
|
||||||
def register() -> flask.Response:
|
def register() -> flask.Response:
|
||||||
try:
|
try:
|
||||||
@ -114,13 +116,20 @@ def register() -> flask.Response:
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
return flask.Response("Not logged in", 428)
|
return flask.Response("Not logged in", 428)
|
||||||
try:
|
try:
|
||||||
|
team_id = utils.UserHandler.get_user_by_id(user_id).team_id
|
||||||
utils.UserHandler.create_user(utils.User(
|
utils.UserHandler.create_user(utils.User(
|
||||||
-1,
|
-1,
|
||||||
secrets.token_urlsafe(20),
|
secrets.token_urlsafe(20),
|
||||||
|
team_id=team_id,
|
||||||
**flask.request.form,
|
**flask.request.form,
|
||||||
))
|
))
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return flask.Response("Not all details provided", 422)
|
return flask.Response("Not all details provided", 422)
|
||||||
except sqlite3.IntegrityError:
|
except sqlite3.IntegrityError as error:
|
||||||
return flask.Response("Mail taken or phone/ pin code wrong", 400)
|
error_message = str(error)
|
||||||
|
if error_message == "UNIQUE constraint failed: users.phone_number":
|
||||||
|
return flask.Response("Phone number taken", 400)
|
||||||
|
if error_message == "UNIQUE constraint failed: users.mail":
|
||||||
|
return flask.Response("Mail taken")
|
||||||
|
return flask.Response("Phone/ pin code wrong", 400)
|
||||||
return flask.Response()
|
return flask.Response()
|
||||||
|
@ -50,3 +50,61 @@ class MailHandler:
|
|||||||
cls.__login_codes.pop(mail)
|
cls.__login_codes.pop(mail)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def send_success_mail(cls, mail: str) -> None:
|
||||||
|
message = MIMEMultipart("alternative")
|
||||||
|
message["Subject"] = "multipart test"
|
||||||
|
message["From"] = "ssth@sahyadri.edu.in"
|
||||||
|
message["To"] = mail
|
||||||
|
|
||||||
|
html = f"""
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<p>Hi,<br>
|
||||||
|
How are you?<br>
|
||||||
|
<a href="http://www.realpython.com">Real Python</a>
|
||||||
|
has many great tutorials.
|
||||||
|
<br/>
|
||||||
|
You've joined!!!
|
||||||
|
</p>
|
||||||
|
</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())
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def send_warning_mail(cls, mail: str) -> None:
|
||||||
|
message = MIMEMultipart("alternative")
|
||||||
|
message["Subject"] = "multipart test"
|
||||||
|
message["From"] = "ssth@sahyadri.edu.in"
|
||||||
|
message["To"] = mail
|
||||||
|
|
||||||
|
html = f"""
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<p>Hi,<br>
|
||||||
|
How are you?<br>
|
||||||
|
<a href="http://www.realpython.com">Real Python</a>
|
||||||
|
has many great tutorials.
|
||||||
|
<br/>
|
||||||
|
You're joining...
|
||||||
|
</p>
|
||||||
|
</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())
|
||||||
|
@ -83,9 +83,10 @@ class UserHandler:
|
|||||||
pin_code,
|
pin_code,
|
||||||
phone_number,
|
phone_number,
|
||||||
name,
|
name,
|
||||||
team_id
|
team_id,
|
||||||
|
team_leader
|
||||||
)
|
)
|
||||||
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
encrypted_password,
|
encrypted_password,
|
||||||
@ -100,7 +101,7 @@ class UserHandler:
|
|||||||
user.pin_code,
|
user.pin_code,
|
||||||
user.phone_number,
|
user.phone_number,
|
||||||
user.name,
|
user.name,
|
||||||
user.team_id
|
user.team_id,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
cls.__connection.commit()
|
cls.__connection.commit()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user