working on verification email sending
This commit is contained in:
@@ -1,2 +1,22 @@
|
|||||||
"""Send emails for account verification through Resend API"""
|
"""Send emails for account verification through Resend API"""
|
||||||
import resend
|
from slopserver.settings import settings
|
||||||
|
import resend
|
||||||
|
|
||||||
|
resend.api_key = settings.resend_token
|
||||||
|
|
||||||
|
def send_email(to: str, subject, content):
|
||||||
|
params: resend.Emails.SendParams = {
|
||||||
|
"from": "slopfarmer@jack-case.pro",
|
||||||
|
"to": to,
|
||||||
|
"subject": subject,
|
||||||
|
"html": content
|
||||||
|
}
|
||||||
|
|
||||||
|
email: resend.Emails.SendResponse = resend.Emails.send(params)
|
||||||
|
|
||||||
|
return email
|
||||||
|
|
||||||
|
def generate_verification_email(verification_url: str):
|
||||||
|
return f"""
|
||||||
|
<p>click here to verify your Slop Farmer account: <a href={verification_url}>{verification_url}</a></p>
|
||||||
|
"""
|
||||||
@@ -87,6 +87,17 @@ def generate_auth_token(username):
|
|||||||
encoded_jwt = jwt.encode(bearer_token, TOKEN_SECRET, ALGO)
|
encoded_jwt = jwt.encode(bearer_token, TOKEN_SECRET, ALGO)
|
||||||
return encoded_jwt
|
return encoded_jwt
|
||||||
|
|
||||||
|
def generate_verification_token(username):
|
||||||
|
expiration = datetime.now() + timedelta(days=2)
|
||||||
|
verification_token = {
|
||||||
|
"iss": "slopserver",
|
||||||
|
"exp": int(expiration.timestamp()),
|
||||||
|
"sub": username
|
||||||
|
}
|
||||||
|
|
||||||
|
encoded_jwt = jwt.encode(verification_token, TOKEN_SECRET, ALGO)
|
||||||
|
return encoded_jwt
|
||||||
|
|
||||||
def get_token_user(decoded_token):
|
def get_token_user(decoded_token):
|
||||||
user = get_user(decoded_token["sub"], DB_ENGINE)
|
user = get_user(decoded_token["sub"], DB_ENGINE)
|
||||||
return user
|
return user
|
||||||
@@ -128,6 +139,14 @@ def signup_form(form_data: Annotated[SignupForm, Form()]):
|
|||||||
# create user
|
# create user
|
||||||
create_user(form_data.email, get_password_hash(form_data.password.get_secret_value()), DB_ENGINE)
|
create_user(form_data.email, get_password_hash(form_data.password.get_secret_value()), DB_ENGINE)
|
||||||
|
|
||||||
|
# send verification email
|
||||||
|
# create a jwt encoding the username and a time limit to be the verification URL
|
||||||
|
|
||||||
|
@app.get("/verify")
|
||||||
|
def verify_email(token: str):
|
||||||
|
get_user()
|
||||||
|
|
||||||
|
|
||||||
@app.get("/altcha-challenge")
|
@app.get("/altcha-challenge")
|
||||||
def altcha_challenge():
|
def altcha_challenge():
|
||||||
options = ChallengeOptions(
|
options = ChallengeOptions(
|
||||||
|
|||||||
@@ -7,4 +7,6 @@ class ServerSettings(BaseSettings):
|
|||||||
altcha_secret: str = "0460de065912d0292df1e7422a5ed2dc362ed56d6bab64fe50b89957463061f3"
|
altcha_secret: str = "0460de065912d0292df1e7422a5ed2dc362ed56d6bab64fe50b89957463061f3"
|
||||||
resend_token: str = "re_NXpjzbqR_KgAbu72PKjYHcquX24WvnN3i"
|
resend_token: str = "re_NXpjzbqR_KgAbu72PKjYHcquX24WvnN3i"
|
||||||
|
|
||||||
|
sender_email: str = "slopfarmer@jack-case.pro"
|
||||||
|
|
||||||
settings = ServerSettings()
|
settings = ServerSettings()
|
||||||
|
|||||||
Reference in New Issue
Block a user