hotfix-loadchats
This commit is contained in:
parent
90e8e24743
commit
8377043286
|
@ -10,13 +10,13 @@ lang_subject = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def send_auth_email(user, token, lang="ru"):
|
async def send_auth_email(user, token, template="email_confirmation", lang="ru"):
|
||||||
try:
|
try:
|
||||||
to = "%s <%s>" % (user.name, user.email)
|
to = "%s <%s>" % (user.name, user.email)
|
||||||
if lang not in ['ru', 'en']:
|
if lang not in ['ru', 'en']:
|
||||||
lang = 'ru'
|
lang = 'ru'
|
||||||
subject = lang_subject.get(lang, lang_subject["en"])
|
subject = lang_subject.get(lang, lang_subject["en"])
|
||||||
template = "email_confirmation_" + lang
|
template = template + "_" + lang
|
||||||
payload = {
|
payload = {
|
||||||
"from": noreply,
|
"from": noreply,
|
||||||
"to": to,
|
"to": to,
|
||||||
|
|
|
@ -133,7 +133,7 @@ async def register_by_email(_, _info, email: str, password: str = "", name: str
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("sendLink")
|
@mutation.field("sendLink")
|
||||||
async def auth_send_link(_, _info, email, lang="ru"):
|
async def auth_send_link(_, _info, email, lang="ru", template="email_confirmation"):
|
||||||
"""send link with confirm code to email"""
|
"""send link with confirm code to email"""
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
user = session.query(User).filter(User.email == email).first()
|
user = session.query(User).filter(User.email == email).first()
|
||||||
|
@ -141,7 +141,7 @@ async def auth_send_link(_, _info, email, lang="ru"):
|
||||||
raise ObjectNotExist("User not found")
|
raise ObjectNotExist("User not found")
|
||||||
else:
|
else:
|
||||||
token = await TokenStorage.create_onetime(user)
|
token = await TokenStorage.create_onetime(user)
|
||||||
await send_auth_email(user, token, lang)
|
await send_auth_email(user, token, lang, template)
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ from auth.authenticate import login_required
|
||||||
from base.redis import redis
|
from base.redis import redis
|
||||||
from base.orm import local_session
|
from base.orm import local_session
|
||||||
from base.resolvers import query
|
from base.resolvers import query
|
||||||
from base.exceptions import ObjectNotExist
|
from base.exceptions import ObjectNotExist, Unauthorized
|
||||||
from orm.user import User
|
from orm.user import User
|
||||||
from resolvers.zine.profile import followed_authors
|
from resolvers.zine.profile import followed_authors
|
||||||
from .unread import get_unread_counter
|
from .unread import get_unread_counter
|
||||||
|
@ -31,7 +31,10 @@ async def load_messages(chat_id: str, limit: int, offset: int):
|
||||||
async def load_chats(_, info, limit: int = 50, offset: int = 0):
|
async def load_chats(_, info, limit: int = 50, offset: int = 0):
|
||||||
""" load :limit chats of current user with :offset """
|
""" load :limit chats of current user with :offset """
|
||||||
user = info.context["request"].user
|
user = info.context["request"].user
|
||||||
print('[inbox] load user\'s chats')
|
if user:
|
||||||
|
print('[inbox] load user\'s chats %s' % user.slug)
|
||||||
|
else:
|
||||||
|
raise Unauthorized("Please login to load chats")
|
||||||
cids = await redis.execute("SMEMBERS", "chats_by_user/" + user.slug)
|
cids = await redis.execute("SMEMBERS", "chats_by_user/" + user.slug)
|
||||||
if cids:
|
if cids:
|
||||||
cids = list(cids)[offset:offset + limit]
|
cids = list(cids)[offset:offset + limit]
|
||||||
|
@ -47,15 +50,14 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0):
|
||||||
c['unread'] = await get_unread_counter(cid, user.slug)
|
c['unread'] = await get_unread_counter(cid, user.slug)
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
c['members'] = []
|
c['members'] = []
|
||||||
for user in c["users"]:
|
for userslug in c["users"]:
|
||||||
a = session.query(User).where(User.slug == user).first().dict()
|
a = session.query(User).where(User.slug == userslug).first().dict()
|
||||||
c['members'].append({
|
c['members'].append({
|
||||||
"slug": user,
|
"slug": userslug,
|
||||||
"userpic": a["userpic"],
|
"userpic": a["userpic"],
|
||||||
"name": a["name"],
|
"name": a["name"],
|
||||||
"lastSeen": a["lastSeen"],
|
"lastSeen": a["lastSeen"],
|
||||||
})
|
})
|
||||||
del c["users"]
|
|
||||||
chats.append(c)
|
chats.append(c)
|
||||||
return {
|
return {
|
||||||
"chats": chats,
|
"chats": chats,
|
||||||
|
@ -66,7 +68,7 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0):
|
||||||
@query.field("loadMessagesBy")
|
@query.field("loadMessagesBy")
|
||||||
@login_required
|
@login_required
|
||||||
async def load_messages_by(_, info, by, limit: int = 50, offset: int = 0):
|
async def load_messages_by(_, info, by, limit: int = 50, offset: int = 0):
|
||||||
''' load :amolimitunt messages of :chat_id with :offset '''
|
''' load :limit messages of :chat_id with :offset '''
|
||||||
messages = set([])
|
messages = set([])
|
||||||
by_chat = by.get('chat')
|
by_chat = by.get('chat')
|
||||||
if by_chat:
|
if by_chat:
|
||||||
|
|
|
@ -160,7 +160,7 @@ type Mutation {
|
||||||
# auth
|
# auth
|
||||||
getSession: AuthResult!
|
getSession: AuthResult!
|
||||||
registerUser(email: String!, password: String, name: String): AuthResult!
|
registerUser(email: String!, password: String, name: String): AuthResult!
|
||||||
sendLink(email: String!, lang: String): Result!
|
sendLink(email: String!, lang: String, template: String): Result!
|
||||||
confirmEmail(token: String!): AuthResult!
|
confirmEmail(token: String!): AuthResult!
|
||||||
|
|
||||||
# shout
|
# shout
|
||||||
|
|
Loading…
Reference in New Issue
Block a user