Beispiel #1
0
 def check_captcha(cls, captcha):
     captcha_lower = captcha.lower()
     if cache.get(captcha_lower):
         cache.delete(captcha_lower)
         return True
     else:
         return False
Beispiel #2
0
 def delete(self, book_id):
     """Delete book object"""
     book = db.session.query(Book).filter_by(id=book_id).first()
     if not book:
         return {'message': "Not found"}, 404
     book.delete()
     cache.delete(f"book:{book_id}")
     return '', 204
Beispiel #3
0
 def put(self, book_id):
     """Update book object. Should be all fields, else some information will
     lost"""
     book = db.session.query(Book).filter_by(id=book_id).first()
     if not book:
         return {'message': "Not found"}, 404
     try:
         book = self.book_schema.load(request.json, instance=book,
                                      session=db.session)
     except ValidationError as e:
         return {"message": str(e)}, 400
     book.save()
     cache.delete(f"book:{book_id}")
     return self.book_schema.dump(book), 200
Beispiel #4
0
 def patch(self, book_id):
     """Update book object. Could be only one field"""
     book = db.session.query(Book).filter_by(id=book_id).first()
     if not book:
         return {'message': "Not found"}, 404
     try:
         book = self.book_schema.load(request.json,
                                      instance=book,
                                      partial=True,
                                      session=db.session)
     except ValidationError as e:
         return {"message": str(e)}, 400
     book.save()
     cache.delete(f"book:{book_id}")
     return {'message': 'Updated successfully'}, 200
Beispiel #5
0
 def post(self, token: str):
     """Function to set new password"""
     new_password = request.json.get("password")
     if not new_password:
         return {"message": "Provide a new password"}, 400
     try:
         payload = decode_auth_token(token)
     except jwt.ExpiredSignatureError:
         return {"message": "The link is expired"}, 410
     except jwt.InvalidTokenError:
         return {
             "message":
             'The link is invalid. Check if the link '
             'was copied rightly'
         }, 400
     uuid = payload["sub"]
     if not cache.get(f"reset_password:{uuid}"):
         return {"message": "This link was already used"}
     user = db.session.query(User).filter_by(uuid=uuid).first()
     user.password = new_password
     user.save()
     cache.delete(f"reset_password:{uuid}")
     return {"message": "Password was successfully changed"}
Beispiel #6
0
def register(_data):
    if not cache.exists(session['username']):
        log.info('设置register_data[session[\'username\']]为空')
        cache.set(session['username'] + '.count', 0, ex=600)
        # expires in 10 minutes
    session['action'] = 'register'
    if verify(_data):
        cache.rpush(session['username'], json.dumps(_data))
        cache.incr(session['username'] + '.count')

        log.info('获取到了一组合法签名数据')
        log.debug(_data)
    if int(cache.get(session['username'] + '.count')) >= 3:
        log.info('获取到了三组信息,成功注册')

        log.debug('所有数据:')
        register_data = cache.lrange(session['username'], 0, -1)
        register_data = [json.loads(i) for i in register_data]
        log.debug(register_data)

        cache.delete(session['username'])
        cache.delete(session['username'] + '.count')

        real = DynamicProcess.prepare_list(register_data)
        real_v = DynamicProcess.prepare_value(real)
        execute_sql(
            "INSERT INTO user (username, password, sign_prepared, sign_val) values (\
                %(username)s, %(password)s, %(sign_prepared)s, %(sign_val)s\
            )",
            username=session['username'],
            password=session['password'],
            sign_prepared=json.dumps(real),
            sign_val=real_v)
        session.pop('username')
        session.pop('password')
        return 'ret'
    return 'continue'
Beispiel #7
0
def rebuild_folders():
    cache.delete("folder_dict")
    cache.delete("folder_list")
Beispiel #8
0
def rebuild_seasons():
    cache.delete("season_dict")
    cache.delete("season_list")
Beispiel #9
0
 def clean_cache(cls, _id):
     key = 'staff:{0}'.format(_id)
     cache.delete(key)
Beispiel #10
0
 def clean_cache(cls, _id):
     key = 'staff:{0}'.format(_id)
     cache.delete(key)