Example #1
0
def route_delete_todo(id):
    global todos
    el = [todo for todo in todos if todo['id'] == id]
    if len(el) == 0:
        abort(404)
    todos = [todo for todo in todos if todo['id'] != id]
    return jsonify(el[0])
Example #2
0
def server_shutdown():
    if not current_app.testing:
        abort(404)
    shutdown = request.environ.get('werkzeug.server.shutdown')
    if not shutdown:
        abort(500)
    shutdown()
    return 'Shutting down...'
Example #3
0
def route_update_todo(id):
    el = [todo for todo in todos if todo['id'] == id]
    if len(el) == 0:
        abort(404)
    todo = el[0]
    body = request.json
    todo['text'] = body['text']
    return jsonify(todo)
Example #4
0
def add_service_configuration(env, service_name):
    data = flask.request.data
    try:
        config = yaml.load(data)
        app["db"][env][service_name] = config
        return "Successfully added new configuration"
    except yaml.YAMLError as e:
        return abort(400, description="Wrong YAML Format")
    except:
        return abort(500, description="Server Error")
Example #5
0
def route_create_todo_with_id(id):
    el = [todo for todo in todos if todo['id'] == id]
    if len(el) != 0:
        abort(422, 'Id you are trying to create already exists')
    body = request.json
    todo = {
        'id': id,
        'text': body['text']
    }
    todos.append(todo)
    return jsonify(todo)
Example #6
0
def edit(id):
    post = Post.query.get_or_404(id)
    if current_user != post.author and \
            not current_user.can(Permission.ADMINISTER):
        abort(403)
    form = PostForm()
    if form.validate_on_submit():
        post.body = form.body.data
        db.session.add(post)
        flash('The post has been updated.')
        return redirect(url_for('.post', id=post.id))
    form.body.data = post.body
    return render_template('edit_post.html', form=form)
Example #7
0
def callback():
    # get X-Line-Signature header value
    signature = request.headers['X-Line-Signature']

    # get request body as text
    body = request.get_data(as_text=True)
    app.logger.info("Request body: " + body)

    # handle webhook body
    try:
        handler.handle(body, signature)
    except InvalidSignatureError:
        abort(400)rom flask import Flask, request, abort
Example #8
0
def register():
    #检查用户名
    name = request.json.get('name')
    check_string(name=name)
    #检查邮箱和密码的格式
    email = request.json.get('email')
    password = request.json.get('sha1_pwd')
    check_email_and_password(email,sha1_pwd)
    #检查邮箱是否被占用
    if User.query.filter_by(email=email).count():
        abort(400,'email:userd')
    user = User(name=name.strip(),email=email,password=sha1_pwd)
    return user.signin(jsonify(user=user.to_json()))
Example #9
0
def delete_service_configuration(env, service_name):
    try:
        config = app["db"][env][service_name]
        del app["db"][env][service_name]
        return "Successfully deleted configuration"
    except e:
        return abort(404, description="Configuration not found")
Example #10
0
def authenticate():
    #验证邮箱和密码
    email = request.json.get('email')
    sha1_pw = request.json.get('sha1_pw')
    check_email_and_password(email,sha1_pw)
    #验证密码是否正确
    user = User.query.filter_by(email=email).first_or_404()
    if not user.verify_password(sha1_pw):
        return abort(400,'Invaild password')
    return user.signin(jsonify(user.to_json()))
Example #11
0
def get_token_auth_header():
    if 'Authorization' not in request.headers:
        abort(401)

    auth_header = request.headers['Authorization']
    header_parts = auth_header.split(' ')

    if len(header_parts) != 2:
        abort(401)
    elif header_parts[0].lower() != 'bearer':
        abort(401)

    return header_parts[1]
Example #12
0
 def decorated_function(*args, **kwargs):
     if request.headers.get('secretkey') and request.headers.get('secretkey') == '1234':
         return view_function(*args, **kwargs)
     else:
         abort(401)
Example #13
0
def get_service_configuration(env, service_name):
    try:
        config = app["db"][env][service_name]
        return yaml.dump(config)
    except e:
        return abort(404, description="Configuration not found")
Example #14
0
 def check_email_and_password(email,password):
     if not email or not _RE_EMAIL.match(email):
         abort(400,'Invaild email')
     if not password or not _RE_SHA1.match(password):
         abort(400,'Invaild password')
Example #15
0
 def check_string(**kw):
     for key,string in kw.items():
         if not string or not string.strip():
             abort(400,'%s cannot be empty.' % key)
Example #16
0
 def check_admin(user):
     if user is None or not user.get('admin'):
         abort(403,'current user must be admin')
Example #17
0
def check_permissions(permission, payload):
    if 'permissions' not in payload:
        abort(400)
    if permission not in payload['permissions']:
        abort(403)
    return True
Example #18
0
def route_get_todo(id):
    el = [todo for todo in todos if todo['id'] == id]
    if len(el) == 0:
        abort(404)
    return jsonify(el[0])