def visitors(): """访客模式""" forms.VisitorsForm().validate_() user = Admin.query.filter_by(create_time="2028-01-01 12:00:00").first() if user: return result_format(data={ 'token': user.generate_token(), 'user_info': user.serialization() }) else: return result_format(error_code=5011, message="接口目前无法使用")
def refresh_token(): """刷新token""" day = 20 iat = g.user.get('iat') if time.time() - time.mktime(time.localtime(iat)) > (60 * 60 * 24 * day): user = Admin.query.filter_by(uuid=g.user.uuid).first_or_404() return result_format(data={ 'token': user.generate_token(), 'user_info': user.serialization() }) else: return result_format(error_code=5009, message='token刷新失败.')
def sign_in(): """登录""" form = forms.SignInForm().validate_() user = Admin.query.filter_by(open_id=form.open_id).first() # user = Admin.query.first() if user: return result_format(data={ 'token': user.generate_token(), 'user_info': user.serialization() }) else: return result_format(error_code=5011, message='客户未注册')
def admin_system_notice(): """管理员短信通知设置""" form = forms.AdminSystemNoticeForm().validate_() user = Admin.query.filter_by(uuid=g.user.uuid).first_or_404() if form.options == 1: user.sms_status = True else: user.sms_status = False user.direct_update_() return result_format()
def sign_in(): """登录""" # open_id = wechat_api.get_open_id() # # user = User.query.filter_by(open_id=open_id).first() # # if user and user.genre is not None: # 用户信息存在,并且用户类型已经选择 # # return common.result_format(data={'token': user.generate_token(), 'user_info': user.info()}) # else: # return common.result_format(error_code=4001, message='客户未注册', data={'open_id': open_id}) return result_format()
def activation(): """激活成为管理员 激活成功后删除Redis中的短信验证码信息 :return: """ form = forms.ActivationForm().validate_() form.admin.open_id = form.open_id form.admin.name = form.name.data form.admin.uuid = uuid.uuid1().hex form.admin.sms_status = False form.admin.update_create_time() form.admin.direct_update_() Redis.delete(form.redis_key) return result_format( data={ 'token': form.admin.generate_token(), 'user_info': form.admin.serialization() })
def admin_info_edit(): """管理员信息修改""" form = forms.AdminInfoEditForm().validate_() user = Admin.query.filter_by(uuid=g.user.uuid).first_or_404() user.set_attrs(form.data).direct_update_() return result_format()
def admin_info(): """管理员信息查询""" user = Admin.query.filter_by(uuid=g.user.uuid).first_or_404() return result_format(data=user.serialization())