Ejemplo n.º 1
0
def login(conn, dic):
    name = dic.get("name")
    pwd = dic.get("pwd")
    password = comment.get_md5(pwd)
    user_obj = comment.check_user(name)
    if user_obj:
        if user_obj.password == password:
            user_id = user_obj.id
            session = comment.get_md5(name)
            addr = dic.get("addr")
            notice = comment.new_notice()
            mutex.acquire()
            alive_user[addr] = [session, user_id]
            mutex.release()
            dic = {
                "flag": 2,
                "msg": "登陆成功!",
                "session": session,
                "notice": notice
            }
        else:
            dic = {"flag": 1, "msg": "密码错误!"}
    else:
        dic = {"flag": 0, "msg": "用户不存在!"}
    comment.service_send(conn, dic)
Ejemplo n.º 2
0
def login(dic, conn):
    name = dic.get("name")
    pwd = dic.get("pwd")
    object_user = comment.check_login(name, pwd)
    if object_user:
        notice = comment.check_notice(flag=1)
        dic_back = {
            "flag": 1,
            "msg": "登陆成功!",
            "user_id": object_user.id,
            "is_vip": object_user.is_vip,
            "notice": notice
        }
        session_obj = comment.get_md5(name)
        dic_back["session"] = session_obj
        dic_back["is_vip"] = object_user.is_vip

        settings.mutex.acquire()
        alive_user[dic["addr"]] = [session_obj, object_user.id]
        settings.mutex.release()

        comment.service_send(conn, dic_back)

    else:
        dic_back = {"flag": 0, "msg": "账号或密码错误!"}
        comment.service_send(conn, dic_back)
Ejemplo n.º 3
0
def login(conn, dic):
    name = dic.get("name")
    pwd = dic.get("pwd")
    pwd_md = comment.get_md5(pwd)
    user_obj = comment.check_user_name(name)
    if not user_obj:
        dic_back = {"flag": 0, "msg": "用户不存在"}
    else:
        if pwd_md == user_obj.password:
            id = user_obj.id
            session = comment.get_md5(name)
            addr = dic.get("addr")
            mutex.acquire()
            alive_user[addr] = [session,id]
            mutex.release()
            dic_back = {"flag": 1, "msg": "登陆成功!", "session": session,"notice":comment.select_first_notice()}
        else:
            dic_back = {"flag": 0, "msg": "密码错误!"}
    comment.service_send(conn, dic_back)
Ejemplo n.º 4
0
def register(conn, dic):
    name = dic.get("name")
    pwd = dic.get("pwd")
    pwd_md = comment.get_md5(pwd)
    flag = comment.check_user_name(name)
    if flag:
        dic_back = {"flag": 0, "msg": "用户已经存在!"}
    else:
        user_obj = models.User(name=name, password=pwd_md, is_vip=0, is_locked=0, user_type=dic.get("user_type"),
                               register_time=comment.get_time())
        user_obj.save()
        dic_back = {"flag": 1, "msg": "注册成功!"}
    comment.service_send(conn, dic_back)
Ejemplo n.º 5
0
def login(c):
    while True:
        name = input("请输入用户名:").strip()
        pwd = input("请输入密码:").strip()
        md_pwd = comment.get_md5(pwd)
        dic = {"type": "login", "name": name, "pwd": md_pwd}
        comment.client_send(c, dic)
        dic_back = comment.client_recv(c)
        if dic_back.get("flag"):
            print(dic_back.get("msg"))
            user_dict["session"] = dic_back.get("session")
            user_dict["user_id"] = dic_back.get("user_id")
            break
        else:
            print(dic_back.get("msg"))
Ejemplo n.º 6
0
def register(c):
    while True:
        name = input("请输入需要注册的用户名:")
        pwd = input("请输入密码:")
        re_pwd = input("请确认密码:")
        if pwd == re_pwd:
            md_pwd = comment.get_md5(pwd)
            dic = {"type": "register", "name": name, "pwd": md_pwd, "user_type": "admin"}
            comment.client_send(c, dic)
            dic_back = comment.client_recv(c)
            if dic_back.get("flag"):
                print(dic_back.get("msg"))
                break
            else:
                print(dic_back.get("msg"))
Ejemplo n.º 7
0
def register(conn, dic):
    name = dic.get("name")
    pwd = dic.get("pwd")
    user_type = dic.get("user_type")
    flag = comment.check_user(name)
    if flag:
        dic1 = {"flag": 0, "msg": "用户已存在!"}
        comment.service_send(conn, dic1)
        return
    password = comment.get_md5(pwd)
    register_time = time.strftime("%Y-%m-%d %H:%M:%S")
    user_obj = models.User(name=name,
                           password=password,
                           is_vip=0,
                           is_locked=0,
                           user_type=user_type,
                           register_time=register_time)
    user_obj.save()
    dic1 = {"flag": 1, "msg": "注册成功!"}
    comment.service_send(conn, dic1)