Exemplo n.º 1
0
def reg():
    if request.method == "GET":
        return ops_render("member/reg.html")

    req = request.values
    nickname = req['nickname'] if "nickname" in req else ""
    login_name = req['login_name'] if "login_name" in req else ""
    login_pwd = req['login_pwd'] if "login_pwd" in req else ""
    login_pwd2 = req['login_pwd2'] if "login_pwd2" in req else ""

    if login_name is None or len(login_name) < 1:
        return ops_renderErrJSON(msg="请输入正确的登录用户名~~")

    if login_pwd is None or len(login_pwd) < 6:
        return ops_renderErrJSON(msg="请输入正确的登录密码,并且不能小于6个字符~~")

    if login_pwd != login_pwd2:
        return ops_renderErrJSON(msg="请输入正确的确认登录密码~~")

    user_info = User.query.filter_by(login_name=login_name).first()
    if user_info:
        return ops_renderErrJSON(msg="登录用户名已被注册,请换一个~~")

    model_user = User()
    model_user.login_name = login_name
    model_user.nickname = nickname if nickname is not None else login_name
    model_user.login_salt = UserService.geneSalt(8)
    model_user.login_pwd = UserService.genePwd(login_pwd,
                                               model_user.login_salt)
    model_user.created_time = model_user.updated_time = getCurrentTime()
    db.session.add(model_user)
    db.session.commit()
    return ops_renderJSON(msg="注册成功~~")
Exemplo n.º 2
0
def login():
    if request.method == "GET":
        return ops_render("member/login.html")

    req = request.values
    login_name = req['login_name'] if 'login_name' in req else ''
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ''
    if login_name is None or len(login_name) < 1:
        return ops_renderErrJSON("请输入正确的登录用户名~~")

    if login_pwd is None or len(login_pwd) < 6:
        return ops_renderErrJSON("请输入正确的登录密码~~")
    user_info = User.query.filter_by(login_name=login_name).first()
    if not user_info:
        return ops_renderErrJSON("请输入正确的登录用户名和密码 -1~~")

    if user_info.login_pwd != UserService.genePwd(login_pwd,
                                                  user_info.login_salt):
        return ops_renderErrJSON("请输入正确的登录用户名和密码 -2 ~~")

    if user_info.status != 1:
        return ops_renderErrJSON("账号被禁用,请联系管理员处理~~")

    #session['uid'] = user_info.id
    response = make_response(ops_renderJSON(msg="登录成功~~"))
    response.set_cookie(
        app.config['AUTH_COOKIE_NAME'],
        "%s#%s" % (UserService.geneAuthCode(user_info), user_info.id),
        60 * 60 * 24 * 120)
    return response
Exemplo n.º 3
0
def reg():
    if request.method == "GET":
        return render_template("member/reg.html")

    req = request.values
    login_name = req["login_name"] if "login_name" in req else ""
    login_pwd = req["login_pwd"] if "login_pwd" in req else ""
    login_pwd2 = req["login_pwd2"] if "login_pwd2" in req else ""

    if login_name is None or len(login_name) < 1:
        return ops_renderErrJSON(msg="请输入正确的登陆用户名~~")
    if login_pwd is None or len(login_pwd) < 6:
        return ops_renderErrJSON(msg="请你输入正确的登陆秘密,并且不能小于6个字符~~")
    if login_pwd != login_pwd2:
        return ops_renderErrJSON(msg="请确认你的登陆秘密是否一致~~")

    user_info = User1.query.filter_by(login_name=login_name).first()
    if user_info:
        return ops_renderErrJSON(msg="登陆用户名被注册,请换一个~~")

    model_user = User1()
    model_user.login_name = login_name
    model_user.nickname = login_name
    model_user.login_salt = UserService.geneSalt(8)
    model_user.login_pwd = UserService.genePwd(login_pwd, model_user.login_salt)
    model_user.created_time = model_user.updated_time = getCurrentTime()
    db.session.add(model_user)
    db.session.commit()
    return ops_renderJSON(msg="注册成功~~")
Exemplo n.º 4
0
def hdfs_download_file(file_path):
    """
    处理下载文件的请求
    """
    cli = MyHDFS(current_user)
    if not cli.is_connection:
        return ops_renderErrJSON(msg="HDFS 连接失败!")
    client = cli.this_connection
    # client.read()

    if file_path[4:5+len(MyHDFS.login_name)] == MyHDFS.login_name or file_path[:6] == "public":
        with send_file_auto_delete(client,file_path) as file_name:
            # 考虑使用with上下文管理器来解决这个问题
            return send_from_directory("download_cache/",file_name,as_attachment=True)
    else:
        return ops_renderErrJSON(msg="You can't download other's file")
Exemplo n.º 5
0
def login():
    """
    login 模板函数用来管理用户登录以及发放cookie
    """
    if request.method == "GET":
        return render_template("login_page.html")
    form = Login(request.form)
    if form.validate():
        user = User.query.filter_by(login_name=form.username.data).first()
        # 使用check_password_hash验证用户密码,其中第一个参数是数据库中查询的用户加密密码,第二个参数是用户输入的密码
        if user and check_password_hash(user._login_pwd, form.password.data):
            # 通过验证的话就使用flask-login想客户端发送cookie
            login_user(user)
            return ops_renderJSON(msg="login success~~")
        else:
            return ops_renderErrJSON(msg="密码错误")
    else:
        return ops_renderErrJSON(msg=str(form.errors))
def hdfs_manage_file():
    """
    处理新建文件夹,删除私有文件的请求
    """
    cli = MyHDFS(current_user)
    if not cli.is_connection:
        return ops_renderErrJSON(msg="HDFS 连接失败!")
    result = cli.delete_file_and_mkdir(request)
    return ops_renderJSON(msg=result[0], data=result[1])
Exemplo n.º 7
0
def hdfs_upload_file():
    """
    用于接收用户上传文件的请求
    """
    cli = MyHDFS(current_user)
    if not cli.is_connection:
        return ops_renderErrJSON(msg="HDFS 连接失败!")
    result = cli.upload_file(request)

    return ops_renderJSON(msg="upload success!",data=result[1]) if result[0] == "upload success!" else ops_renderJSON(msg=result)
def dashboard():
    if request.method == "GET":
        cli = MyHDFS(current_user)
        if not cli.is_connection:
            return ops_renderErrJSON(msg="HDFS 连接失败!")
        context = {}
        context["username"] = cli.login_name
        return render_template("user_ui.html", **context)
    req = request.values
    if req["log_out"]:
        logout_user()
        return redirect(url_for("index_page.index"))
def hdfs_download_file(file_path):
    """
    处理下载文件的请求
    """
    cli = MyHDFS(current_user)
    if not cli.is_connection:
        return ops_renderErrJSON(msg="HDFS 连接失败!")
    client = cli.this_connection

    if file_path[4:5 +
                 len(MyHDFS.login_name
                     )] == MyHDFS.login_name or file_path[:6] == "public":
        try:
            client.download("/lake/" + file_path, "download_cache/", True)
        except Exception as error:
            return ops_renderErrJSON(msg=str(error))
        file_name = file_path.split("/")[-1]
        # 为了解决文件缓存问题,可以考虑使用html和js在文件下载完成后返回一个响应请求
        return send_from_directory("download_cache/",
                                   file_name,
                                   as_attachment=True)
    else:
        return ops_renderErrJSON(msg="You can't download other's file")
def registered():
    if request.method == "GET":
        return render_template("Registered_page.html")
    form = Register(request.form)
    if form.validate():
        # 将用户信息注册进数据库
        model_user = User()
        model_user.login_name = form.username.data
        # 使用加密方法存储密码
        model_user._login_pwd = generate_password_hash(form.password.data)
        model_user.created_time = model_user.updated_time = getCurrentTime()
        try:
            db.session.add(model_user)
            db.session.commit()
        except Exception as error:
            return ops_renderErrJSON(msg=str(error))
        else:
            return ops_renderJSON(msg="注册成功~~")
    else:
        # 返回表单验证中的错误信息
        return ops_renderJSON(msg=str(form.errors))
Exemplo n.º 11
0
def hdfs_res():
    """
    用于获取hdfs上相关目录信息,以及对目录各层查看提供响应
    """
    if request.method == "POST":
        req = request.values
        content = {}
        cli = MyHDFS(current_user)
        if not cli.is_connection:
            return ops_renderErrJSON(msg="HDFS 连接失败!")
        # 获取首页的目录
        if "first_get" in req:
            content = cli.make_complete_path("/lake/")
            return ops_renderJSON(data=content)
        # 进入点击的下一级
        if "path" in req:
            content = cli.make_complete_path("/lake/" + req["path"])
            return ops_renderJSON(data=content)
        # 返回上一级
        if "path_back" in req:
            content = cli.make_complete_path("/lake" + req["path_back"])
            return ops_renderJSON(data=content)