修改email为配置项

This commit is contained in:
wcq 2023-12-06 12:04:11 +08:00
parent 156079283c
commit 59076d751d
5 changed files with 24 additions and 30 deletions

View File

@ -18,9 +18,9 @@ db = file_receive
host = 127.0.0.1
port = 6379
[email]
api = http://116.63.130.34:30001
sender = fecribd@fecr.com.cn
;[email]
;api = http://116.63.130.34:30001
;sender = fecribd@fecr.com.cn
[fastapi_mail]
@ -57,10 +57,9 @@ signature = 远东资信
status_call_back = ""
[app]
port = 8008
title = 中小商业企业评级系统
sys_name = wd-smebiz
;host = https://testapi.fecribd.com
port = 8041
title = 文件接收管理系统
sys_name = file-receive
[tianyancha]
token = 32737167-cb63-4ce9-9397-d66169488f51

View File

@ -12,20 +12,14 @@ user = postgres
password = 12345
db = file_receive
[postgresql_v2]
host = db
post = 5432
user = postgres
password = 12345
db = wd_smebiz_v2
[redis]
host = redis
port = 6379
[email]
api = http://email_api:30001
sender = fecribd@fecr.com.cn
;[email]
;api = http://email_api:30001
;sender = fecribd@fecr.com.cn
[fastapi_mail]
MAIL_USERNAME = dogbillions@163.com
@ -61,9 +55,9 @@ signature = 远东资信
status_call_back = ""
[app]
port = 8008
title = 中小商业企业评级系统
sys_name = wd-smebiz
port = 8041
title = 文件接收管理系统
sys_name = file-receive
host = http://139.9.155.218
[tianyancha]

View File

@ -23,6 +23,7 @@ uvicorn_log = getLogger('uvicorn')
# 配置数据
conf = ConfigParser()
conf.optionxform = str
start_model = "dev"
if 'prod' in sys.argv:
start_model = 'prod'
@ -78,8 +79,6 @@ mg_db = MongoConnect(conf["mongo"]["host"], int(conf["mongo"]["port"]),
conf["mongo"]["db"],
conf["mongo"].get('user'),
conf["mongo"].get("password"))
# 邮箱验证码工具类
email_verify_code = EmailVerifyCode(redis_pool, conf['email']['api'], conf['email']['sender'])
# 图片验证码工具类
image_captcha_verify = ImageCaptchaVerify(redis_pool)
@ -98,6 +97,8 @@ phone_verify_code = PhoneVerifyCode(redis_pool, phone_msg_send)
tianyancha_api = TianyanchaApi(conf['tianyancha']['token'], mongo_connect=mg_db)
# 全局配置
# 邮件发送工具
email_tool = EmailTool(conf['fastapi_mail'].__dict__)
email_tool = EmailTool(dict(conf['fastapi_mail']))
# 邮箱验证码工具类
email_verify_code = EmailVerifyCode(redis_pool, email_tool)

View File

@ -24,12 +24,12 @@ class EmailTool:
MAIL_FROM_NAME="维德团队",
"""
conf = ConnectionConfig(
**conf_dic,
MAIL_STARTTLS=True,
MAIL_SSL_TLS=False,
USE_CREDENTIALS=True,
VALIDATE_CERTS=True,
**conf_dic,
MAIL_PORT=int(conf_dic.get('MAIL_PORT', 25))
# MAIL_PORT=int(conf_dic.get('MAIL_PORT', 25))
)
self.conf = conf
self.fm = FastMail(conf)

View File

@ -4,7 +4,6 @@ import requests
from enum import Enum
from captcha.image import ImageCaptcha
from context.common import email_tool
from utils.email_utils import send_email
from utils.random_utils import get_random_num_code, get_random_letter_and_num_code
from utils.redis_utils import RedisPool
@ -46,10 +45,11 @@ class ImageCaptchaVerify:
class EmailVerifyCode:
def __init__(self, redis_pool: RedisPool, email_api: str, email_sender: str, id_sign="EmailVerifyCodeId"):
def __init__(self, redis_pool: RedisPool,email_tool, id_sign="EmailVerifyCodeId"):
self.redis_pool = redis_pool
self.email_api = email_api
self.email_sender = email_sender
self.email_tool = email_tool
# self.email_api = email_api
# self.email_sender = email_sender
self.id_sign = id_sign
def get_email_id(self, email, verify_type: EmailVerifyType = EmailVerifyType.login):
@ -80,7 +80,7 @@ class EmailVerifyCode:
title = "修改信息验证码"
elif verify_type == EmailVerifyType.reset_password:
title = "修改密码验证码"
email_tool.send_email(title, email, code)
self.email_tool.send_email(title, email, code)
def check_code(self, email, code, verify_type: EmailVerifyType = EmailVerifyType.login):
email_id = self.get_email_id(email, verify_type)