diff --git a/auth/email.py b/auth/email.py index f99dcb64..c7c44fe2 100644 --- a/auth/email.py +++ b/auth/email.py @@ -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 " % MAILGUN_DOMAIN +api_url = "https://api.mailgun.net/v3/%s/messages" % MAILGUN_DOMAIN +noreply = "discours.io " % MAILGUN_DOMAIN + +tmplt = """ + Follow the link to authorize + + """ + +baseUrl = "https://new.discours.io" async def send_auth_email(user, token): - text = """ - Follow the link to authorize - - """ - to = "%s <%s>" % (user.username, user.email) - url_with_token = "%s/confirm-email/%s" % (BACKEND_URL, token) - text = text % url_with_token - response = requests.post( - MAILGUN_API_URL, - auth=("api", MAILGUN_API_KEY), - data={ - "from": MAILGUN_FROM, - "to": to, - "subject": "Confirm email", - "html": text, - }, - ) - response.raise_for_status() + try: + to = "%s <%s>" % (user.username, user.email) + url_with_token = "%s/confirm/%s" % (baseUrl, token) + response = requests.post( + api_url, + auth=("api", MAILGUN_API_KEY), + data={ + "from": noreply, + "to": to, + "subject": "Confirm email", + "html": tmplt % url_with_token, + }, + ) + response.raise_for_status() + except Exception as e: + print(e) diff --git a/migration/tables/content_items.py b/migration/tables/content_items.py index 2bccd7f7..88e6aec1 100644 --- a/migration/tables/content_items.py +++ b/migration/tables/content_items.py @@ -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) diff --git a/migration/tables/users.py b/migration/tables/users.py index 53f1da57..811ffce0 100644 --- a/migration/tables/users.py +++ b/migration/tables/users.py @@ -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"] = ( diff --git a/orm/user.py b/orm/user.py index 638d4a2d..4ab3fe12 100644 --- a/orm/user.py +++ b/orm/user.py @@ -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") diff --git a/resolvers/auth.py b/resolvers/auth.py index eabd6479..02210ad8 100644 --- a/resolvers/auth.py +++ b/resolvers/auth.py @@ -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: diff --git a/schema.graphql b/schema.graphql index b779a62f..4017b5fb 100644 --- a/schema.graphql +++ b/schema.graphql @@ -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] diff --git a/settings.py b/settings.py index 8dd30033..3ff5d282 100644 --- a/settings.py +++ b/settings.py @@ -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"