|
|
@ -37,27 +37,32 @@ def handle_authentication(headers):
|
|
|
|
password = urllib.parse.unquote(headers["Auth-Pass"])
|
|
|
|
password = urllib.parse.unquote(headers["Auth-Pass"])
|
|
|
|
ip = urllib.parse.unquote(headers["Client-Ip"])
|
|
|
|
ip = urllib.parse.unquote(headers["Client-Ip"])
|
|
|
|
user = models.User.query.get(user_email)
|
|
|
|
user = models.User.query.get(user_email)
|
|
|
|
|
|
|
|
status = False
|
|
|
|
if user:
|
|
|
|
if user:
|
|
|
|
for token in user.tokens:
|
|
|
|
for token in user.tokens:
|
|
|
|
if (token.check_password(password) and
|
|
|
|
if (token.check_password(password) and
|
|
|
|
(not token.ip or token.ip == ip)):
|
|
|
|
(not token.ip or token.ip == ip)):
|
|
|
|
return {
|
|
|
|
status = True
|
|
|
|
"Auth-Status": "OK",
|
|
|
|
|
|
|
|
"Auth-Server": server,
|
|
|
|
|
|
|
|
"Auth-Port": port
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.check_password(password):
|
|
|
|
if user.check_password(password):
|
|
|
|
return {
|
|
|
|
status = True
|
|
|
|
"Auth-Status": "OK",
|
|
|
|
if status:
|
|
|
|
"Auth-Server": server,
|
|
|
|
if protocol == "imap" and not user.enable_imap:
|
|
|
|
"Auth-Port": port
|
|
|
|
status = False
|
|
|
|
}
|
|
|
|
elif protocol == "pop3" and not user.enable_pop:
|
|
|
|
status, code = get_status(protocol, "authentication")
|
|
|
|
status = False
|
|
|
|
return {
|
|
|
|
if status:
|
|
|
|
"Auth-Status": status,
|
|
|
|
return {
|
|
|
|
"Auth-Error-Code": code,
|
|
|
|
"Auth-Status": "OK",
|
|
|
|
"Auth-Wait": 0
|
|
|
|
"Auth-Server": server,
|
|
|
|
}
|
|
|
|
"Auth-Port": port
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
status, code = get_status(protocol, "authentication")
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
"Auth-Status": status,
|
|
|
|
|
|
|
|
"Auth-Error-Code": code,
|
|
|
|
|
|
|
|
"Auth-Wait": 0
|
|
|
|
|
|
|
|
}
|
|
|
|
# Unexpected
|
|
|
|
# Unexpected
|
|
|
|
return {}
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
|
|