def register(): dict1 = request.form mobile = dict1.get('mobile') image_yzm = dict1.get('image_yzm') msg_yzm = dict1.get('msg_yzm') password = dict1.get('password') if not all((mobile, image_yzm, msg_yzm, password)): return jsonify(error_info='数据填写不完整') if len(mobile) != 11: return jsonify(error_info='手机号不合法') if UserInfo.query.filter_by(mobile=mobile).count(): return jsonify(error_info='该手机号已经被注册过') if image_yzm != session['image_yzm']: return jsonify(error_info='图片验证码不正确') if msg_yzm != session['msg_yzm']: return jsonify(error_info='短信验证码不正确') if not re.match(r'\w{6,20}', password): return jsonify(error_info='密码格式不正确') user = UserInfo() user.mobile = mobile user.nick_name = mobile user.password = password try: db.session.add(user) db.session.commit() return jsonify(success_info='注册成功,请登录') except: return jsonify(error_info='服务器出错')
def register(): # 接收 form = request.form mobile = form.get('mobile') # '' None # sms_code = form.get('sms_code') pwd = form.get('pwd') # 验证 # 1.所有数据不为空 # if not all([mobile, sms_code, pwd]): # 判断参数中是否有空值bool(x) # return jsonify(result=1) # 参数为空则返回1 # # 2.验证短信是否正确 # sms_code_session = str(session.get('sms_code')) # if sms_code != sms_code_session: # return jsonify(result=2) # 短信验证码错误 # 3.验证手机号是否存在 mobile_exists = UserInfo.query.filter_by(mobile=mobile).count() if mobile_exists: return jsonify(result=3) # 手机号存在 # 4.验证当前手机号是否与接收短信的手机号一致 # mobile_session = session.get('mobile') # if mobile != mobile_session: # return jsonify(result=5) # 两次手机号不一致 # 处理:新建对象并保存 user = UserInfo() user.nick_name = mobile user.mobile = mobile user.password = pwd # 添加 db.session.add(user) # 保存到数据库 db.session.commit() # 响应 return jsonify(result=4) # 注册成功
def register(): dict1 = request.form mobile = dict1.get('mobile') yzm_image = dict1.get('yzm_image') yzm_sms = dict1.get('yzm_sms') pwd = dict1.get('pwd') if not all([mobile, yzm_image, yzm_sms, pwd]): return jsonify(result=1) if yzm_image != session['image_yzm']: return jsonify(result=2) if int(yzm_sms) != session['sms_yzm']: return jsonify(result=3) if not re.match(r'[a-zA-Z0-9_]{6,20}', pwd): return jsonify(result=4) mobile_count = UserInfo.query.filter_by(mobile=mobile).count() if mobile_count > 0: return jsonify(result=5) user = UserInfo() user.nick_name = mobile user.mobile = mobile user.password = pwd try: db.session.add(user) db.session.commit() except: current_app.logger_xjzx.error('用户注册访问数据库失败') return jsonify(result=7) return jsonify(result=6)
def run(self): username = input('请输入管理员账号:') pwd = input('请输入密码') user = UserInfo() user.mobile = username user.nick_name = username user.password = pwd user.isAdmin = True db.session.add(user) db.session.commit() print('创建管理员成功')
def run(self): name = input('请输入用户名:') pwd = input('请输入密码:') user = UserInfo() user.mobile = name user.nick_name = name user.password = pwd user.isAdmin = True db.session.add(user) db.session.commit() print('管理员创建成功')
def run(self): user_list = [] for i in range(100): user = UserInfo() user.nick_name = str(i) user.mobile = str(i) user.password = str(i) user.create_time = datetime(2018, random.randint(1, 7), random.randint(1, 16)) user_list.append(user) db.session.add_all(user_list) db.session.commit() print('成功')
def run(self): now = datetime.datetime.now() user_list = [] for i in range(0000, 1000): user = UserInfo() user.nick_name = '1360000' + str(i) user.mobile = '1360000' + str(i) user.password = '******' + str(i) user.create_time = datetime.datetime(now.year, random.randint(1, 6), random.randint(1, now.day)) user_list.append(user) db.session.add_all(user_list) db.session.commit()
def run(self): # 接收用户输入的账号、密码 username = input('请输入管理员账号:') pwd = input('请输入密码:') # 创建对象 user = UserInfo() user.mobile = username user.nick_name = username user.password = pwd user.isAdmin = True # 保存 db.session.add(user) db.session.commit() # 响应 print('创建管理员成功')
def register(): mobile = request.form.get('mobile') smscode = request.form.get('smscode') passwd = request.form.get('passwd') sms_session = session.get('sms_code') if smscode not in sms_session: return jsonify(res=1) del session['sms_code'] if smscode == sms_session: user = UserInfo() if user.query.filter_by(mobile=mobile).count() > 0: return jsonify(res=3) user.password = passwd user.mobile = mobile user.nick_name = mobile db.session.add(user) db.session.commit() return jsonify(res=2)
def register(): # 1.接收数据 dict1 = request.form mobile = dict1.get('mobile') image_yzm = dict1.get('image_yzm').upper() sms_yzm = dict1.get('sms_yzm') pwd = dict1.get('pwd') # 2.验证数据的有效性 if not all([mobile, image_yzm, sms_yzm, pwd]): return jsonify(result=1) if image_yzm != session['image_yzm']: return jsonify(result=2) if int(sms_yzm) != session['sms_yzm']: return jsonify(result=3) import re if not re.match(r'[a-zA-Z0-9_]{6,20}', pwd): return jsonify(result=4) mobile_count = UserInfo.query.filter_by(mobile=mobile).count() if mobile_count > 0: return jsonify(result=5) # 3.创建对象 user = UserInfo() user.nick_name = mobile user.mobile = mobile user.password = pwd # 4.提交 try: # 把user对象添加到session db.session.add(user) # 提交即保存到数据库 db.session.commit() except: current_app.logger_xjzx.error('注册用户时数据库访问失败') return jsonify(result=6) # 返回响应(成功) return jsonify(result=7)
def register(): form = request.form mobile = form.get('mobile') sms_code = form.get('sms_code') pwd = form.get('pwd') if not all([mobile, sms_code, pwd]): return jsonify(result=1) #参数有空 sms_code_session = str(session.get('sms_code')) if sms_code != sms_code_session: return jsonify(result=2) #短信验证码错误 mobile_exists = UserInfo.query.filter_by(mobile=mobile).count() if mobile_exists: return jsonify(result=3) #手机号存在 if mobile != session.get('mobile'): return jsonify(result=4) #两次手机号不一致 user = UserInfo() user.nick_name = mobile user.mobile = mobile user.password = pwd db.session.add(user) db.session.commit() return jsonify(result=0) #成功
def register(): # 接收数据 dect1 = request.form mobile = dect1.get('mobile') yzm_image = dect1.get('yzm_image') yzm_sms = dect1.get('yzm_sms') pwd = dect1.get('pwd') print(dect1) # 验证数据的有效性 if not all([mobile, yzm_image, yzm_sms, pwd]): return jsonify(result=1) # 对比图片验证码 if yzm_image != session['image_yzm']: return jsonify(result=2) # 对比短信验证码 if int(yzm_sms) != session['sms_yzm']: return jsonify(result=3) # 判断密码长度 if not re.match(r'[a-zA-Z0-9 + - * /]{6,16}', pwd): return jsonify(result=4) # 验证mobile是否纯在 mobile_count = UserInfo.query.filter_by(mobile=mobile).count() if mobile_count > 0: return jsonify(result=5) # 创建对象 user = UserInfo() user.nick_name = mobile user.mobile = mobile user.password = pwd # 提交到数据库 try: db.session.add(user) db.session.commit() except: current_app.logger_xjzx.error('用户注册访问数据库失败') return jsonify(result=6) return jsonify(result=7)