Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mancheng
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mancheng
Commits
44f5c078
Commit
44f5c078
authored
Mar 04, 2022
by
dong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix20220304
parent
0765685d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
91 deletions
+98
-91
apps/util.py
+3
-7
apps/view_radar/view.py
+1
-1
apps/view_user/view.py
+94
-83
No files found.
apps/util.py
View file @
44f5c078
...
@@ -6,6 +6,8 @@ from flask import request, jsonify, current_app
...
@@ -6,6 +6,8 @@ from flask import request, jsonify, current_app
from
config
import
Config
from
config
import
Config
# from apps.models import User, Bstage
# from apps.models import User, Bstage
import
functools
import
functools
# from flask_httpauth import HTTPBasicAuth
# from flask_httpauth import HTTPBasicAuth
#
#
# auth = HTTPBasicAuth
# auth = HTTPBasicAuth
...
@@ -27,7 +29,7 @@ def create_token(api_user):
...
@@ -27,7 +29,7 @@ def create_token(api_user):
# 第一个参数是内部的私钥,第二个参数是有效期(秒)
# 第一个参数是内部的私钥,第二个参数是有效期(秒)
s
=
Serializer
(
current_app
.
config
[
"SECRET_KEY"
],
expires_in
=
Config
.
TOKEN_EXPIRATION
)
s
=
Serializer
(
current_app
.
config
[
"SECRET_KEY"
],
expires_in
=
Config
.
TOKEN_EXPIRATION
)
# 接收用户id转换与编码
# 接收用户id转换与编码
token
=
s
.
dumps
({
"id"
:
api_user
,
"type"
:
"登录验证"
})
.
decode
(
"ascii"
)
token
=
s
.
dumps
({
"id"
:
api_user
,
"type"
:
"登录验证"
})
.
decode
(
"ascii"
)
return
token
return
token
...
@@ -94,9 +96,3 @@ def login_required(view_func):
...
@@ -94,9 +96,3 @@ def login_required(view_func):
return
view_func
(
*
args
,
**
kwargs
)
return
view_func
(
*
args
,
**
kwargs
)
return
verify_token
return
verify_token
apps/view_radar/view.py
View file @
44f5c078
...
@@ -336,7 +336,7 @@ def recommond():
...
@@ -336,7 +336,7 @@ def recommond():
# if not all([name]):
# if not all([name]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
try
:
try
:
enterprise
=
Enterprise
.
query
.
filter
(
Enterprise
.
product_all
.
like
(
"
%
{}
%
"
.
format
(
name
)))
enterprise
=
Enterprise
.
query
.
filter
(
Enterprise
.
city
!=
'晋城市'
,
Enterprise
.
product_all
.
like
(
"
%
{}
%
"
.
format
(
name
)))
size
=
enterprise
.
count
()
size
=
enterprise
.
count
()
enterprise
=
enterprise
.
order_by
(
Enterprise
.
c_type
,
Enterprise
.
hots
.
desc
())
.
paginate
(
page
,
enterprise
=
enterprise
.
order_by
(
Enterprise
.
c_type
,
Enterprise
.
hots
.
desc
())
.
paginate
(
page
,
perpage
)
.
items
# # 企业热度倒序
perpage
)
.
items
# # 企业热度倒序
...
...
apps/view_user/view.py
View file @
44f5c078
...
@@ -23,7 +23,7 @@ from apps.utils.vxconfig import WxConfig
...
@@ -23,7 +23,7 @@ from apps.utils.vxconfig import WxConfig
from
apps.utils.encrypt_decrypt.aes_cbc
import
encrypt
,
decrypt
from
apps.utils.encrypt_decrypt.aes_cbc
import
encrypt
,
decrypt
# 给手机发验证码
(2020-11-4)
# 给手机发验证码
@api_user.route
(
"/SendMobileCode"
,
methods
=
[
"POST"
])
@api_user.route
(
"/SendMobileCode"
,
methods
=
[
"POST"
])
def
send_phone_code
():
def
send_phone_code
():
'''
'''
...
@@ -68,7 +68,7 @@ def send_phone_code():
...
@@ -68,7 +68,7 @@ def send_phone_code():
return
jsonify
(
code
=
RET
.
THIRDERR
,
msg
=
"发送失败"
)
return
jsonify
(
code
=
RET
.
THIRDERR
,
msg
=
"发送失败"
)
# 手机验证码登录
(2020-11-4)
# 手机验证码登录
@api_user.route
(
"/LoginBySms"
,
methods
=
[
"POST"
])
@api_user.route
(
"/LoginBySms"
,
methods
=
[
"POST"
])
def
login_bysms
():
def
login_bysms
():
'''
'''
...
@@ -284,6 +284,97 @@ def register():
...
@@ -284,6 +284,97 @@ def register():
return
jsonify
(
code
=
RET
.
OK
,
msg
=
"注册成功"
)
return
jsonify
(
code
=
RET
.
OK
,
msg
=
"注册成功"
)
# 内部用户手机-密码登录
@api_user.route
(
"/LoginByPwd"
,
methods
=
[
"POST"
])
def
login_bypwd
():
'''
用户密码登录
:return:
'''
# 参数获取与校验
req_dict
=
request
.
get_json
()
# 解密
# param = req_dict.get("param") # 加密参数
# req_dict = json.loads(decrypt(param))
mobile
=
req_dict
.
get
(
'mobile'
)
password
=
req_dict
.
get
(
'password'
)
# 校验参数完整性
if
not
all
([
mobile
,
password
]):
return
jsonify
(
code
=
RET
.
PARAMERR
,
msg
=
"参数不完整"
)
# 校验手机号格式
if
not
re
.
match
(
r"1[23456789]\d{9}$"
,
mobile
):
return
jsonify
(
code
=
RET
.
PARAMERR
,
msg
=
"手机号错误"
)
# 判断错误次数是否超过限制,如果超过则10分钟内禁止此IP登录
user_ip
=
request
.
remote_addr
print
(
"IP地址:"
,
user_ip
)
# 获取ip的锁定时间
try
:
access_nums
=
redis_store
.
get
(
'access_nums_{}'
.
format
(
user_ip
))
if
access_nums
:
if
int
(
access_nums
.
decode
())
>=
constants
.
LOGIN_ERROR_TIMES
:
lock_time
=
redis_store
.
ttl
(
'access_nums_{}'
.
format
(
user_ip
))
return
jsonify
(
code
=
RET
.
LOCKTIME
,
msg
=
"ip锁定倒计时中....."
,
lock_time
=
lock_time
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
else
:
pass
try
:
access_nums
=
redis_store
.
get
(
'access_nums_{}'
.
format
(
user_ip
))
# access_nums = "123456"
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
else
:
if
access_nums
:
if
int
(
access_nums
.
decode
())
>=
constants
.
LOGIN_ERROR_TIMES
:
return
jsonify
(
code
=
RET
.
REQERR
,
msg
=
"错误次数过多,请15分钟后重试!"
,
time
=
constants
.
LOGIN_ERROR_FORBID_TIME
)
# 验证手机号与密码
try
:
user
=
User
.
query
.
filter_by
(
mobile
=
mobile
,
flag
=
2
)
.
first
()
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
jsonify
(
code
=
RET
.
DATAERR
,
msg
=
"获取用户信息失败"
)
if
not
user
:
return
jsonify
(
code
=
RET
.
DATAERR
,
msg
=
"账户不存在"
)
# 将用户名与密码验证放置在一处,若失败返回提示信息并记录次数
if
not
user
.
check_password
(
password
):
try
:
redis_store
.
incr
(
'access_nums_{}'
.
format
(
user_ip
))
redis_store
.
expire
(
'access_nums_{}'
.
format
(
user_ip
),
constants
.
LOGIN_ERROR_FORBID_TIME
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
jsonify
(
code
=
RET
.
DATAERR
,
msg
=
"密码错误"
)
if
user
.
status
==
0
:
# 被禁止
return
jsonify
(
code
=
RET
.
ROLEERR
,
msg
=
"账号被禁止,请联系管理员进行处理!"
)
# if user.status == 2: # 审核
# return jsonify(code=RET.ROLEERR, msg="审核暂未通过,请以外部访客身份登陆")
#
# if user.status == 3: # 驳回
# return jsonify(code=RET.ROLEERR, msg="您的审核未通过,请联系工作人员")
session
.
permanent
=
True
# 设置session在设定时间内有效 注意这个要设置在request里边 即请求内部
# 若成功保存登录状态
token
=
create_token
(
user
.
id
)
time
=
datetime
.
now
()
current_app
.
logger
.
error
(
'++++++++++++++++++++++++++++登录日志>>>{}:{}通过使用手机-密码登录成功了!+++++++++++++++++++++++=++'
.
format
(
time
,
mobile
))
return
jsonify
(
code
=
RET
.
OK
,
msg
=
"登录成功"
,
token
=
token
,
flag
=
user
.
flag
)
# # 异步邮箱发送信息
# # 异步邮箱发送信息
# def send_async_email(mail, app, msg):
# def send_async_email(mail, app, msg):
# with app.app_context():
# with app.app_context():
...
@@ -352,87 +443,7 @@ def register():
...
@@ -352,87 +443,7 @@ def register():
#
#
#
#
#
#
# # 内部用户手机-密码登录 (2020-11-4)
# @api_user.route("/login_bypwd", methods=["POST"])
# def login_bypwd():
# '''
# 用户密码登录
# :return:
# '''
# # 参数获取与校验
# req_dict = request.get_json()
# # 解密
# param = req_dict.get("param") # 揭秘参数
# req_dict = json.loads(decrypt(param))
# mobile = req_dict.get('mobile')
# password = req_dict.get('password')
# # 校验参数完整性
# if not all([mobile, password]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
#
# # 校验手机号格式
# if not re.match(r"1[23456789]\d{9}$", mobile):
# return jsonify(code=RET.PARAMERR, msg="手机号错误")
#
# # 判断错误次数是否超过限制,如果超过则10分钟内禁止此IP登录
# user_ip = request.remote_addr
# print("IP地址:", user_ip)
#
# # 获取ip的锁定时间
# try:
# access_nums = redis_store.get('access_nums_{}'.format(user_ip))
# if access_nums:
# if int(access_nums.decode()) >= constants.LOGIN_ERROR_TIMES:
# lock_time = redis_store.ttl('access_nums_{}'.format(user_ip))
# return jsonify(code=RET.LOCKTIME, msg="ip锁定倒计时中.....", lock_time=lock_time)
# except Exception as e:
# current_app.logger.error(e)
# else:
# pass
#
# try:
# access_nums = redis_store.get('access_nums_{}'.format(user_ip))
# # access_nums = "123456"
# except Exception as e:
# current_app.logger.error(e)
# else:
# if access_nums:
# if int(access_nums.decode()) >= constants.LOGIN_ERROR_TIMES:
# return jsonify(code=RET.REQERR, msg="错误次数过多,请15分钟后重试!", time=constants.LOGIN_ERROR_FORBID_TIME)
#
# # 验证手机号与密码
# try:
# user = User.query.filter_by(mobile=mobile, flag=2).first()
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DATAERR, msg="获取用户信息失败")
#
# if not user:
# return jsonify(code=RET.DATAERR, msg="账户不存在")
# # 将用户名与密码验证放置在一处,若失败返回提示信息并记录次数
# if not user.check_password(password):
# try:
# redis_store.incr('access_nums_{}'.format(user_ip))
# redis_store.expire('access_nums_{}'.format(user_ip), constants.LOGIN_ERROR_FORBID_TIME)
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DATAERR, msg="密码错误")
#
# if user.status == 2: # 审核
# return jsonify(code=RET.ROLEERR, msg="审核暂未通过,请以外部访客身份登陆")
#
# if user.status == 3: # 驳回
# return jsonify(code=RET.ROLEERR, msg="您的审核未通过,请联系工作人员")
#
# session.permanent = True # 设置session在设定时间内有效 注意这个要设置在request里边 即请求内部
# # 若成功保存登录状态
# token = create_token(user.id)
#
# time = datetime.now()
# current_app.logger.error(
# '++++++++++++++++++++++++++++登录日志>>>{}:{}通过使用手机-密码登录成功了!+++++++++++++++++++++++=++'.format(time, mobile))
#
# return jsonify(code=RET.OK, msg="登录成功", token=token, flag=user.flag)
#
#
#
#
# ''''''
# ''''''
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment