Example #1
0
def get_questions(token: str, app, pagination_result,
                  pagination_after) -> list or str:
    """Получаем случайные вопросы"""
    if check_token(token):
        if function.Authentication.get_authorization(token):
            status = get_status(token)
            if check_status_applicant(status):
                question = Question()
                question_list = QuestionList()
                random_id = question_list.rand()
                question.give_random_id(random_id)
                list_id_text_questions = question.choice_question(
                    pagination_result, pagination_after)
                if list_id_text_questions:
                    code = question_list.choice_code(random_id)
                    data = convert_dict(code, list_id_text_questions)
                    return information_output(app, data)
                else:
                    return page_is_not_found()
            else:
                return access_denied()
        else:
            return not_authorized()
    else:
        return incorrect_token()
def get_list_answer_applicant(token: str, email: str, app,
                              pagination_result: str,
                              pagination_after: str) -> list or str:
    """Получаем список ответов соискателя"""
    if check_token(token):
        if function.Authentication.get_authorization(token):
            status = get_status(token)
            if check_status_applicant(status):
                return access_denied()
            else:
                job_seeker = Applicant()
                name, email, status, users_id, applicant_id = job_seeker.get_information_from_email(
                    email)
                job_seeker.give_applicant_id(applicant_id)

                ans = Answer1()
                ans.give_applicant_id(applicant_id)
                list_tuple = ans.get_answer_list(pagination_result,
                                                 pagination_after)
                if list_tuple:

                    data = sort_ans_list(list_tuple)
                    return information_output(app, data)
                else:
                    return page_is_not_found()
        else:
            return not_authorized()
    else:
        return incorrect_token()
Example #3
0
def get_authorization(token: str) -> bool:
    """Получаем токен статус для проверки авторизации пользователя"""
    if check_token(token):
        user = Users()
        email = user.get_email(token)
        token_user = Token(email)
        bool_value = token_user.get_bool_token_status(token)
        return bool_value
    else:
        return incorrect_token()
Example #4
0
def log_out(token: str) -> str:
    """Выход из системы"""
    if check_token(token):
        if function.Authentication.get_authorization(token):
            user = Users()
            user.exit(token)
            return successfully_exited()
        else:
            return not_authorized()
    else:
        return incorrect_token()
Example #5
0
def get_picture(token: str):
    if check_token(token):
        picture = PictureUsers()
        path = picture.get_path_picture(token)
        if 'jpeg' in path or 'jpg' in path:
            mimetype = 'image/jpeg'
            return path, mimetype
        elif 'png' in path:
            mimetype = 'image/png'
            return path, mimetype
        else:
            return incorrect_mimetype()
    else:
        return incorrect_token()
Example #6
0
def get_information_employer(token: str) -> tuple:
    """Получаем всю информацию о работодателе"""
    if check_token(token):
        conn, cur = connecting()
        cur.execute(f"SELECT employer.employer_name, users.email, users.status, employer.users_id FROM users INNER JOIN token ON token.user_id = users.id INNER JOIN employer ON employer.users_id = "
                    f"users.id WHERE token_text = '{token}'")
        s = cur.fetchall()
        name = s[0][0]
        email = s[0][1]
        status = s[0][2]
        user_id = s[0][3]
        return name, email, status, user_id
    else:
        return incorrect_token()
def get_information_applicant(token: str) -> tuple:
    """Получаем всю информацию о соискателе"""
    if check_token(token):
        conn, cur = connecting()
        cur.execute(
            f"SELECT applicant.applicant_name, users.email, users.status, applicant.users_id, applicant.id FROM users INNER JOIN token ON token.user_id = users.id INNER JOIN applicant ON "
            f"applicant.users_id = "
            f"users.id WHERE token_text = '{token}'")
        list_tuple = cur.fetchall()
        name = list_tuple[0][0]
        email = list_tuple[0][1]
        status = list_tuple[0][2]
        users_id = list_tuple[0][3]
        applicant_id = list_tuple[0][4]
        return name, email, status, users_id, applicant_id
    else:
        return incorrect_token()
Example #8
0
def accept_applicant(token: str, employer_email: str,
                     applicant_email: str) -> str:
    """Принимаем соискателя на работу"""
    if check_token(token):
        if function.Authentication.get_authorization(token):
            status = get_status(token)
            if check_status_applicant(status):
                return access_denied()
            else:
                employ = Employer()
                employer_id = employ.get_employer_id(employer_email)
                job_seeker = Applicant()
                job_seeker.accept_applicant(employer_id, applicant_email)
                return successfully_updated()
        else:
            return not_authorized()
    else:
        return incorrect_token()
Example #9
0
def photo(file, token: str):
    if check_token(token):
        user = Users()
        email = user.get_email(token)
        user_id = user.get_id_users(email)
        picture = PictureUsers()
        if file.content_type == 'image/png':
            naming = f"image_user_{user_id}.png"
            path = f'C:/users/kpech/photousers/{naming}'
            file.save(f'C:/users/kpech/photousers/{naming}')
            return picture.add_photo(path, user_id)
        elif file.content_type == 'image/jpeg':
            naming = f"image_user_{user_id}.jpg"
            path = f'C:/users/kpech/photousers/{naming}'
            file.save(f'C:/users/kpech/photousers/{naming}')
            return picture.add_photo(path, user_id)
    else:
        return incorrect_token()
Example #10
0
def insert_answer_applicant(answer_applicant: list, question_id: int,
                            token: str, code: int):
    """Добавляем ответы соискателя"""
    if check_token(token):
        if function.Authentication.get_authorization(token):
            status = get_status(token)
            if check_status_applicant(status):
                question = Question()
                cnt = question.get_count_question()
                question_id = int(question_id)
                if question_id <= cnt:
                    applicant = Applicant()
                    applicant_id = applicant.get_applicant_id(token)
                    answer = Answer1()
                    count_answer = answer.check_answer_applicant(
                        applicant_id, code)
                    question = Question()
                    count_question = question.count_question_by_code(code)
                    if int(count_answer) < int(count_question):
                        applicant.update_category_applicants(
                            code, applicant_id)
                        answer.insert_answer_question(applicant_id,
                                                      answer_applicant,
                                                      question_id)
                        applicant_new_code = CodeApplicant()
                        list_code_answer = applicant_new_code.check_answer_code(
                            applicant_id)
                        if code not in list_code_answer:
                            applicant_new_code.insert_code_in_CodeApplicant(
                                code, applicant_id)
                        return succesfully_answer_added()
                    elif int(count_answer) == int(count_question):
                        answer.update_answer(answer_applicant, question_id)
                        return answer_the_question_update()
                else:
                    return incorrect_id_qustion()
            else:
                return access_denied()
        else:
            return not_authorized()
    else:
        return incorrect_token()
Example #11
0
def get_applicant_list_for_employer(token: str, app, pagination_result: str,
                                    pagination_after: str) -> list or str:
    """Получаем список соискателей для работодателей"""
    if check_token(token):
        if function.Authentication.get_authorization(token):
            status = get_status(token)
            if check_status_applicant(status):
                return access_denied()
            else:
                job_seeker = Applicant()
                list_tuples = job_seeker.list_for_employers(
                    pagination_result, pagination_after)
                if list_tuples:
                    data = convert_applicant_list_for_employer(list_tuples)
                    return information_output(app, data)
                else:
                    return page_is_not_found()
        else:
            return not_authorized()
    else:
        return incorrect_token()
Example #12
0
def get_inf_applicant(token: str, app, pagination_result: str,
                      pagination_after: str) -> list or str:
    """Получаем информацию по соискателям"""
    if check_token(token):
        if function.Authentication.get_authorization(token):
            status = get_status(token)
            if check_status_applicant(status):
                return access_denied()
            else:
                job_seeker = Applicant()
                list_tuple = job_seeker.get_applicant_list(
                    pagination_result, pagination_after)
                if list_tuple:
                    data = convert_applicant(list_tuple)
                    return information_output(app, data)
                else:
                    return page_is_not_found()
        else:
            return not_authorized()
    else:
        return incorrect_token()