def post_picture(user_id):
        user = get_requesting_user()

        if user_id != user.id:
            return base_routes.make_not_authorized_response()

        image_file = request.files['file']
        if not image_file:
            return base_routes.make_bad_request_response('missing image data')

        image_data = image_file.read()
        if not is_allowable_image(image_data):
            return base_routes.make_bad_request_response('unallowed image type')

        filename = image_to_user_filename(image_data, user_id)

        store_image(image_file, filename)

        user.picture_filename = filename
        store.session.add(user)
        store.session.commit()

        logger.info('Saving image {!r}'.format(filename))

        return base_routes.make_OK_response()
Exemple #2
0
    def post_picture(user_id):
        user = get_requesting_user()

        if user_id != user.id:
            return base_routes.make_not_authorized_response()

        image_file = request.files['file']
        if not image_file:
            return base_routes.make_bad_request_response('missing image data')

        image_data = image_file.read()
        if not is_allowable_image(image_data):
            return base_routes.make_bad_request_response(
                'unallowed image type')

        filename = image_to_user_filename(image_data, user_id)

        store_image(image_file, filename)

        user.picture_filename = filename
        store.session.add(user)
        store.session.commit()

        logger.info('Saving image {!r}'.format(filename))

        return base_routes.make_OK_response()
Exemple #3
0
 def request_reset_password(email):
     user = store.session.query(User).filter_by(email=email).first()
     if user is None:
         response = base_routes.make_not_found_response()
     else:
         error_message = mail_actions.request_password_reset(user)
         if error_message:
             response = base_routes.make_server_error_response(error_message)
         else:
             response = base_routes.make_OK_response()
     return response
Exemple #4
0
 def request_confirm_email():
     requester = get_requesting_user()
     if requester is None:
         response = base_routes.make_not_authorized_response()
     else:
         error_message = mail_actions.request_signup_email_confirmation(requester)
         if error_message:
             response = base_routes.make_server_error_response(error_message)
         else:
             response = base_routes.make_OK_response()
     return response
Exemple #5
0
 def request_confirm_email():
     requester = get_requesting_user()
     if requester is None:
         response = base_routes.make_not_authorized_response()
     else:
         error_message = mail_actions.request_signup_email_confirmation(
             requester)
         if error_message:
             response = base_routes.make_server_error_response(
                 error_message)
         else:
             response = base_routes.make_OK_response()
     return response
Exemple #6
0
 def request_reset_password(email):
     user = store.session.query(User).filter_by(email=email,
                                                active=True).first()
     if user is None:
         response = base_routes.make_not_found_response()
     else:
         error_message = mail_actions.request_password_reset(user)
         if error_message:
             response = base_routes.make_server_error_response(
                 error_message)
         else:
             response = base_routes.make_OK_response()
     return response
    def receive_email():

        logger.debug('Received an email.')

        if config.MAILER_TYPE == 'MAILGUN':
            verify = True
        else:
            verify = False
        email = Email.from_mailgun_data(request.values, verify=verify)
        logger.info('Received an email with content "{}"'.format(
            email.content))

        message = None
        message_id = Message.process_from_address(email.to_address)
        if message_id is not None:
            message = store.session.query(Message).filter_by(
                id=message_id).first()
        if message is None:
            logger.warning(
                'Received an email but did not find corresponding message.')
        else:
            logger.debug('Creating a new email to send')
            # Create a new message
            new_message = Message(
                conversation_id=message.conversation_id,
                sender_user_id=message.receiver_user().id,
                content=email.new_content,
            )
            store.session.add(new_message)
            store.session.commit()
            # Create an email to send to the recipient
            forward_to_address = message.sender_user.email
            forward_from_address = new_message.generate_from_address()
            forward_content = append_conversation_link(email.content,
                                                       message.conversation)
            forward_new_content = append_conversation_link(
                email.new_content, message.conversation)
            forward_email = Email(
                from_address=forward_from_address,
                to_address=forward_to_address,
                subject=email.subject,
                content=forward_content,
                new_content=forward_new_content,
            )
            error_message = get_mailer().send(forward_email)
        response = base_routes.make_OK_response()
        return response
    def receive_email():

        logger.debug('Received an email.')

        if config.MAILER_TYPE == 'MAILGUN':
            verify = True
        else:
            verify = False
        email = Email.from_mailgun_data(request.values, verify=verify)
        logger.info('Received an email with content "{}"'.format(email.content))

        message = None
        message_id = Message.process_from_address(email.to_address)
        if message_id is not None:
            message = store.session.query(Message).filter_by(id=message_id).first()
        if message is None:
            logger.warning('Received an email but did not find corresponding message.')
        else:
            logger.debug('Creating a new email to send')
            # Create a new message
            new_message = Message(
                conversation_id=message.conversation_id,
                sender_user_id=message.receiver_user().id,
                content=email.new_content,
            )
            store.session.add(new_message)
            store.session.commit()
            # Create an email to send to the recipient
            forward_to_address = message.sender_user.email
            forward_from_address = new_message.generate_from_address()
            forward_content = append_conversation_link(email.content, message.conversation)
            forward_new_content = append_conversation_link(email.new_content, message.conversation)
            forward_email = Email(
                from_address=forward_from_address,
                to_address=forward_to_address,
                subject=email.subject,
                content=forward_content,
                new_content=forward_new_content,
            )
            error_message = get_mailer().send(forward_email)
        response = base_routes.make_OK_response()
        return response
Exemple #9
0
 def post_picture(user_id):
     requester = get_requesting_user()
     if (user_id == requester.id):
         user = requester
         f = request.files['file']
         if f:
             filename = process_filename(f.filename, user_id)
             if filename is None:
                 response = base_routes.make_bad_request_response()
             else:
                 conn = tinys3.Connection(
                     config.S3_USERNAME, config.S3_KEY, tls=True)
                 # Upload it.  Set cache expiry time to 1 hr.
                 conn.upload(filename, f, config.S3_BUCKETNAME,
                             expires=3600)
                 user.picture_filename = filename
                 store.session.add(user)
                 store.session.commit()
                 response = base_routes.make_OK_response()
         else:
             response = base_routes.make_bad_request_response()
     else:
         response = base.routes.make_forbidden_response()
     return response