支持短信找回密码功能

dependabot/npm_and_yarn/fir_admin/tmpl-1.0.5
youngS 3 years ago
parent a8e8402eff
commit 37df9f4a5d
  1. 2
      fir_admin/.env.development
  2. 46
      fir_client/src/components/FirResetPwd.vue
  3. 12
      fir_ser/api/utils/sendmsg/aliyunApi.py
  4. 14
      fir_ser/api/utils/sendmsg/emailApi.py
  5. 12
      fir_ser/api/utils/sendmsg/jiguangApi.py
  6. 20
      fir_ser/api/utils/sendmsg/sendmsg.py
  7. 14
      fir_ser/api/utils/utils.py
  8. 37
      fir_ser/api/views/login.py
  9. 27
      fir_ser/config.py

@ -2,4 +2,4 @@
ENV = 'development'
# base api
VUE_APP_BASE_API = 'https://app.hehelucky.cn/api/v3/fir/server'
VUE_APP_BASE_API = 'https://flyapps.cn/api/v3/fir/server'

@ -14,7 +14,7 @@
<el-main>
<el-form ref="form" :model="form">
<el-form-item>
<el-input v-model="form.email" prefix-icon="el-icon-user" placeholder="邮箱" autofocus
<el-input v-model="form.email" prefix-icon="el-icon-user" placeholder="邮箱或手机号" autofocus
clearable/>
</el-form-item>
<el-form-item style="height: 40px" v-if="cptch.cptch_image">
@ -59,6 +59,7 @@
<script>
import {loginFun} from "@/restful";
import {checkEmail, geetest} from "@/utils";
import {checkphone} from "../utils";
export default {
name: "FirResetPwd",
@ -95,26 +96,27 @@
}
if (cptch_flag) {
let checke = checkEmail(this.form.email);
if (!checke) {
this.$message({
message: '邮箱输入有误',
type: 'error'
});
return
}
let params = {
"username": email,
"authcode": authcode,
"cptch_key": this.cptch.cptch_key,
"login_type": 'reset',
};
this.login_disable = true;
if (this.cptch.geetest) {
geetest(this, params, (n_params) => {
this.do_login(n_params);
})
} else {
this.do_login(params)
let checkp = checkphone(this.form.email);
if(checke||checkp){
let params = {
"username": email,
"authcode": authcode,
"cptch_key": this.cptch.cptch_key,
"login_type": 'reset',
};
this.login_disable = true;
if (this.cptch.geetest) {
geetest(this, params, (n_params) => {
this.do_login(n_params);
})
} else {
this.do_login(params)
}
}else {
this.$message({
message: '邮箱或手机号输入有误',
type: 'error'
});
}
} else {
@ -128,7 +130,7 @@
loginFun(data => {
if (data.code === 1000) {
this.$message({
message: '密码重置成功,请登录邮箱查看邮件',
message: '密码重置成功,请登录邮箱或者手机短信查看',
type: 'success'
});

@ -38,11 +38,7 @@ class AliMsgSender(object):
else:
return False, data.get('Message')
def send_register_msg(self, phone, code):
return self.send_msg(self.template_code.get('register'), phone, code)
def send_change_msg(self, phone, code):
return self.send_msg(self.template_code.get('change'), phone, code)
def send_login_msg(self, phone, code):
return self.send_msg(self.template_code.get('login'), phone, code)
def send_msg_by_act(self, phone, code, act):
if act not in self.template_code.keys():
return False, f'act {act} not found'
return self.send_msg(self.template_code.get(act), phone, code)

@ -41,18 +41,14 @@ class EmailMsgSender(object):
except Exception as e:
return False, e
def send_register_msg(self, phone, code):
return self.send_msg(self.template_code.get('register'), phone, code)
def send_change_msg(self, phone, code):
return self.send_msg(self.template_code.get('change'), phone, code)
def send_login_msg(self, phone, code):
return self.send_msg(self.template_code.get('login'), phone, code)
def send_email_msg(self, email, text):
try:
response = send_mail("重要消息通知", text, self.form, [email], )
except Exception as e:
return -1, e
return response, text
def send_msg_by_act(self, phone, code, act):
if act not in self.template_code.keys():
return False, f'act {act} not found'
return self.send_msg(self.template_code.get(act), phone, code)

@ -43,11 +43,7 @@ class JiGuangMsgSender(object):
else:
return False, response.get('error')
def send_register_msg(self, phone, code):
return self.send_msg(self.template_code.get('register'), phone, code)
def send_change_msg(self, phone, code):
return self.send_msg(self.template_code.get('change'), phone, code)
def send_login_msg(self, phone, code):
return self.send_msg(self.template_code.get('login'), phone, code)
def send_msg_by_act(self, phone, code, act):
if act not in self.template_code.keys():
return False, f'act {act} not found'
return self.send_msg(self.template_code.get(act), phone, code)

@ -61,23 +61,13 @@ class SendMessage(object):
logger.error(f"get {send_type} sender failed Exception:{e}")
self.sender = None
def send_register_msg(self, target, code):
status, msg = self.sender.send_register_msg(target, code)
logger.info(f"send_register_msg target:{target} code:{code} status:{status} msg:{msg}")
return status, msg
def send_change_msg(self, target, code):
status, msg = self.sender.send_change_msg(target, code)
logger.info(f"send_change_msg target:{target} code:{code} status:{status} msg:{msg}")
return status, msg
def send_login_msg(self, target, code):
status, msg = self.sender.send_login_msg(target, code)
logger.info(f"send_login_msg target:{target} code:{code} status:{status} msg:{msg}")
return status, msg
def send_email_msg(self, email, text):
if self.send_type == 'email':
status, msg = self.sender.send_email_msg(email, text)
logger.info(f"send_email_msg target:{email} text:{text} status:{status} msg:{msg}")
return status, msg
def send_msg_by_act(self, target, code, act):
status, msg = self.sender.send_msg_by_act(target, code, act)
logger.info(f"send_{act}_msg target:{target} code:{code} status:{status} msg:{msg}")
return status, msg

@ -95,14 +95,12 @@ def upload_oss_default_head_img(user_obj, storage_obj):
def get_sender_token(sender, user_id, target, action, msg=None):
code = generate_numeric_token_of_length(6)
if msg:
code = msg
token = make_token(code, time_limit=300, key=user_id)
TmpCache.set_tmp_cache(user_id, token, target)
if action == 'change':
sender.send_change_msg(target, code)
elif action == 'register':
sender.send_register_msg(target, code)
elif action == 'login':
sender.send_login_msg(target, code)
if action in ('change', 'password', 'register', 'login'):
sender.send_msg_by_act(target, code, action)
elif action == 'msg':
sender.send_email_msg(target, msg)
else:
@ -111,9 +109,9 @@ def get_sender_token(sender, user_id, target, action, msg=None):
return token, code
def get_sender_sms_token(key, phone, action):
def get_sender_sms_token(key, phone, action, msg=None):
sender = SendMessage('sms')
return get_sender_token(sender, key, phone, action)
return get_sender_token(sender, key, phone, action, msg)
def is_valid_sender_code(key, token, code):

@ -7,7 +7,7 @@ from django.core.cache import cache
from rest_framework.views import APIView
from api.utils.utils import get_captcha, valid_captcha, \
get_sender_sms_token, is_valid_sender_code, get_sender_email_token, get_random_username, \
check_username_exists, set_user_token
check_username_exists, set_user_token, get_sender_token
from api.utils.baseutils import is_valid_phone, is_valid_email, get_min_default_domain_cname_obj
from api.utils.auth import ExpiringTokenAuthentication
from api.utils.response import BaseResponse
@ -16,7 +16,6 @@ from api.utils.storage.caches import login_auth_failed
import logging
from api.utils.geetest.geetest_utils import first_register, second_validate
from api.utils.throttle import VisitRegister1Throttle, VisitRegister2Throttle, GetAuthC1Throttle, GetAuthC2Throttle
from api.utils.storage.storage import Storage
logger = logging.getLogger(__name__)
@ -205,21 +204,37 @@ class LoginView(APIView):
login_type = receive.get("login_type", None)
if login_auth_failed("get", username):
if login_type == 'reset':
user1_obj = None
user2_obj = None
if is_valid_email(username):
user_obj = UserInfo.objects.filter(email=username).first()
if user_obj:
password = get_random_username()[:16]
msg = '您的新密码为 %s 请用新密码登录之后,及时修改密码' % password
a, b = get_sender_email_token('email', username, 'msg', msg)
user1_obj = UserInfo.objects.filter(email=username).first()
if is_valid_phone(username):
user2_obj = UserInfo.objects.filter(mobile=username).first()
if user1_obj or user2_obj:
user_obj = user1_obj if user1_obj else user2_obj
password = get_random_username()[:16]
if login_auth_failed("get", user_obj.uid):
login_auth_failed("set", user_obj.uid)
if user2_obj:
a, b = get_sender_sms_token('sms', username, 'password', password)
else:
a, b = get_sender_email_token('email', username, 'password', password)
if a and b:
reset_user_pwd(user_obj, password)
login_auth_failed("del", username)
logger.warning(f'{user_obj} 找回密码成功,您的新密码为 {password} 请用新密码登录之后,及时修改密码')
else:
response.code = 1007
response.msg = "密码重置失败,请稍后重试或者联系管理员"
else:
response.code = 1002
response.msg = "邮箱不存在"
response.code = 1008
response.msg = "手机或者邮箱已经超过最大发送,请24小时后重试"
else:
response.code = 1003
response.msg = "无效邮箱"
response.code = 1002
response.msg = "邮箱或者手机号不存在"
return Response(response.dict)
password = receive.get("password")

@ -82,7 +82,7 @@ class AUTHCONF(object):
"captcha": False, # 是否开启注册字母验证码
"geetest": True, # 是否开启geetest验证,如要开启请先配置geetest
"change_type": {
'sms': False, # 短信注册
'sms': True, # 短信注册
'email': True, # 邮件注册
'code': False, # 邀请码注册,邀请码必填写,需要和短信,邮件一起使用
}
@ -159,9 +159,10 @@ class SENDERCONF(object):
'form': 'FlyApp Validation <flyapps@126.com>',
'subject': '%(code)s验证',
'template_code': {
'login': '欢迎使用FLY 应用分发平台。 您的验证码%(code)s,您正在登录,若非本人操作,请勿泄露。',
'change': '欢迎使用FLY 应用分发平台。 您的验证码%(code)s,您正在尝试变更重要信息,请妥善保管账户信息。',
'register': '欢迎使用FLY 应用分发平台。 您的验证码%(code)s,您正在注册成为新用户,感谢您的支持!',
'login': '欢迎使用FLY 应用分发平台。 您的验证码%(code)s ,您正在登录,若非本人操作,请勿泄露。',
'change': '欢迎使用FLY 应用分发平台。 您的验证码%(code)s ,您正在尝试变更重要信息,请妥善保管账户信息。',
'register': '欢迎使用FLY 应用分发平台。 您的验证码%(code)s ,您正在注册成为新用户,感谢您的支持!',
'password': '欢迎使用FLY 应用分发平台。 您的新密码为%(code)s , 请用新密码登录之后,及时修改密码,并妥善保管账户信息。'
}
},
'active': True
@ -170,17 +171,18 @@ class SENDERCONF(object):
'name': 'aliyun',
'type': 1,
'auth': {
'access_key': 'xxxx',
'secret_key': 'xxxx',
'access_key': 'LTAI5tJH2EnjVzJGMmNCYo9U',
'secret_key': 'd0LETks5oxkdfbkLGtFihklWGbokab',
'region_id': 'cn-hangzhou',
'sing_name': 'FLY应用分发',
'sing_name': '东城飞阳',
'template_code': {
'login': 'SMS_88888',
'change': 'SMS_88888',
'register': 'SMS_8888',
'login': 'SMS_216700569',
'change': 'SMS_216700566',
'register': 'SMS_216700567',
'password': 'SMS_222341718'
}
},
'active': False
'active': True
},
{
'name': 'jiguang',
@ -193,9 +195,10 @@ class SENDERCONF(object):
'login': '1',
'change': '1',
'register': '1',
'password': '1'
}
},
'active': True
'active': False
},
]

Loading…
Cancel
Save