Exemple #1
0
def stuffInfo():
    try:
        if request.method == "POST":
            raise Exception("method must be get")
        hr_id = request.values.get("hr_id")
        if not hr_id:
            raise Exception("hr_id can not be empty")

        retrieve_list = [
            "user_id", "username", "password", "name", "sex", "identitycard",
            "tags", "edubackground", "eduschool", "briefintro", "tel", "email",
            "politicsstatus", "address", "postcode", "workaddress"
        ]
        querylist = Person.get_obj(retrieve_list)
        msg = db.session.query(*querylist, Stafflist.corporation_id,
                               Stafflist.user_id, Hr.corporation_id, Hr.hr_id). \
            filter(Hr.hr_id == hr_id,
                   Stafflist.corporation_id == Hr.corporation_id,
                   Stafflist.user_id == Person.user_id)
        return_msg = []
        for line in msg:
            temp = zip(retrieve_list, line)
            return_msg.append(dict(temp))

        return dict(status=1, message="success", data=return_msg)
    except Exception as e:
        return dict(status=0, message=str(e), data="none")
Exemple #2
0
def login():
    status = 0
    try:
        if request.method == "GET":
            raise Exception("method must be post")
        username = request.form.get('username')
        password = request.form.get('password')
        usertype = request.form.get('usertype')
        if not all([username, password, usertype]):
            raise Exception("username/password/usertype must not be empty")
        if usertype == "1":  # 这里是hr登录
            retrieve_list = [
                "hr_id", "corporation_id", "name", "sex", "identitycard",
                "username", "password", "is_register"
            ]
            querylist = Hr.get_obj(retrieve_list)
            msg = db.session.query(*querylist)
            have_user = msg.filter(Hr.username == username).first()
            if not have_user:
                status = 2
                raise Exception("user is not exist, please check your account")
            passcheck = msg.filter(Hr.username == username,
                                   Hr.password == password).first()
            if not passcheck:
                status = 3
                raise Exception("password error")
            if passcheck.is_register == 0:
                status = 4
                raise Exception("hr account is checking now, please waiting")
            session["user_id"] = have_user[0]
            session["user_type"] = 1
            return dict(status=1,
                        message="success",
                        data=dict(zip(retrieve_list, passcheck)))
            # 如果用户名和密码不一致返回登录页面,并给提示信息
        elif usertype == "2":  # 这里是person登录
            retrieve_list = [
                "user_id", "username", "password", "name", "sex",
                "identitycard", "tags", "edubackground", "eduschool",
                "briefintro", "tel", "email", "politicsstatus", "address",
                "postcode", "workaddress"
            ]
            querylist = Person.get_obj(retrieve_list)
            msg = db.session.query(*querylist)
            have_user = msg.filter(Person.username == username).first()
            if not have_user:
                status = 2
                raise Exception("user is not exist, please check your account")
            passcheck = msg.filter(Person.username == username,
                                   Person.password == password).first()
            if not passcheck:
                status = 3
                raise Exception("password error")
            session["user_id"] = have_user[0]
            session["user_type"] = 2

            passcheck = list(passcheck)
            if passcheck[4] == 1:
                passcheck[4] = "男"
            else:
                passcheck[4] = "女"
            passcheck[10] = passcheck[10].strip(";")
            return_data = dict(zip(retrieve_list, passcheck))
            msg = db.session.query(Stafflist.user_id, Stafflist.corporation_id).\
                filter(Stafflist.user_id == have_user[0]).first()
            if msg:
                return_data["corporation_id"] = msg[1]
            else:
                return_data["corporation_id"] = 0

            return dict(status=1, message="success", data=return_data)
        else:
            raise Exception(
                "user type error: user type must be 1 for hr or 2 for staff")

    except Exception as e:
        return dict(status=status, message=str(e), data="none")