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