def post(self): args = parse_base.parse_args() action = args.get('action') password = args.get('password') if action == 'register': args_register = parse_register.parse_args() phone = args_register.get('phone') email = args_register.get('email') # icon = photos.save(request.files['icon']) # pathname = os.path.join('/static/uploads/icons', icon) boke_user = BokeUserModel() boke_user.u_email = email boke_user.u_phone = phone boke_user.password = password # boke_user.u_icon = pathname if not boke_user.save(): abort(400, msg="create fail") data = {"status": 200, "msg": "用户创建成功", "data": boke_user} return marshal(data, single_boke_user_fields) elif action == 'login': args_login = parse_login.parse_args() email = args_login.get("email") phone = args_login.get("phone") code = args_login.get("code") user = get_boke_user(email) or get_boke_user(phone) print(cache.get(phone)) if cache.get(phone) != code: abort(400, msg='验证码错误') if not user: abort(400, msg="用户不存在") if not user.check_password(password): abort(401, msg="密码错误") if user.is_delete: abort(401, msg="用户不存在") token = generate_boke_user_token() cache.set(token, user.id, timeout=60 * 60 * 24 * 7) data = {"msg": "login success", "status": 200, "token": token} return data else: abort(400, msg="其提供正确的参数")
def get(self): # 获取由uuid生成的唯一值token info = parser.parse_args() token = info.get('token') uuid = cache.get(token) # 根据token查询数据库 如果查得到说明未过期,进行修改active的状态值 users = User.query.filter_by(token=uuid) if users.count() > 0: user = users.first() if user: try: user.active = 1 db.session.add(user) db.session.commit() except Exception as e: print(e) db.session.rollback() return {'msg': 'Failed to active!'} return {'msg': 'Success to active!'} # 如果上面的缓存过期,则查不到,此时通过浏览器的请求返回token来赋值给uuid进行查询 else: user = User.query.filter(User.token == token).first() db.session.delete(user) db.session.commit() return '邮件过期'
def get(self): # 获取排挡ID planid = request.args.get("planid") # 获取排挡信息 movie_plan = MoviePlan.query.get(planid) # 从大厅中获取信息座位 hall = Hall.query.get(movie_plan.mp_hall) order_list = cache.get(planid) if not order_list: hall_data = {"h_count": hall.h_count, "h_seat": hall.seats} else: hall_seats = hall.seats hall_seat_list = hall_seats.split('#') for order_id in order_list: ticket = Ticket.query.filtert(Ticket.t_order == order_id) for tickets in ticket: # 移除大厅中对应的位置 hall_seat_list.remove(tickets.t_seat) hall_data = { "h_count": hall.h_count, "h_seat": hall.seat_list.join("#") } data = {"returnCode": "0", "returnValue": hall_data} return data
def get(self): data = {} parser = parse.parse_args() action = parser.get("action") if action == "activate": u_token = parser.get("u_token") user_id = cache.get(u_token) cache.delete(u_token) if user_id: user = User.query.get(user_id) user.is_active = True user.save() data["returnCode"] = "0" data["returnValue"] = "user activate success" return data else: data["returnCode"] = "900" data["returnValue"] = "激活邮件过期,请重新激活邮件" return data else: pass
def wrapper(*args, **kwargs): token = request.args.get("token") #token = args.get("token") #parser = reqparse.RequestParser() #parser.add_argument('token', required=True, help="请输入token") if not token: abort(401, message="user not login") u_id = cache.get(token) #return u_id #(temp) #u_id = 1 if not u_id: abort(401, message="user not available") user = Mentors.query.get(u_id) if not user: abort(400, message="user not exist") if user.is_delete: abort(403, message="user deleted") if not user.check_permission(permission): abort(403, message="can not access") g.user = user return fun(*args, **kwargs)
def get(self): data = {} parser = parse.parse_args() action = parser.get('action') if action == 'activate': u_token = parser.get('u_token') user_id = cache.get(u_token) cache.delete(u_token) if user_id: user = User.query.get(user_id) user.is_active = True user.save() data['returnCode'] = '0' data['returnValue'] = 'user activate success' return data else: data['returnCode'] = '900' data['returnValue'] = '激活邮件过期,请重新激活邮件' else: pass
def wrapper(*args, **kwargs): token = request.args.get("token") if not token: abort(400, msg="请提供token") if not token.startswith(ADMIN): abort(400, msg="请提供有效token") user_id = cache.get(token) if not user_id: abort(400, msg="token 失效") user = AdminUser.query.get(user_id) if not user: abort(400, msg="用户不存在") if not user.is_super: abort(403, msg="没有权限,请联系管理员") g.user = user return fun(*args, **kwargs)
def get(self): parser = parse_get.parse_args() action = parser.get("action") data = {} if action == "activate": u_token = parser.get("u_token") user_id = cache.get(u_token) cache.delete(u_token) if user_id: user = User.query.get(user_id) user.is_activate = True user.save() data["returnMsg"] = "激活成功" data["returnCode"] = "0" return data else: data["returnMsg"] = "邮件已过期,请重新激活" data["returnCode"] = "802" return data return {"msg": "send ok"}
def get(self): parse = parser.parse_args() token = parse.get('token') userid = cache.get(token) if not userid: responseData = { 'status': 402, 'msg': '激活失败', 'err': '请与管理员联系', 'time': str(int(time.time())) } return responseData else: user = User.query.get(userid) user.isactive = True user.token = get_token() db.session.add(user) db.session.commit() responseData = { 'status': 200, 'msg': '用户激活成功', 'data': user, 'time': str(int(time.time())) } return responseData
def testCache(): value = cache.get('ip') #先查找是不是在cache缓存中 if value: return '你又来了--%s' % value ip = request.remote_addr #获取请求的ip cache.set('ip', ip) #set方法存放到cache中,前者设置值的键,后者值 return '欢迎光临……'
def get(self): # 获取token parse = parser.parse_args() token = parse.get('token') # 根据token获取userid userid = cache.get(token) if not userid: # 不存在 response_data = { 'status': 401, 'msg': '激活失败', 'error': '激活超时,请联系管理员!', 'date': str(time.ctime()), } return response_data # 删除token cache.delete(token) # 更改用户状态 user = User.query.get(userid) user.isactive = True user.token = str(uuid.uuid5(uuid.uuid4(), 'active')) db.session.add(user) db.session.commit() response_data = { 'status': 201, 'msg': '激活成功', 'date': str(time.ctime()), 'data': user } return response_data
def get(self): token = request.args.get('token') if token: u_id = cache.get(token) if u_id: user = User.query.get(u_id) if user: if not user.is_delete: g.user = user return self.get_data() else: data = {'msg': 'user deleted'} return data else: data = {'msg': 'user not exist'} return data else: data = {'msg': 'user not avalibal'} return data else: data = {'msg': 'user not login'} return data
def student_register(): if request.method == "GET": return render_template('StudentRegister.html') elif request.method == "POST": username = request.form.get("username") password = request.form.get("password") phone = request.form.get("phone") # hash_pwd = generate_password_hash(password) code = request.form.get("code") cache_code = cache.get(username) if code != cache_code: return "验证失败" student = Student() student.s_name = username student.s_password = password student.s_phone = phone db.session.add(student) db.session.commit() return 'Register Success'
def student_register(): if request.method == 'GET': return render_template('StudentRegister.html') elif request.method == "POST": username = request.form.get('username') password = request.form.get('password') phone = request.form.get('phone') # hash_psd = generate_password_hash(password) # hash_psd = password code = request.form.get('code') cache_code = cache.get(username) print("验证码", code,cache_code) if code != cache_code: return '验证失败' student = Student() student.s_name = username student.s_password = password # model 里面已经做了处理了 student.s_phone = phone db.session.add(student) db.session.commit() return '注册成功'
def get(self): parse = parser.parse_args() token = parse.get('u_token') print('---------------------------') print(token) user_id = cache.get(token) users = UserModel.query.filter(UserModel.id == user_id) #当在页面发送过来请求之后 我想作的是把对象的u_active的值由false改为true #找对象 #UserModel.query.filter_by(u_token=token) #users = UserModel.query.filter(UserModel.u_token==token) #UserModel.query.filter(UserModel.u_token.__eq__(token)) #此时如果不从缓存中拿取会发生什么问题 if users.count() > 0: print(1111111111) user = users.first() user.u_active = True db.session.add(user) db.session.commit() return {'message': 'jfjdsfjlkdsjflkds'} return {'message': 'bu ok'}
def wrapper(*args, **kwargs): token = request.args.get("token") # data = {} if not token: abort(400) user_id = cache.get(token) if not user_id: abort(401) user = User.query.get(user_id) if not user: abort(401) if not user.check_permission(permission): abort(403) g.user = user g.auth = token return fun(*args, **kwargs)
def wrapper(*args, **kwargs): token = request.args.get("token") if not token: abort(401, message="user not login") u_id = cache.get(token) if not u_id: abort(401, message="user not available") user = User.query.get(u_id) if not user: abort(400, message="user not exist") if user.is_delete: abort(403, message="user deleted") if not user.check_permission(permission): abort(403, message="can not access") g.user = user return fun(*args, **kwargs)
def wrapper(*args, **kwargs): token = request.args.get("token") if token: u_id = cache.get(token) if u_id: user = User.query.get(u_id) if user: if not user.is_delete: g.user = user return fun(*args, **kwargs) else: abort(403, message="user deleted") else: abort(400, message="user not exist") else: abort(401, message="user not available") else: abort(401, message="user not login")
def _verify(user_type: str): token = request.args.get('token') or request.form.get('token') if not token: abort(401, msg="Not Logged In.") # 验证超级管理员权限 if user_type == TokenPrefix.ADMIN_USER and not token.startswith( TokenPrefix.ADMIN_USER): abort(401, msg="Use Normal Privilege As Admin.") # 验证普通用户权限 if user_type == TokenPrefix.NORMAL_USER and not token.startswith( TokenPrefix.NORMAL_USER): abort(401, msg="Privilege Error.") # 如果两者都可以 if user_type == TokenPrefix.BOTH: if not any( (token.startswith(getattr(TokenPrefix, prefix)) for prefix in dir(TokenPrefix) if not prefix.startswith('__') and not isinstance(getattr(TokenPrefix, prefix), Callable))): abort(401, msg="Invalid token.") # 获取user id 根据token user_id = cache.get(token) if user_id is None: abort(401, msg="Invalid Token.") session = get_session() user_instance = session.query(User).get(user_id) if user_instance is None: abort(401, msg="Invalid ID") g.user = user_instance g.token = token
def check_token(token): user_id = cache.get(token) user = get_movie_user(user_id) if not user: abort(400,msg = "请登录") return True
def post(self): args = parse.parse_args() token = args.get("token") user_id = cache.get(token) user = get_user(user_id) if not user: abort(400, message="plz input effective token ") return {"msg": "success"}
def post(self): """ 下单 用户 排挡(目前没有) 电影 movieapi 大厅 None 定义一个表 大厅类型 座位类型(0,0) (0,1) 1 - 16 if 一排就是五个位置 0 1 2 3 4 6 7 8 9 11 12 13 14 """ u_token = request.form.get("u_token") mp = request.form.get("mp") seats = request.form.get("seats") order = Order() order.o_user = cache.get(u_token) order.o_movie_plan = mp order.save() seat_list = seats.split("#") for seats_positon in seat_list: ticket = Ticket() ticket.t_order = order.id ticket.t_seat = int(seats_positon) ticket.save() # 将订单放入缓存中并限定过期时间 order_list = cache.get(mp) if not order_list: order_list.append(order.id) cache.set(mp, order_list) data = {"returnCode": "0", "returnValue": order.id} return data
def f(*args, **kwargs): u_token = request.args.get("u_token") print(u_token) if u_token: user_id = cache.get(u_token) if user_id: return fun(*args, **kwargs) else: abort(401, message='用户状态失效或无效') else: # 未认证 abort(401, message='请登录')
def get(self): parse=parser.parse_args() phone=parse.get('phone') randomint=parse.get('randomint') cache_randomint=cache.get('phone') if cache_randomint: if cache_randomint==randomint: user=User.query.filter(User.phone==phone).first() user.token=get_token() db.session.add(user) db.session.commit() cache.delete(phone)
def get_cinema_user(token): if token: if token.startswith(CINEMA): user_id = cache.get(token) if user_id: user = CinemaUser.query.get(user_id) if user: return user return None
def index(): result = cache.get("index") if result: return result result = render_template("GradeList.html") sleep(5) cache.set("index", result, timeout=20) return result
def _verify(): token = request.args.get("token") if not token: abort(401, msg="not login") if not token.startswith(ADMIN_USER): abort(403, msg='no access') user_id = cache.get(token) if not user_id: abort(401, msg="user not avaliable") user = get_admin_user(user_id) if not user: abort(401, msg="must login") g.user = user g.auth = token
def _verify(): token = request.args.get("token") if not token: abort(401, msg="not login") user_id = cache.get(token) if not user_id: abort(401, msg="token不正确") if not token.startswith(ADMIN_USER): abort(403, msg="非用户") user = get_admin_user(user_id) if not user: abort(401, msg="用户不存在") g.user = user g.auth = token
def f(*args, **kwargs): u_token = request.form.get('u_token') if not u_token: abort(401, message='请登录') else: user_id = cache.get(u_token) if not user_id: abort(401, message='用户状态失效') else: user = User.query.get(user_id) if user.check_permission(dest_permission): return fun(*args, **kwargs) else: abort(403, message='您没有权限访问本模块')
def have_cache(): result = cache.get("have_cache") if result: return result resp = render_template('HaveCache.html') sleep(2) cache.set("have_cache", resp, timeout=10) return resp