fix-lastseen
This commit is contained in:
parent
0c882dfc44
commit
7084bdb1a9
|
@ -1,27 +1,32 @@
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from settings import BACKEND_URL, MAILGUN_API_KEY, MAILGUN_DOMAIN
|
from settings import MAILGUN_API_KEY, MAILGUN_DOMAIN
|
||||||
|
|
||||||
MAILGUN_API_URL = "https://api.mailgun.net/v3/%s/messages" % MAILGUN_DOMAIN
|
api_url = "https://api.mailgun.net/v3/%s/messages" % MAILGUN_DOMAIN
|
||||||
MAILGUN_FROM = "discours.io <noreply@%s>" % MAILGUN_DOMAIN
|
noreply = "discours.io <noreply@%s>" % MAILGUN_DOMAIN
|
||||||
|
|
||||||
|
tmplt = """<html><body>
|
||||||
|
Follow the <a href='%s'>link</a> to authorize
|
||||||
|
</body></html>
|
||||||
|
"""
|
||||||
|
|
||||||
|
baseUrl = "https://new.discours.io"
|
||||||
|
|
||||||
|
|
||||||
async def send_auth_email(user, token):
|
async def send_auth_email(user, token):
|
||||||
text = """<html><body>
|
try:
|
||||||
Follow the <a href='%s'>link</link> to authorize
|
to = "%s <%s>" % (user.username, user.email)
|
||||||
</body></html>
|
url_with_token = "%s/confirm/%s" % (baseUrl, token)
|
||||||
"""
|
response = requests.post(
|
||||||
to = "%s <%s>" % (user.username, user.email)
|
api_url,
|
||||||
url_with_token = "%s/confirm-email/%s" % (BACKEND_URL, token)
|
auth=("api", MAILGUN_API_KEY),
|
||||||
text = text % url_with_token
|
data={
|
||||||
response = requests.post(
|
"from": noreply,
|
||||||
MAILGUN_API_URL,
|
"to": to,
|
||||||
auth=("api", MAILGUN_API_KEY),
|
"subject": "Confirm email",
|
||||||
data={
|
"html": tmplt % url_with_token,
|
||||||
"from": MAILGUN_FROM,
|
},
|
||||||
"to": to,
|
)
|
||||||
"subject": "Confirm email",
|
response.raise_for_status()
|
||||||
"html": text,
|
except Exception as e:
|
||||||
},
|
print(e)
|
||||||
)
|
|
||||||
response.raise_for_status()
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ def create_author_from_app(app):
|
||||||
"emailConfirmed": False,
|
"emailConfirmed": False,
|
||||||
"slug": slug,
|
"slug": slug,
|
||||||
"createdAt": ts,
|
"createdAt": ts,
|
||||||
"wasOnlineAt": ts,
|
"lastSeen": ts,
|
||||||
}
|
}
|
||||||
user = User.create(**userdata)
|
user = User.create(**userdata)
|
||||||
session.add(user)
|
session.add(user)
|
||||||
|
|
|
@ -28,7 +28,7 @@ def migrate(entry):
|
||||||
if "updatedAt" in entry:
|
if "updatedAt" in entry:
|
||||||
user_dict["updatedAt"] = parse(entry["updatedAt"])
|
user_dict["updatedAt"] = parse(entry["updatedAt"])
|
||||||
if "wasOnineAt" in entry:
|
if "wasOnineAt" in entry:
|
||||||
user_dict["wasOnlineAt"] = parse(entry["wasOnlineAt"])
|
user_dict["lastSeen"] = parse(entry["wasOnlineAt"])
|
||||||
if entry.get("profile"):
|
if entry.get("profile"):
|
||||||
# slug
|
# slug
|
||||||
user_dict["slug"] = (
|
user_dict["slug"] = (
|
||||||
|
|
|
@ -68,7 +68,7 @@ class User(Base):
|
||||||
createdAt = Column(
|
createdAt = Column(
|
||||||
DateTime, nullable=False, default=datetime.now, comment="Created at"
|
DateTime, nullable=False, default=datetime.now, comment="Created at"
|
||||||
)
|
)
|
||||||
wasOnlineAt = Column(
|
lastSeen = Column(
|
||||||
DateTime, nullable=False, default=datetime.now, comment="Was online at"
|
DateTime, nullable=False, default=datetime.now, comment="Was online at"
|
||||||
)
|
)
|
||||||
deletedAt = Column(DateTime, nullable=True, comment="Deleted at")
|
deletedAt = Column(DateTime, nullable=True, comment="Deleted at")
|
||||||
|
|
|
@ -47,10 +47,14 @@ async def confirm_email(_, _info, confirm_token):
|
||||||
user = session.query(User).where(User.id == user_id).first()
|
user = session.query(User).where(User.id == user_id).first()
|
||||||
session_token = TokenStorage.create_session(user)
|
session_token = TokenStorage.create_session(user)
|
||||||
user.emailConfirmed = True
|
user.emailConfirmed = True
|
||||||
user.wasOnlineAt = datetime.now()
|
user.lastSeen = datetime.now()
|
||||||
session.add(user)
|
session.add(user)
|
||||||
session.commit()
|
session.commit()
|
||||||
return {"token": session_token, "user": user}
|
return {
|
||||||
|
"token": session_token,
|
||||||
|
"user": user,
|
||||||
|
"news": await get_user_subscriptions(user.slug)
|
||||||
|
}
|
||||||
except InvalidToken as e:
|
except InvalidToken as e:
|
||||||
raise InvalidToken(e.message)
|
raise InvalidToken(e.message)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -343,7 +343,6 @@ type User {
|
||||||
emailConfirmed: Boolean # should contain all emails too
|
emailConfirmed: Boolean # should contain all emails too
|
||||||
muted: Boolean
|
muted: Boolean
|
||||||
updatedAt: DateTime
|
updatedAt: DateTime
|
||||||
wasOnlineAt: DateTime
|
|
||||||
ratings: [Rating]
|
ratings: [Rating]
|
||||||
bio: String
|
bio: String
|
||||||
notifications: [Int]
|
notifications: [Int]
|
||||||
|
|
|
@ -3,14 +3,6 @@ from os import environ
|
||||||
PORT = 8080
|
PORT = 8080
|
||||||
INBOX_SERVICE_PORT = 8081
|
INBOX_SERVICE_PORT = 8081
|
||||||
|
|
||||||
BACKEND_URL = environ.get("BACKEND_URL") or "https://localhost:8080"
|
|
||||||
OAUTH_CALLBACK_URL = environ.get("OAUTH_CALLBACK_URL") or "https://localhost:8080"
|
|
||||||
CONFIRM_CALLBACK_URL = "https://new.discours.io/confirm"
|
|
||||||
CONFIRM_EMAIL_URL = environ.get("AUTH_CONFIRM_URL") or BACKEND_URL + "/confirm"
|
|
||||||
ERROR_URL_ON_FRONTEND = (
|
|
||||||
environ.get("ERROR_URL_ON_FRONTEND") or "https://new.discours.io"
|
|
||||||
)
|
|
||||||
|
|
||||||
DB_URL = (
|
DB_URL = (
|
||||||
environ.get("DATABASE_URL") or environ.get("DB_URL") or
|
environ.get("DATABASE_URL") or environ.get("DB_URL") or
|
||||||
"postgresql://postgres@localhost:5432/discoursio" or "sqlite:///db.sqlite3"
|
"postgresql://postgres@localhost:5432/discoursio" or "sqlite:///db.sqlite3"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user