Beispiel #1
0
def create_message(ticket_id):
    """
    Create a new message.
    """
    json_data = request.get_json()
    if request is None:
        return Iresponse.empty_json_request()

    current_identity = get_current_user()
    json_data["studentid"] = current_identity.id

    userId = escape(json_data["studentid"])
    msg = rp_message.create_request(json_data, ticket_id)

    ticket = Ticket.query.get(ticket_id)
    user = User.query.get(userId)

    if (ticket.user_id != user.id):
        message = createdEmailMessage(ticket.title, [ticket.email], ticket_id,
                                      json_data['message'], user.name)
        if current_app.config['SEND_MAIL_ON_MESSAGE']:
            print("send email")
            app = current_app._get_current_object()
            thr = Thread(target=sendAsyncEmail, args=[message, app])
            thr.start()
    return msg
Beispiel #2
0
def user_reset_password():
    """
    Function that checks a code, resets it if correct and changes user pass
    """
    json_data = request.get_json()
    if not validate_json(json_data, ["code", "password", "psw_confirmation"]):
        return Iresponse.empty_json_request()

    return rp_user.reset_password(json_data)
Beispiel #3
0
def user_set_reset_code():
    """
    Sets user reset code.
    """
    json_data = request.get_json()
    if not validate_json(json_data, ["email"]):
        return Iresponse.empty_json_request()

    email = json_data["email"]
    return rp_user.set_reset_code(email)
Beispiel #4
0
def create_course():
    """
    Check ticket submission and add to database.
    """
    print("Posted to /courses")
    jsonData = request.get_json()
    if jsonData is None:
        return Iresponse.empty_json_request()

    return rp_courses.create_request(jsonData)
Beispiel #5
0
def add_new_note():
    """
    Creates a new note.
    If no json is given return a 400 with no body.
    If no ticket is found return a 404 error.
    If a note is created return a 201 status.
    """
    jsonData = request.get_json()
    if jsonData is None:
        return Iresponse.empty_json_request()

    return rp_notes.create_request(jsonData)
Beispiel #6
0
def userid_exists():
    """
    Function that checks if the id of a user already exists.
    """
    json_data = request.get_json()
    if not validate_json(json_data, ["studentid"]):
        return Iresponse.empty_json_request()

    studentid = json_data["studentid"]
    user = User.query.filter_by(id=studentid).first()

    if user is None:
        return Iresponse.create_response({"status": False}, 200)
    return Iresponse.create_response({"status": True}, 200)
Beispiel #7
0
def user_exists():
    """
    Function that checks if a user email already exists.
    """
    json_data = request.get_json()
    if not validate_json(json_data, ["email"]):
        return Iresponse.empty_json_request()

    email = json_data["email"]
    user = User.query.filter_by(email=email).first()

    if user is None:
        return Iresponse.create_response({"status": False}, 200)
    return Iresponse.create_response({"status": True}, 200)
Beispiel #8
0
def register_user():
    '''
    Expects a request with email, name, id and password (and confirmed)
    and enters new user into database.
    '''

    json_data = request.get_json()

    if not validate_json(
            json_data,
        ["email", "name", "studentid", "password", "password_confirmation"]):
        return Iresponse.empty_json_request()

    return rp_user.register_user(json_data)
Beispiel #9
0
def add_tas_to_course(course_id):
    """
    Add new teaching assistants to course.
    """
    if request.files == '':
        return Iresponse.empty_json_request()
    for f_id in request.files:
        f = request.files[f_id]
        if f.filename.split('.').pop() != "csv":
            return Iresponse.create_response("", 400)
        filename = secure_filename(f.filename)
        f.save(filename)
        read_tas_csv(filename, course_id)
        os.remove(filename)
    return Iresponse.create_response("", 200)
Beispiel #10
0
def mailNotifyFailedMatch():
    '''
    Notify user that an email failed to match.
    '''
    # Request and check the data.
    json_data = request.get_json()
    if not validate_json(json_data, ['body', 'subject', 'address']):
        return Iresponse.empty_json_request()

    # Match on first success.
    subject = json_data['subject']
    address = json_data['address']
    body = json_data['body']
    subject = subject.replace('\n', '')
    message = ticketErrorEmail(subject, [address], body)
    app = current_app._get_current_object()
    thr = Thread(target=sendAsyncEmail, args=[message, app])
    thr.start()

    return Iresponse.create_response('Success', 200)
Beispiel #11
0
def mailMatchWithEmail():
    '''
    Try to match incoming email to an email address.
    '''
    # Request and check the data.
    json_data = request.get_json()
    if not validate_json(json_data, ['email']):
        return Iresponse.empty_json_request()

    # Match on first success.
    email = json_data['email'].lower()
    user = User.query.filter_by(email=email).first()

    if user is not None:
        id = user.id
        success = True
    else:
        id = None
        success = False
    response = {'success': success, 'studentid': id}
    return Iresponse.create_response(response, 200)
Beispiel #12
0
def mailMatchWithStudentID():
    '''
    Try to match incomming email on studentid.
    '''
    # Request and check the data.
    json_data = request.get_json()
    if not validate_json(json_data, ['studentid']):
        return Iresponse.empty_json_request()

    # Match on first success.
    studentid = json_data['studentid']
    user = User.query.filter_by(id=studentid).first()

    if user is not None:
        id = user.id
        success = True
    else:
        id = None
        success = False
    response = {'success': success, 'studentid': id}

    return Iresponse.create_response(response, 200)