示例#1
0
def user_search():
    keyword = request.args.get("keyword")
    header_title, path1, path2, users, p = u'查看用户', u'用户管理', u'用户列表', '', ''
    sql = "select * from users WHERE name like '%" + "%s" % str(keyword) + "%'"
    users = user_dir(db_sql.select_mysql(sql))
    user_cookies = request.cookies
    return render_template("user/user_lists.html", **locals())
示例#2
0
def users():
    #sql = "select name,tel,mail from users"
    sql = "select * from users"
    data = db_sql.select_mysql(sql)
    username = ''
    role = ''
    if request.cookies:
        if "username" in request.cookies:
            username = request.cookies["username"]
            role = request.cookies["role"]
    #print user_dir(data)
    return render_template("index.html",
                           data=user_dir(data),
                           username=username,
                           role=role)
示例#3
0
def login():
    if request.method == "POST":
        username = str(request.form.get("username"))
        password = request.form.get("password")
        sql = "select role,password from users where name='%s'" % username
        user = db_sql.select_mysql(sql)
        print user[0][0]
        if user and user[0][1] == encrypt_md5(password):
            resp = make_response(redirect("/users"))
            resp.set_cookie("username", username)
            resp.set_cookie("role", user[0][0])
            return "success"
        else:
            return redirect("/login")
        pass
    if request.method == "GET":
        return render_template("login.html")
示例#4
0
def user_add():
    header_title, path1, path2, users, p = u'', u'用户管理', u'添加用户', '', ''
    user_cookies = request.cookies
    if request.method == "GET":
        return render_template("/user/user_add.html", **locals())
    if request.method == "POST":
        sql = "select * from users where name = '%s' " % str(request.form["name"])
        if not db_sql.select_mysql(sql):
            sql = "INSERT INTO users(NAME,tel,mail,password,status,role) VALUES ('%s','%s','%s','%s','%s','%s')" % (str(request.form["name"]),
                                                                                          str(request.form["tel"]),
                                                                                          str(request.form["mail"]),
                                                                                          encrypt_md5(
                                                                                              str(request.form[
                                                                                                      "password"])),
                                                                                          str(request.form["status"]),
                                                                                          str(request.form["role"]))
            db_sql.update_mysql(sql)
    return redirect("/user/user_lists")
示例#5
0
def user_edit():
    if request.method == "GET":
        header_title, path1, path2, users, p = u'编辑用户', u'用户管理', u'编辑用户', '', ''
        if request.method == "GET":
            Uid = request.args.get("id")
        sql = "select * from users WHERE id = '%s'" % Uid
        users = user_dir(db_sql.select_mysql(sql))
        for ulist in users:
            user = ulist
        user_cookies = request.cookies
        return render_template("user/user_edit.html", **locals())
    if request.method == "POST":
        mail = str(request.form["mail"])
        phone = str(request.form["tel"])
        name = str(request.form["name"])
        status = str(request.form["status"])
        sql = "update users set  status = '%s',tel = '%s',mail = '%s' where name = '%s'" % (status, phone, mail, name)
        db_sql.update_mysql(sql)
        return  redirect("/user/user_lists")
示例#6
0
def update_user():
    if request.method == "POST":
        user = request.form.get("username")
        if not user:
            return "非法用户"
        sql = "select name,tel,mail from users where name like '%s'" % user
        data = db_sql.select_mysql(sql)
        if not data:
            return "不存在此用户"
        else:
            print "aa"
            return render_template("update_user.html", data=data)
    if request.method == "GET":
        user = request.args.get("username")
        tel = request.args.get("tel")
        mail = request.args.get("mail")
        if not user and not tel and not mail:
            return "小伙淡定,慢慢慢来"
        sql = "UPDATE users SET tel='%s',mail='%s' WHERE users.`name`='%s'" % (
            tel, mail, user)
        db_sql.update_mysql(sql)
        return redirect("/users")
示例#7
0
def login():
    if request.method == "POST":
        user_logs ={}
        role_list = {"SA": u"运维工程师", "Test": u"测试工程师"}
        username = str(request.form.get("username"))
        password = request.form.get("password")
        sql = "select role,name,password,id from users where name='%s'" % username
        user = db_sql.select_mysql(sql)
        for u1 in user:
            user_logs["role"] = role_list[u1[0]]
            user_logs["name"] = u1[1]
            user_logs["password"] = u1[2]
            user_logs["id"] = u1[3]
        if user and user_logs["password"] == encrypt_md5(password):
            resp = make_response(redirect("/index"))
            resp.set_cookie("username", user_logs["name"])
            resp.set_cookie("role", user_logs["role"])
            resp.set_cookie("id", str(user_logs["id"]))
            return resp
        else:
            return redirect("/")
        pass
    if request.method == "GET":
        return render_template("/")
示例#8
0
def select_user():
    user = request.form.get("username")
    sql = "select * from users where name like '%s'" % user
    data = db_sql.select_mysql(sql)
    return render_template("users.html", data=user_dir(data))
示例#9
0
def user_lists():
    header_title, path1, path2, users, p = u'查看用户', u'用户管理', u'用户列表','',''
    sql = "select * from users"
    users = user_dir(db_sql.select_mysql(sql))
    user_cookies = request.cookies
    return render_template("user/user_lists.html", **locals())