Ejemplo n.º 1
0
def login():
    request_data = request.form
    user_name = request_data["user_name"]
    password = request_data["password"]
    result, info = user_m.check(user_name, password)
    if result is False:
        return info
    if info["tel"] is None:
        session["user_name"] = info["account"]
        session["bind_token"] = gen_salt(57)
        session["expires_in"] = datetime.now() + timedelta(seconds=300)
        session["password"] = password
        return redirect("%s/tel/" % url_prefix)
    if "remember" in request_data and request_data["remember"] == "on":
        remember = True
    else:
        remember = False
    user = User()
    user.user_name = info["account"]
    login_user(user, remember=remember)
    session["role"] = info["role"]
    if "next" in request_data and request_data["next"] != "":
        return redirect(request_data["next"])
    if session["role"] == 0:
            return u"您还没有任何权限,请联系管理员授权"
    else:
        resp = redirect(url_prefix + "/portal/")
        return resp
Ejemplo n.º 2
0
def login():
    request_data = request.form
    user_name = request_data["user_name"]
    password = request_data["password"]
    result, info = user_m.check(user_name, password)
    if result is False:
        return info
    # if info["tel"] is None:
    #     session["user_name"] = info["user_name"]
    #     session["bind_token"] = gen_salt(57)
    #     session["expires_in"] = datetime.now() + timedelta(seconds=300)
    #     session["password"] = password
    #     return redirect("%s/tel/" % url_prefix)
    if "remember" in request_data and request_data["remember"] == "on":
        remember = True
    else:
        remember = False
    user = User()
    user.user_name = info["user_name"]
    login_user(user, remember=remember)
    session["role"] = info["role"]
    p_info = control.get_project(user_name)
    if p_info is None:
        session["project_no"] = None
    else:
        session["project_no"] = p_info["project_no"]
        session["project_name"] = p_info["project_name"]
        session["project_role"] = p_info["project_role"]
    if "next" in request_data and request_data["next"] != "":
        return redirect(request_data["next"])
    resp = redirect(url_prefix + "/portal/")
    return resp
Ejemplo n.º 3
0
def bind_tel_func():
    if "bind_token" in session and "expires_in" in session and "user_name" in session and "password" in session:
        expires_in = session["expires_in"]
        if expires_in > datetime.now():
            if "tel" not in session:
                return jsonify({"status": False, "data": "Please Send Code"})
            request_data = request.json
            bind_token = request_data["bind_token"]
            if bind_token != session["bind_token"]:
                return redirect(url_for("dms_view.login_page"))
            tel = request_data["tel"]
            if tel != session["tel"]:
                return jsonify({"status": False, "data": "Please Send Code First"})
            code = request_data["code"]
            user_name = session["user_name"]
            result, info = control.bind_tel(user_name, session["password"], tel, code)
            if result is True:
                user = User()
                user.user_name = user_name
                login_user(user)
                del session["bind_token"]
                del session["expires_in"]
                del session["user_name"]
                del session["password"]
                del session["tel"]
                return jsonify({"status": True, "data": {"tel": tel}})
            else:
                return jsonify({"status": False, "data": info})
    return redirect(url_for("dms_view.login_page"))
Ejemplo n.º 4
0
def bind_tel_func():
    if "bind_token" in session and "expires_in" in session and "user_name" in session and "password" in session:
        expires_in = session["expires_in"]
        if expires_in > datetime.now():
            if "tel" not in session:
                return jsonify({"status": False, "data": "Please Send Code"})
            request_data = request.json
            bind_token = request_data["bind_token"]
            if bind_token != session["bind_token"]:
                return redirect(url_for("dms_view.login_page"))
            tel = request_data["tel"]
            if tel != session["tel"]:
                return jsonify({
                    "status": False,
                    "data": "Please Send Code First"
                })
            code = request_data["code"]
            user_name = session["user_name"]
            result, info = control.bind_tel(user_name, session["password"],
                                            tel, code)
            if result is True:
                user = User()
                user.user_name = user_name
                login_user(user)
                del session["bind_token"]
                del session["expires_in"]
                del session["user_name"]
                del session["password"]
                del session["tel"]
                return jsonify({"status": True, "data": {"tel": tel}})
            else:
                return jsonify({"status": False, "data": info})
    return redirect(url_for("dms_view.login_page"))
Ejemplo n.º 5
0
def login_vip():
    request_data = request.json
    user_name = request_data["user_name"]
    result, info = user_m.check_vip(user_name)
    if result is False:
        return jsonify({"status": False, "data": "fail"})
    user = User()
    user.user_name = info["account"]
    login_user(user)
    session["role"] = info["role"]
    return jsonify({"status": True, "data": "success"})