fix-lastseen

This commit is contained in:
tonyrewin 2022-10-05 18:54:29 +03:00
parent 0c882dfc44
commit 7084bdb1a9
7 changed files with 35 additions and 35 deletions

View File

@ -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
</body></html>
"""
to = "%s <%s>" % (user.username, user.email) to = "%s <%s>" % (user.username, user.email)
url_with_token = "%s/confirm-email/%s" % (BACKEND_URL, token) url_with_token = "%s/confirm/%s" % (baseUrl, token)
text = text % url_with_token
response = requests.post( response = requests.post(
MAILGUN_API_URL, api_url,
auth=("api", MAILGUN_API_KEY), auth=("api", MAILGUN_API_KEY),
data={ data={
"from": MAILGUN_FROM, "from": noreply,
"to": to, "to": to,
"subject": "Confirm email", "subject": "Confirm email",
"html": text, "html": tmplt % url_with_token,
}, },
) )
response.raise_for_status() response.raise_for_status()
except Exception as e:
print(e)

View File

@ -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)

View File

@ -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"] = (

View File

@ -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")

View File

@ -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:

View File

@ -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]

View File

@ -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"