def ajax_get_sms_code(): """ 校验图形验证码,获取短信验证码 :return: """ # 校验图形验证码 code_str = request.args.get('code_str', '', type=str) code_key = '%s:%s' % ('code_str', 'reg') session_code_str = session.get(code_key, '') if not session_code_str: return json.dumps({'result': False, 'msg': u'图形验证码过期,请刷新后重试'}) result_code = code_str.upper() == session_code_str.upper() if result_code is False: return json.dumps({'result': False, 'msg': u'图形验证码错误,请重新提交'}) # 获取短信验证码 area_id = request.args.get('area_id', '', type=str) area_code = area_code_map.get(area_id, '86') mobile = request.args.get('phone', '', type=str) mobile_iso = '%s%s' % (area_code, mobile) sms_code = str(get_randint()) code_key = '%s:%s' % ('sms_code', 'reg') session[code_key] = sms_code sms_content = SMS_CODE_REG % sms_code # sms_client = SmsChuangLanIsoApi(UN, PW) # result = sms_client.send_international(mobile_iso, sms_content) # 推送短信优先级队列 q = RabbitPriorityQueue(exchange=EXCHANGE_NAME, queue_name='send_sms_p') q.put({'mobile': mobile_iso, 'sms_content': sms_content}, 20) return json.dumps({'result': True})
def add(): """ 添加管理 """ # return render_template('admin/add.html', title='admin_add') form = AdminAddForm(request.form) if request.method == 'POST': if form.validate_on_submit(): current_time = datetime.utcnow() # 手机号码国际化 area_id = form.area_id.data area_code = area_code_map.get(area_id, '86') admin_info = { 'username': form.username.data, 'password': md5(form.password.data), 'area_id': area_id, 'area_code': area_code, 'phone': form.phone.data, 'role_id': form.role_id.data, 'create_time': current_time, 'update_time': current_time, } admin_uid = add_admin(admin_info) if admin_uid: flash(u'Add Success', 'success') return redirect(url_for('admin.lists')) else: flash(u'Add Failed', 'warning') # flash(form.errors, 'warning') # 调试打开 return render_template('admin/add.html', title='admin_add', form=form)
def phone(): """ 手机注册 """ # return "Hello, World!\nReg!" from app_frontend.forms.reg import RegPhoneForm form = RegPhoneForm() # 推荐人赋值 form.user_pid.data = session.get('user_pid', 0) if request.method == 'POST': if form.validate_on_submit(): current_time = datetime.utcnow() # 添加用户注册信息 user_data = { 'reg_ip': get_real_ip(), 'create_time': current_time, 'update_time': current_time, } user_id = add_user(user_data) # 添加用户认证信息 # 手机号码国际化 area_id = form.area_id.data area_code = area_code_map.get(area_id, '86') mobile_iso = '%s%s' % (area_code, form.phone.data) user_auth_data = { 'user_id': user_id, 'type_auth': TYPE_AUTH_PHONE, 'auth_key': mobile_iso, 'auth_secret': md5(form.password.data), 'status_verified': 1, 'create_time': current_time, 'update_time': current_time, } add_user_auth(user_auth_data) # 添加用户基本信息 user_profile_data = { 'user_id': user_id, 'user_pid': form.user_pid.data, 'area_id': form.area_id.data, 'phone': form.phone.data, 'create_time': current_time, 'update_time': current_time, } add_user_profile(user_profile_data) if user_id: flash(u'%s, 恭喜您注册成功' % form.phone.data, 'success') else: flash(u'%s, 很遗憾注册失败' % form.phone.data, 'warning') return redirect(url_for('auth.index')) # 闪现消息 success info warning danger # flash(form.errors, 'warning') # 调试打开 return render_template('reg/phone.html', title='reg', form=form)
def profile(): """ 用户基本信息 """ # 获取团队成员三级树形结构 team_tree = get_team_tree(current_user.id) form = UserProfileForm(request.form) user_info = get_user_profile_row_by_id(current_user.id) if user_info: form.user_pid.data = user_info.user_pid form.nickname.data = user_info.nickname form.avatar_url.data = user_info.avatar_url form.create_time.data = user_info.create_time form.update_time.data = user_info.update_time if request.method == 'GET': form.area_id.data = user_info.area_id form.area_code.data = user_info.area_code form.phone.data = user_info.phone form.email.data = user_info.email form.birthday.data = user_info.birthday form.real_name.data = user_info.real_name form.id_card.data = user_info.id_card if request.method == 'POST': if form.validate_on_submit(): current_time = datetime.utcnow() # 手机号码国际化 area_id = form.area_id.data area_code = area_code_map.get(area_id, '86') user_data = { 'email': form.email.data, 'area_id': area_id, 'area_code': area_code, 'phone': form.phone.data, 'birthday': form.birthday.data, 'id_card': form.id_card.data, 'update_time': current_time, } result = edit_user_profile(current_user.id, user_data) if result: flash(u'修改成功', 'success') return redirect(url_for('.profile')) else: flash(u'信息不变', 'info') else: flash(u'修改失败', 'warning') # flash(form.errors, 'warning') # 调试打开 # flash(u'Hello, %s' % current_user.id, 'info') # 测试打开 return render_template('user/profile.html', title='profile', form=form, team_tree=team_tree)
def __call__(self, form, field): # 手机号码国际化 area_id = form['area_id'].data area_code = area_code_map.get(area_id, '86') mobile_iso = '%s%s' % (area_code, field.data) condition = { 'type_auth': TYPE_AUTH_PHONE, 'auth_key': mobile_iso } row = get_user_auth_row(**condition) if row: raise ValidationError(self.message or u'注册手机重复')
def profile(): """ 当前登录管理员信息 :return: """ admin_id = current_user.id # return render_template('admin/profile.html', title='admin_profile') form = AdminProfileForm(request.form) admin_info = get_admin_row_by_id(admin_id) if request.method == 'GET': form.id.data = admin_id form.username.data = admin_info.username form.password.data = '' form.area_id.data = admin_info.area_id form.phone.data = admin_info.phone form.role_id.data = admin_info.role_id form.create_time.data = admin_info.create_time form.update_time.data = admin_info.update_time if request.method == 'POST': if form.validate_on_submit(): current_time = datetime.utcnow() # 手机号码国际化 area_id = form.area_id.data area_code = area_code_map.get(area_id, '86') admin_data = { 'username': form.username.data, 'area_id': area_id, 'area_code': area_code, 'phone': form.phone.data, 'role_id': form.role_id.data, 'update_time': current_time, } if form.password.data: admin_data['password'] = md5(form.password.data) result = edit_admin(admin_id, admin_data) if result: flash(u'修改成功', 'success') return redirect(url_for('admin.lists')) else: form.create_time.data = admin_info.create_time form.update_time.data = admin_info.update_time flash(u'修改失败', 'warning') # flash(form.errors, 'warning') # 调试打开 return render_template('admin/profile.html', title='admin_profile', form=form)
def phone(): """ 手机登录认证 """ if current_user and current_user.is_authenticated: return redirect(url_for('index')) if not SWITCH_LOGIN_PHONE: flash(u'手机登录功能关闭,暂不支持手机登录', 'warning') return redirect(url_for('index')) form = LoginPhoneForm() if request.method == 'POST': if form.validate_on_submit(): # 手机号码国际化 area_id = form.area_id.data area_code = area_code_map.get(area_id, '86') mobile_iso = '%s%s' % (area_code, form.phone.data) # 获取认证信息 condition = { 'type_auth': TYPE_AUTH_PHONE, 'auth_key': mobile_iso, 'auth_secret': md5(form.password.data) } user_auth_info = get_user_auth_row(**condition) if not user_auth_info: flash(u'%s, 登录失败,请检查内容后重新登录' % form.phone.data, 'warning') return render_template('auth/phone.html', title='login', form=form) if user_auth_info.status_verified == 0: flash(u'%s, 登录手机尚未验证,请先验证手机' % form.phone.data, 'warning') return render_template('auth/phone.html', title='login', form=form) # session['logged_in'] = True # 用 login_user 函数来登入他们 login_user(get_user_row_by_id(user_auth_info.user_id), remember=form.remember.data) flash(u'%s, 恭喜,您已成功登录' % form.phone.data, 'success') return redirect(request.args.get('next') or url_for('index')) # flash(form.errors, 'warning') # 调试打开 return render_template('auth/phone.html', title='login', form=form, SWITCH_LOGIN_THREE_PART=SWITCH_LOGIN_THREE_PART)
def ajax_get_sms_code(): """ 获取短信验证码 :return: """ # 获取短信验证码 area_id = request.args.get('area_id', '', type=str) area_code = area_code_map.get(area_id, '86') mobile = request.args.get('phone', '', type=str) mobile_iso = '%s%s' % (area_code, mobile) sms_code = str(get_randint()) code_key = '%s:%s' % ('sms_code', 'edit') session[code_key] = sms_code sms_content = SMS_CODE_EDIT % sms_code # sms_client = SmsChuangLanIsoApi(UN, PW) # result = sms_client.send_international(mobile_iso, sms_content) # 推送短信优先级队列 q = RabbitPriorityQueue(exchange=EXCHANGE_NAME, queue_name='send_sms_p') q.put({'mobile': mobile_iso, 'sms_content': sms_content}, 20) return json.dumps({'result': True})