Esempio n. 1
0
def get_info_about_student_for_review(login):
    global comment
    student_for_db = GetStudent.get_info_about_student_for_review(login)
    reviews = GetStudent.get_comment_about_student(login)
    photo = student_for_db[3]
    if photo is None:
        photo = 'http://placehold.it/500x500'
    else:
        photo = photo
    student = {
        'login': login,
        'name': student_for_db[0],
        'last_name': student_for_db[1],
        'email': student_for_db[2],
        'photo': photo,
        'city': student_for_db[4],
        'country': student_for_db[5],
        'date_of_birth': student_for_db[6],
        'university': student_for_db[7],
        'time_of_styding': student_for_db[8],
        'linkedIn': student_for_db[9],
        'about': student_for_db[10],
        'cv': student_for_db[11]
    }
    comments = []
    for review in reviews:
        comment = {
             'review': review[0],
             'time': review[1],
             'company_name': review[2]
        }
        comments.append(comment)
    return render_template('profile-s-reviews.html', student=student, reviews=comments)
Esempio n. 2
0
def api_student_courses():
    global student_approve_status
    if 'student' in session:
        student_login = session['student']
        id_student = GetStudent.get_students_id_from_db(student_login)
        courses = GetApplyStudentCourse.get_courses_student(id_student)
        result = []
        for course in courses:
            status_student = course[12]
            if status_student == 0:
                student_approve_status = 'DELETE'
            if status_student == 1:
                student_approve_status = 'ACCEPT'
            if status_student is None:
                student_approve_status = 'IN PROGRESS'
            student_courses = {
                'company_name': course[0],
                'company_login': course[1],
                'course_name': course[4],
                'amount': course[5],
                'city': course[6],
                'country': course[7],
                'date_of_start': course[8],
                'date_of_end': course[9],
                'info': course[10],
                'status': course[11],
                'link': '/course/!' + str(course[2]) + '/!' + str(course[3]),
                'status_student': student_approve_status
            }
            result.append(student_courses)
        return render_template('courses-s.html', courses=result), 200
    else:
        return redirect('/'), 200
Esempio n. 3
0
def register_student_api():
    if not request.json:
        return jsonify(status="Bed request"), 400

    if 'login' not in request.json:
        return jsonify(status='Enter login'), 400

    if 'email' not in request.json:
        return jsonify(status='Enter email'), 400

    if 'firstName' not in request.json:
        return jsonify(status='Enter First Name'), 400

    if 'lastName' not in request.json:
        return jsonify(status='Enter LastName'), 400

    if 'password' not in request.json:
        return jsonify(status='Enter password'), 400

    if 'confirm' not in request.json:
        return jsonify(status='Enter confirm password'), 400

    first_name = request.json['firstName']
    last_name = request.json['lastName']
    password = request.json['password']
    login = request.json['login']
    email = request.json['email']
    confirm_password = request.json['confirm']

    if first_name != "" and last_name != "" and password != "" and login != "" and email != "" and \
            confirm_password != "":
        if password == confirm_password:
            if Student.check_login_for_used(login) == 0:
                return jsonify(status='Login already exists'), 400
            elif Student.check_email_for_used(email) == 0:
                return jsonify(status='Email already exists'), 400
            else:
                enc_password = generate_password_hash(password)
                Student.save_students_user(login, first_name, last_name, email,
                                           enc_password)
                id_student = GetStudent.get_students_id_from_db(login)
                Student.save_info_about_students(id_student)
            session['student'] = login
            return jsonify(redirect="true",
                           redirect_url="/user/student/" + login), 201
        else:
            return jsonify(redirect='false',
                           message='Passwords don`t match. Try again....'), 400
    else:
        return jsonify(redirect='false', message='Bad request'), 405
Esempio n. 4
0
def api_apply_on_course():
    if 'student' in session and request.json:
        link = request.json['link']
        id_course = link[0][1:3]
        id_company = link[1][1:3]
        check_course = ApplyOnCourse.check_course(id_course, id_company)
        if check_course == 0 or check_course > 1:
            print('bad')
            return 'hello'
        else:
            student_login = session['student']
            id_student = GetStudent.get_students_id_from_db(student_login)
            check_apply = ApplyOnCourse.api_check_already_applied(id_course, id_student)
            if check_apply == 1:
                return jsonify(redirect='false', redirect_url='/course/!' + id_course + '/!' + id_company,
                               message='You are already exists on this course.'), 200
            else:
                ApplyOnCourse.apply_students(id_course, id_student)
                return jsonify(redirect='true', redirect_url='/courses'), 200
def comment_about_student_request():
    print(request.json)
    if not request.json:
        return abort(400)
    if 'student_login' not in request.json:
        return abort(400)
    if 'review' not in request.json:
        return abort(400)
    student_login = request.json['student_login']
    review = request.json['review']
    if 'company' in session:
        company_login = session['company']
        if CommentAboutStudent.check_student_course(student_login, company_login) == 1:
            company_id = GetCompany.get_company_id_from_db(company_login)
            student_id = GetStudent.get_students_id_from_db(student_login)
            time = str(datetime.now().strftime('%H:%M, %d.%m.%Y'))
            CommentAboutStudent.comment_about_student(student_id, company_id, review, time)
            return jsonify(redirect="true", redirect_url=student_login), 200
        else:
            return jsonify(redirect="false", message="This user does not finished your course or "
                                                     "had not approved your course"), 200
def comment_about_course_request():
    if not request.json:
        return abort(400)
    if 'course_id' not in request.json:
        return abort(400)
    if 'review' not in request.json:
        return abort(400)
    course_id = request.json['course_id']
    review = request.json['review']
    if 'student' in session:
        student_login = session['student']
        student_id = GetStudent.get_students_id_from_db(student_login)
        check = CommentAboutCourse.check_student_review_course(
            student_id, course_id)
        if check == 1:
            time = str(datetime.now().strftime('%H:%M, %d.%m.%Y'))
            CommentAboutCourse.save_comment_about_course(
                course_id, student_id, review, time)
            return jsonify(redirect="true", redirect_url=""), 200
        if check == 0:
            return jsonify(redirect="false",
                           message='You don`t end this course'), 200
    return jsonify(redirect='false', message='Something bad..... Try later!!!')
    def equals_password(cls, password, login, new_password):
        value = ChangePasswordStudent.check_password(login, password)
        print(value)
        if value == 1:
            connect = mysql.connect()
            cursor = connect.cursor()

            password_enc = generate_password_hash(new_password)
            id_student = GetStudent.get_students_id_from_db(login)

            query = 'update students SET StudentsPassword = %s WHERE idStudents = %s'
            param = (password_enc, id_student)
            cursor.execute(query, param)

            response_value = value

            connect.commit()
            cursor.close()

        else:
            response_value = value

        return response_value
Esempio n. 8
0
def api_update_students():
    value = 0
    if 'student' in session:
        login = session['student']
        id_student = GetStudent.get_students_id_from_db(login)
        if 'first_name' in request.json:
            first_name = request.json['first_name']
            if first_name != "":
                UpdateStudent.update_student_first_name(id_student, first_name)
                value = 1

        if 'last_name' in request.json:
            last_name = request.json['last_name']
            if last_name != "":
                UpdateStudent.update_student_last_name(id_student, last_name)
                value = 1

        if 'img' in request.json:
            photo = request.json['img']
            if photo != "":
                UpdateStudent.update_students_photo(photo, id_student)
                value = 1

        if 'city' in request.json:
            city = request.json['city']
            if city != "Null":
                if city != "":
                    UpdateStudent.update_students_city(city, id_student)
                    value = 1

        if 'country' in request.json:
            country = request.json['country']
            if country != "Null":
                if country != "":
                    UpdateStudent.update_students_country(country, id_student)
                    value = 1

        if 'date_of_birth' in request.json:
            date_of_birth = request.json['date_of_birth']
            if date_of_birth != "":
                UpdateStudent.update_students_date_of_birth(
                    date_of_birth, id_student)
                value = 1

        if 'time_of_studing' in request.json:
            study_time = request.json['time_of_studing']
            if study_time != "":
                UpdateStudent.update_students_styding_time(
                    study_time, id_student)
                value = 1

        if 'university' in request.json:
            university = request.json['university']
            if university != "":
                UpdateStudent.update_students_university(
                    university, id_student)
                value = 1

        if 'link' in request.json:
            linked_in = request.json['link']
            if linked_in != "":
                UpdateStudent.update_students_linked_in(linked_in, id_student)
                value = 1

        if 'bio' in request.json:
            about_student = request.json['bio']
            if about_student != "":
                UpdateStudent.update_students_about_student(
                    about_student, id_student)
                value = 1

        if 'CV' in request.json:
            cv = request.json['CV']
            if cv != "":
                UpdateStudent.update_students_cv(cv, id_student)
                value = 1

        if 'email' in request.json:
            email = request.json['email']
            if email != "":
                check_email = UpdateStudent.check_student_email(email)
                if check_email == 1:
                    return jsonify(redirect='false',
                                   message='This email is already exist'), 201
                elif check_email == 0:
                    UpdateStudent.update_student_email(id_student, email)
                    value = 1

        if 'new_password' in request.json and 'old_password' in request.json and 'confirm_password' in request.json:
            new_password = request.json['new_password']
            old_password = request.json['old_password']
            confirm_password = request.json['confirm_password']
            if new_password != "" and old_password != "" and confirm_password != "":
                if confirm_password == new_password:
                    value = ChangePasswordStudent.equals_password(
                        old_password, login, new_password)
                    if value == 0:
                        return jsonify(redirect='false',
                                       message='Incorrect old password'), 200
                else:
                    return jsonify(
                        redirect='false',
                        message='Password don`t match. Try again....'), 200
        if value == 1:
            return jsonify(redirect='true',
                           redirect_url='/user/student/' + login,
                           message='Changes have been successfully saved'), 201
        else:
            return jsonify(
                redirect='false',
                message='Something went wrong. Try again later!!!'), 201

    else:
        return 'Please login'
Esempio n. 9
0
def api_info_about_students(login):
    if login == "":
        return jsonify(status="User`s login is null"), 404
    else:
        id_student = GetStudent.get_students_id_from_db(login)
        if id_student == 0:
            return 'Not such user in db'
        else:
            result = StudentSession.check_in_session_student()
            if result == 0:
                return 'please Log in'
            if result == login:
                first_name = GetStudent.get_student_first_name_from_db(login)
                last_name = GetStudent.get_student_last_name_from_db(login)
                email = GetStudent.get_student_email_from_db(login)
                city = GetStudent.get_student_city_from_db(id_student)
                country = GetStudent.get_student_country_from_db(id_student)
                date_of_birth = GetStudent.get_student_date_of_birth_from_db(id_student)
                university = GetStudent.get_student_university_from_db(id_student)
                time_of_study = GetStudent.get_student_time_of_study_from_db(id_student)
                link = GetStudent.get_student_linked_in_from_db(id_student)
                about = GetStudent.get_student_about_from_db(id_student)
                photo = GetStudent.get_student_photo_from_db(id_student)
                if photo is None:
                    photo = 'http://placehold.it/500x500'
                else:
                    photo = photo
                student = {
                    "first_name": first_name,
                    "last_name": last_name,
                    "email": email,
                    "city": city,
                    "country": country,
                    "dateOfBirth": date_of_birth,
                    "university": university,
                    "timeOfStudy": time_of_study,
                    "link": link,
                    "about": about,
                    "photo": photo
                }
                reviews = GetStudent.get_comment_about_student(login)
                comments = []
                for review in reviews:
                    result = {
                        'review': review[0],
                        'time': review[1],
                        'company_name': review[2]
                    }
                    comments.append(result)
                return render_template("profile-s.html", student=student, reviews=comments)

            else:
                return 'Please log in'