示例#1
0
def authorization(cursor, params):
    cursor.execute("select * from Authorization_info where login='******'".format(params[User.Login.value]))
    row = cursor.fetchone()

    status = Object()
    obj = Object()
    status.status = Status.Error.value

    if row is None:
        status.message = EventAuth.LoginNotExist.value
    elif row[2] == params[User.Password.value]:
        id_auth = row[0]
        obj.phone_number = '+' + row[3][1:]
        status.message = EventAuth.SuccessAuthorizaion.value
        status.status = Status.Ok.value
        #tok = params[User.Login.value] + str(time.time())
        #obj.token = md5(tok.encode('utf-8')).hexdigest()

        cursor.execute("select id from Profile where id_authorization_info={}".format(id_auth))
        row = cursor.fetchone()
        obj.id_profile = row[0]
        #cursor.execute("insert into Token_Table (token, last_update, id_profile) values('{}', {}, {})"
        #               .format(obj.token, int(time.time()), obj.id_profile))

        #  Вставка fcm_tokena
        cursor.execute("select * from FCM_Token where id_profile = {}".format(obj.id_profile))
        fcm = cursor.fetchone()
        if fcm is not None:
            cursor.execute("delete FCM_Token where id_profile = {}".format(obj.id_profile))
        cursor.execute("insert into FCM_Token (id_profile, fcm_token) values( {}, '{}')"
                       .format(obj.id_profile, params[User.FCM_Token.value]))

        cursor.execute("select * from Witcher where id_profile={}".format(obj.id_profile))
        row = cursor.fetchone()
        if row is not None:
            obj.type = 0
        else:
            obj.type = 1

        status.object = obj
    else:
        status.message = EventAuth.PasswordIncorrect.value

    return status.toJSON()
示例#2
0
def get_profile(cursor, params):
    status = Object()
    obj = Object()
    status.status = Status.Error.value

    id_profile = params.get(Profile.ID.value, None)

    if id_profile is None:
        cursor.execute(
            "select id_profile from Token_Table where token='{}'".format(
                params[User.Token.value]))
        row = cursor.fetchone()
        if row is None:
            return status.toJSON()
        else:
            id_profile = row[0]

    cursor.execute(
        "select a.id, a.name, a.about, b.photo from Profile as a left \
          join Photo as b on a.id_photo = b.id where a.id={}".format(
            id_profile))
    row = cursor.fetchone()

    if row is not None:
        status.status = Status.Ok.value
        obj.id = row[0]
        obj.name = row[1]
        obj.about = row[2]
        obj.photo = row[3]

        cursor.execute("select id from Witcher where id_profile={}".format(
            obj.id))
        row = cursor.fetchone()

        if row is not None:
            obj.type = Profile.Witcher.value
            cursor.execute(
                "select c.id, c.id_witcher, c.id_client, c.header, c.status, c.last_update,  \
                            c.last_update_status from Profile as a inner join Witcher as b on a.id=b.id_profile \
                            inner join Contract as c on c.id_witcher=b.id where b.id={}"
                .format(row[0]))
            row = cursor.fetchall()
            obj.history = Object()
            obj.history.count = len(row)
            obj.history.contract = {}
            for line in row:
                hist = Object()
                hist.id_contract = line[0]
                hist.id_witcher = line[1]
                hist.id_client = line[2]
                hist.header = line[3]
                hist.status = line[4]
                hist.last_update = line[5]
                hist.last_update_status = line[6]

                obj.history.contract[len(obj.history.contract)] = hist

        else:
            obj.type = Profile.Client.value
            cursor.execute("select id from Client where id_profile={}".format(
                obj.id))
            row = cursor.fetchone()

            cursor.execute(
                "select c.id, c.id_witcher, c.id_client, c.header, c.status, c.last_update, c.last_update_status \
                from Profile as a inner join Client as b on a.id=b.id_profile \
                inner join Contract as c on c.id_witcher=b.id where b.id={}".
                format(row[0]))
            row = cursor.fetchall()
            obj.history = Object()
            obj.history.count = len(row)
            obj.history.contract = {}
            for line in row:
                hist = Object()
                hist.id_contract = line[0]
                hist.id_witcher = line[1]
                hist.id_client = line[2]
                hist.header = line[3]
                hist.status = line[4]
                hist.last_update = line[5]
                hist.last_update_status = line[6]

                obj.history.contract[len(obj.history.contract)] = hist

    status.object = obj
    return status.toJSON()