代码拉取完成,页面将自动刷新
import smtplib
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
from peewee import *
from pycket.session import SessionMixin
import ctrl_base
from werkzeug.security import generate_password_hash, check_password_hash
import tornado.web
from database.XRedis import redis_0
from database.Xmongodb import mongo
from database.xMySQL_1 import PatientPatient, DoctorDoctor, objects, DrugDrugCategory, PatientPatientFrontFeedback, \
DoctorDoctorFrontFeedback, DoctorDoctorDepartments, DoctorDoctorSections, NewsNewsBlog, NewsNewsImg
from settings import email_code, email_from, email_from_name
from util.check_login import auth_login_redirect, ban_check, check_redirect
from util.utils import GetInformation, emailisValid, generate_verification_code, GetDataSensitive, GetFlowNumber, \
is_valid_date, send_qq_email
class ready(ctrl_base.BaseHandler):
async def get(self):
await self.render("ready.html")
class front_feedback_submit(ctrl_base.BaseHandler):
@tornado.web.authenticated
@auth_login_redirect
@ban_check
async def post(self):
feedback = self.get_argument('feedback')
type = self.get_secure_cookie('type')
username = self.get_secure_cookie('username')
message = {}
if 'patient' in str(type):
patient_id = self.get_secure_cookie('user_id')
info_1 = await objects.get(PatientPatient, patient_id=patient_id)
await objects.execute(PatientPatientFrontFeedback.insert(feedback=feedback,
patient_feedback_id=GetFlowNumber(
259,
task='Patient_front_feedback'),
patient_id=info_1.id,
status=False))
message['code'] = 200
elif 'doctor' in str(type):
doctor_id = self.get_secure_cookie('user_id')
print(doctor_id)
info_2 = await objects.get(DoctorDoctor, doctor_id=doctor_id)
await objects.execute(DoctorDoctorFrontFeedback.insert(feedback=feedback,
doctor_feedback_id=GetFlowNumber(272, task='Doctor_front_feedback'),
doctor_id=info_2.id,
status=False))
message['code'] = 200
else:
message['code'] = 500
print(message['code'])
await self.finish(message)
return
class error_500(ctrl_base.BaseHandler):
async def get(self):
current_type, current_username, current_user_id, find_0, find_0_0, find_0_1 = await self.get_base_config()
await self.render("error_500.html", find_0=find_0, current_type=current_type,
current_username=current_username, current_user_id=current_user_id,find_0_0=find_0_0,
find_0_1=find_0_1)
class error_503(ctrl_base.BaseHandler):
async def get(self):
current_type, current_username, current_user_id, find_0, find_0_0, find_0_1 = await self.get_base_config()
await self.render("error_503.html", find_0=find_0, current_type=current_type,
current_username=current_username, current_user_id=current_user_id,find_0_0=find_0_0,
find_0_1=find_0_1)
class error_403(ctrl_base.BaseHandler):
async def get(self):
current_type, current_username, current_user_id, find_0, find_0_0, find_0_1 = await self.get_base_config()
await self.render("error_403.html", find_0=find_0, current_type=current_type,
current_username=current_username, current_user_id=current_user_id,find_0_0=find_0_0,
find_0_1=find_0_1)
class error_offline(ctrl_base.BaseHandler):
async def get(self):
current_type, current_username, current_user_id, find_0, find_0_0, find_0_1 = await self.get_base_config()
await self.render("error_offline.html", find_0=find_0, current_type=current_type,
current_username=current_username, current_user_id=current_user_id,find_0_0=find_0_0,
find_0_1=find_0_1)
class front_index(ctrl_base.BaseHandler, SessionMixin):
@ban_check
async def get(self):
r = redis_0.zrevrange(name="news", start=0, end=-1)
rank = []
i = 0
m = 0
while i < len(r):
find = await objects.get(NewsNewsBlog, news_id=r[i])
find_img = await objects.execute(NewsNewsImg.select().where(NewsNewsImg.news_blog_id == find.id))
if find.status == 0:
pass
else:
if len(find_img) == 0:
img_url = '/static/img/slider/3.jpg'
else:
img_url = 'http://localhost:8081/' + find_img[0].img
view_count = int(redis_0.zscore('news', '{}'.format(find.news_id)))
info = {'id': m + 1, 'title': find.title, 'news_id': find.id, 'img_url':img_url, 'create_time':find.create_time.date(),'view_count':view_count}
rank.append(info)
m += 1
if m == 10:
break
i += 1
doc = await objects.execute(DoctorDoctor.select().where(DoctorDoctor.title == 'President',DoctorDoctor.status == 1))
for i in doc:
if i.img == '':
img_url = '/static/img/slider/3.jpg'
else:
img_url = 'http://localhost:8081/' + i.img
i.img_url = img_url
current_type, current_username, current_user_id, find_0, find_0_0, find_0_1 = await self.get_base_config()
await self.render("index.html", find_0=find_0, current_type=current_type,
current_username=current_username, current_user_id=current_user_id,find_0_0=find_0_0,
find_0_1=find_0_1,rank=rank,doc=doc)
class choose_identity(ctrl_base.BaseHandler, SessionMixin):
@ban_check
async def get(self):
current_type, current_username, current_user_id, find_0, find_0_0, find_0_1 = await self.get_base_config()
await self.render("choose_identity.html", find_0=find_0, current_type=current_type,
current_username=current_username, current_user_id=current_user_id,find_0_0=find_0_0,
find_0_1=find_0_1)
class logout(ctrl_base.BaseHandler):
@tornado.web.authenticated
@auth_login_redirect
async def get(self):
type = self.get_secure_cookie('type')
username = self.get_secure_cookie('username')
user_id = None
if 'patient' in str(type):
patient_id = self.get_secure_cookie('user_id')
user_id = str(patient_id).replace("b'", "").replace("'", "")
await objects.execute(
PatientPatient.update(is_online=False).where
(PatientPatient.username == username))
if 'doctor' in str(type):
doctor_id = self.get_secure_cookie('user_id')
user_id = str(doctor_id).replace("b'", "").replace("'", "")
await objects.execute(DoctorDoctor.update(is_online=False).where
(DoctorDoctor.doctor_id == doctor_id))
self.clear_cookie('username')
self.clear_cookie('type')
self.clear_cookie('user_id')
self.session.delete('username')
self.session.delete('type')
self.session.delete('user_id')
user = await mongo.user.find_one({'user':user_id})
url = check_redirect(user)
await mongo.user.update_one({'user': user_id}, {'$set': {'is_online': False}})
self.redirect('{}'.format(url))
return
# class logout(ctrl_base.BaseHandler):
# @tornado.web.authenticated
# @auth_login_redirect
# async def get(self):
# type = self.get_secure_cookie('type')
# username = self.get_secure_cookie('username')
# status = 1
# if 'patient' in str(type):
# patient_id = self.get_secure_cookie('user_id')
# await objects.execute(
# PatientPatient.update(is_online=False).where
# (PatientPatient.username == username))
# patient = await objects.get(PatientPatient,patient_id=patient_id)
# if patient.status == 0:
# status = 0
# self.clear_cookie('username')
# self.clear_cookie('type')
# self.clear_cookie('user_id')
# self.session.delete('username')
# self.session.delete('type')
# self.session.delete('user_id')
# if 'doctor' in str(type):
# doctor_id = self.get_secure_cookie('user_id')
# await objects.execute(DoctorDoctor.update(is_online=False).where
# (DoctorDoctor.doctor_id == doctor_id))
# doctor = await objects.get(DoctorDoctor,doctor_id=doctor_id)
# if doctor.status == 0:
# status = 0
# self.clear_cookie('username')
# self.clear_cookie('type')
# self.clear_cookie('user_id')
# self.session.delete('username')
# self.session.delete('type')
# self.session.delete('user_id')
# if status == 0:
# self.redirect('/error_403')
# else:
# self.redirect('/front_index')
# return
class doctor_login(ctrl_base.BaseHandler):
async def get(self):
await self.render("doctor_login.html")
return
async def post(self):
doctor_id = self.get_argument('account')
password = self.get_argument('password')
message = {}
try:
await objects.get(DoctorDoctor, doctor_id=doctor_id)
except DoesNotExist:
message['code'] = 402
else:
user = await objects.get(DoctorDoctor, doctor_id=doctor_id)
if user.status == 0:
message['code'] = 400
elif check_password_hash(user.password, password) == 1 and user.status == 1:
self.set_secure_cookie('username', user.name, path='/')
self.set_secure_cookie('user_id', doctor_id, path='/')
self.set_secure_cookie('type', 'doctor', path='/')
self.session.set('username', user.name)
self.session.set('user_id', doctor_id)
self.session.set('type', 'doctor')
await objects.execute(DoctorDoctor.update(is_online=True).where
(DoctorDoctor.doctor_id == doctor_id))
await mongo.user.update_one({'user': doctor_id}, {'$set': {'is_online': True}})
message['code'] = 200
else:
message['code'] = 401
await self.finish(message)
return
class patient_login(ctrl_base.BaseHandler):
async def get(self):
await self.render("patient_login.html")
return
async def post(self):
username = self.get_json_argument('username')
password = self.get_json_argument('password')
message = {}
try:
await objects.get(PatientPatient, username=username)
except DoesNotExist:
message['code'] = 401
else:
_password = await objects.get(PatientPatient, username=username)
if _password.status is False:
message['code'] = 402
elif check_password_hash(_password.password, password) is True and _password.status is True:
patient_id = _password.patient_id
print(patient_id)
self.set_secure_cookie('user_id', patient_id, path='/')
self.set_secure_cookie('username', username, path='/')
self.set_secure_cookie('type', 'patient', path='/')
self.session.set('username', username)
self.session.set('user_id', patient_id)
self.session.set('type', 'patient')
await objects.execute(
PatientPatient.update(is_online=True).where
(PatientPatient.username == username))
await mongo.user.update_one({'user': patient_id}, {'$set': {'is_online': True}})
message['code'] = 200
else:
message['code'] = 400
await self.finish(message)
return
class patient_register(ctrl_base.BaseHandler):
async def get(self):
await self.render("patient_register.html")
return
async def post(self):
register_username = self.get_json_argument('register_username')
register_password = self.get_json_argument('register_password')
register_confirm_password = self.get_json_argument('register_confirm_password')
register_email = self.get_json_argument('register_email')
register_phone = self.get_json_argument('register_phone')
register_patient_name = self.get_json_argument('register_patient_name')
register_ID_number = str(self.get_json_argument('register_ID_number'))
register_address = self.get_json_argument('register_address')
message = {}
try:
await objects.get(PatientPatient, username=register_username)
except DoesNotExist:
try:
await objects.get(PatientPatient, idcard=register_ID_number)
except DoesNotExist:
if len(register_phone) != 11 or register_phone.isdigit() is False:
message['code'] = 402 # len phone
elif len(register_ID_number) != 18:
message['code'] = 403 # len idcard
elif emailisValid(register_email) is False:
message['code'] = 404
elif register_password != register_confirm_password:
message['code'] = 405
else:
if GetInformation(register_ID_number).get_sex() == 0:
gender = '女'
else:
gender = '男'
patient = await objects.execute(PatientPatient.select().order_by(PatientPatient.id.desc()))
count = await objects.count(PatientPatient.select())
if count == 0:
patient_id = 'Patient0'
else:
patient_id = 'Patient{}'.format(str(int(str(patient[0].patient_id).replace('Patient',''))+1))
birthday = GetInformation(register_ID_number).get_birthday()
if is_valid_date(birthday) is False:
message['code'] = 403
else:
await objects.get_or_create(PatientPatient, patient_id=patient_id,
username=register_username,
password=generate_password_hash(register_password),
name=register_patient_name,
gender=gender,
addr=register_address,
phone=register_phone,
email=register_email,
idcard=register_ID_number,
brithdate=GetInformation(
register_ID_number).get_birthday())
message['code'] = 200
else:
message['code'] = 401
else:
message['code'] = 400
await self.finish(message)
return
class patient_change_password(ctrl_base.BaseHandler):
async def post(self):
ChangePassword_username = self.get_json_argument('ChangePassword_username')
ChangePassword_old_password = self.get_json_argument('ChangePassword_old_password')
ChangePassword_new_password = self.get_json_argument('ChangePassword_new_password')
ChangePassword_confirm_password = self.get_json_argument('ChangePassword_confirm_password')
message = {}
try:
await objects.get(PatientPatient, username=ChangePassword_username)
except DoesNotExist:
message['code'] = 400
else:
user = await objects.get(PatientPatient, username=ChangePassword_username)
if user.status is False:
message['code'] = 403
elif check_password_hash(user.password, ChangePassword_old_password) is False:
message['code'] = 401
else:
if ChangePassword_new_password != ChangePassword_confirm_password:
message['code'] = 402
else:
await objects.execute(
PatientPatient.update(password=generate_password_hash(ChangePassword_new_password)).where
(PatientPatient.username == ChangePassword_username))
message['code'] = 200
await self.finish(message)
return
class patient_retrieve_password(ctrl_base.BaseHandler):
async def post(self):
RetrievePassword_username = self.get_json_argument('username')
RetrievePassword_ID_number = self.get_json_argument('ID_number')
message = {}
try:
await objects.get(PatientPatient, username=RetrievePassword_username)
except DoesNotExist:
message['code'] = 400
else:
user = await objects.get(PatientPatient, username=RetrievePassword_username)
if user.status is False:
message['code'] = 402
elif RetrievePassword_ID_number != user.idcard:
message['code'] = 401
else:
message['code'] = 200
self.set_secure_cookie('username', RetrievePassword_username)
await self.finish(message)
return
class patient_retrieve_get_email(ctrl_base.BaseHandler):
async def post(self):
username = self.get_json_argument('username')
user = await objects.get(PatientPatient, username=username)
code = generate_verification_code()
send_qq_email(str(user.email), 'Code Check', 'Your Code:{}'.format(code))
self.set_secure_cookie('code', code)
self.set_secure_cookie('username', username)
_email = GetDataSensitive(user.email)
message = {'email': _email}
print(message)
await self.finish(message)
return
class patient_retrieve_code_check(ctrl_base.BaseHandler):
async def post(self):
code = self.get_json_argument('code')
_code = str(self.get_secure_cookie("code"))
message = {}
if code not in _code:
message['code'] = 400
else:
message['code'] = 200
self.clear_cookie('code')
await self.finish(message)
return
class patient_retrieve_redefine_password(ctrl_base.BaseHandler):
async def post(self):
username = self.get_secure_cookie('username')
print(username)
_user = await objects.get(PatientPatient, username=username)
RedefinePassword_new_password = self.get_json_argument('RedefinePassword_new_password')
await objects.execute(
PatientPatient.update(password=generate_password_hash(RedefinePassword_new_password)).where
(PatientPatient.patient_id == _user.patient_id))
message = {'code': 200}
self.clear_cookie('username')
await self.finish(message)
return
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。