signIn via email
This commit is contained in:
parent
b36678a4ca
commit
6bdf994a28
|
@ -4,12 +4,12 @@ from starlette.exceptions import HTTPException
|
||||||
|
|
||||||
from auth.authenticate import EmailAuthenticate
|
from auth.authenticate import EmailAuthenticate
|
||||||
|
|
||||||
from settings import MAILGUN_API_KEY, MAILGUN_DOMAIN
|
from settings import BACKEND_URL, MAILGUN_API_KEY, MAILGUN_DOMAIN
|
||||||
|
|
||||||
MAILGUN_API_URL = "https://api.mailgun.net/v3/%s/messages" % (MAILGUN_DOMAIN)
|
MAILGUN_API_URL = "https://api.mailgun.net/v3/%s/messages" % (MAILGUN_DOMAIN)
|
||||||
MAILGUN_FROM = "postmaster <postmaster@%s>" % (MAILGUN_DOMAIN)
|
MAILGUN_FROM = "postmaster <postmaster@%s>" % (MAILGUN_DOMAIN)
|
||||||
|
|
||||||
AUTH_URL = "https://localhost:8080/email_authorize"
|
AUTH_URL = "%s/email_authorize" % (BACKEND_URL)
|
||||||
|
|
||||||
async def send_auth_email(user):
|
async def send_auth_email(user):
|
||||||
token = await EmailAuthenticate.get_email_token(user)
|
token = await EmailAuthenticate.get_email_token(user)
|
||||||
|
|
|
@ -41,12 +41,16 @@ async def register(*_, email: str, password: str = ""):
|
||||||
|
|
||||||
|
|
||||||
@query.field("signIn")
|
@query.field("signIn")
|
||||||
async def login(_, info: GraphQLResolveInfo, email: str, password: str):
|
async def login(_, info: GraphQLResolveInfo, email: str, password: str = ""):
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
orm_user = session.query(User).filter(User.email == email).first()
|
orm_user = session.query(User).filter(User.email == email).first()
|
||||||
if orm_user is None:
|
if orm_user is None:
|
||||||
return {"error" : "invalid email"}
|
return {"error" : "invalid email"}
|
||||||
|
|
||||||
|
if not password:
|
||||||
|
await send_auth_email(orm_user)
|
||||||
|
return {"error" : ""}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
device = info.context["request"].headers['device']
|
device = info.context["request"].headers['device']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
|
@ -81,7 +81,7 @@ type Mutation {
|
||||||
type Query {
|
type Query {
|
||||||
# auth
|
# auth
|
||||||
isEmailFree(email: String!): Result!
|
isEmailFree(email: String!): Result!
|
||||||
signIn(email: String!, password: String!): AuthResult!
|
signIn(email: String!, password: String): AuthResult!
|
||||||
signOut: Result!
|
signOut: Result!
|
||||||
# user profile
|
# user profile
|
||||||
getCurrentUser: UserResult!
|
getCurrentUser: UserResult!
|
||||||
|
|
|
@ -3,6 +3,8 @@ from os import environ
|
||||||
|
|
||||||
PORT = 8080
|
PORT = 8080
|
||||||
|
|
||||||
|
BACKEND_URL = "https://localhost:8080"
|
||||||
|
|
||||||
DB_URL = environ.get("DB_URL") or "sqlite:///db.sqlite3"
|
DB_URL = environ.get("DB_URL") or "sqlite:///db.sqlite3"
|
||||||
JWT_ALGORITHM = "HS256"
|
JWT_ALGORITHM = "HS256"
|
||||||
JWT_SECRET_KEY = "8f1bd7696ffb482d8486dfbc6e7d16dd-secret-key"
|
JWT_SECRET_KEY = "8f1bd7696ffb482d8486dfbc6e7d16dd-secret-key"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user