def logout(): r_data = request.get_json() if r_data: token = r_data['token'] user_id = get_token_user_id(token) r.delete(token) if UserDao().set_userinfo('is_active',False,'id',user_id): return jsonify({'code':200,'msg':'当前用户已经退出登录'})
def kill_id(): r_data = request.get_json() if r_data: token = r_data['token'] user_id = get_token_user_id(token) r.delete(token) if UserDao().del_userinfo(user_id): return jsonify({'code':200,'msg':'账户注销成功'})
def loginout(): api_logger.debug('user forget get action!') resp = eval(request.get_data()) if resp: token = resp.get('token') id = cache_.get_token_user_id(token) # 从redis中获取id r.delete(token) # 删除服务端token UserDao().user_update('is_active', 0, 'id', id) # 更改激活状态为0 return jsonify({'code': 200, 'msg': '退出成功!'}) return jsonify({'code': 304, 'msg': '传入数据为空'})
def is_ok(): args = eval(request.get_data()) user_id = args.get("user_id") shop_id = args.get("shop_id") order_num = args.get("order_num") if r.exists(order_num): print(r.get(order_num).decode()) user = userdao.get_profile(user_id) u_burse = user.get("u_burse_balance") total = float(r.get(order_num).decode()) if u_burse < total: return jsonify({ "code": 207, "msg": "您的余额不足,请先充值" }) dic = { "order_detail_shop_id": shop_id, "order_detail_tel": user.get("u_tel"), "order_detail_addr": "abc", "order_detail_time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "order_price": total, "order_num": order_num } sql = "update users set u_burse_balance = %s where id = %s" userdao.query(sql, u_burse - total, user_id) dao.update("order_status", 1, "order_num", order_num) OrderDetailDao().save(**dic) r.delete(order_num) return jsonify({ "code": 200, "msg": "ok" }) else: return jsonify({ "code": 207, "msg": "该订单已失效" })
import uuid from libs import r def new_token(): return uuid.uuid4().hex def save_token(token, id): r.setex(token, id, 12 * 3600) # 保存12小时 def check_token(token): # 验证token return r.exists(token) def get_token_user_id(token): if check_token(token): return r.get(token).decode() if __name__ == '__main__': r.delete()