示例#1
0
def send_ucp_files(path):
    """User CP page static resources - CSS, JS"""
    if 'jwt' in flask.request.cookies:
        if Jwt().validate_jwt(flask.request.cookies['jwt']):
            return flask.send_from_directory(CP_PATH, path)

    return flask.redirect(LOGIN_PATH)
示例#2
0
def send_login():
    """Return the login page"""
    valid = False

    if 'jwt' in flask.request.cookies:
        valid = Jwt().validate_jwt(flask.request.cookies['jwt'])

    if valid:
        return flask.redirect(CP_WEB_PATH)

    return flask.render_template('index.html')
示例#3
0
def get_logs(user_name, path):
    valid = False
    user_info = None

    if 'jwt' in flask.request.cookies:
        valid, user_info = Jwt().validate_jwt(flask.request.cookies['jwt'])

    if not valid or user_info["username"] != user_name:
        return responses.get_json_error_response("Bad login")

    logs = scr_logger.load(user_name, path)
    resp = flask.Response(logs)
    return resp
示例#4
0
文件: users.py 项目: ivaivalous/ivodb
    def login(self, username, password):
        """Log in"""
        user = self.db.get_user(username, username)

        if user is None:
            return None

        user['_id'] = str(user['_id'])

        if Password.check_password(password, user['hash']):
            del user['hash']
            jwt = Jwt().generate_jwt(user)
            return user, jwt

        return None
示例#5
0
def delete_resource(resource_id):
    valid = False
    user_info = None

    if 'jwt' in flask.request.cookies:
        valid, user_info = Jwt().validate_jwt(flask.request.cookies['jwt'])

    if not valid:
        return responses.get_json_error_response("Bad login")

    try:
        user_id = user_info['_id']
    except:
        return responses.get_invalid_request()

    ResourceManager(db).delete(user_id, resource_id)
    return responses.get_created()
示例#6
0
def user_cp():
    """Return the user control panel app"""

    if 'jwt' in flask.request.cookies:
        valid, user_info = Jwt().validate_jwt(flask.request.cookies['jwt'])
        user_id = user_info['_id']
        user_name = user_info['username']
    else:
        return flask.redirect(LOGIN_WEB_PATH)

    if valid:
        resources = ResourceManager(db).get_resources(user_id)
        # TODO move cp.html from the login folder
        return flask.render_template('cp.html',
                                     resources=resources,
                                     user_name=user_name)

    return flask.redirect(LOGIN_WEB_PATH)
示例#7
0
def create_resource():
    valid = False
    user_info = None

    if 'jwt' in flask.request.cookies:
        valid, user_info = Jwt().validate_jwt(flask.request.cookies['jwt'])

    if not valid:
        return responses.get_json_error_response("Bad login")

    try:
        user_id = user_info['_id']
        name = flask.request.form['name']
        path = flask.request.form['path']
        r_type = flask.request.form['type']
        body = flask.request.form['body']
        headers = flask.request.form['headers']
    except:
        return responses.get_invalid_request()

    ResourceManager(db).create(user_id, name, path, r_type, body, headers)
    return responses.get_created()