Exemplo n.º 1
0
def send_user_pw_reset__email(req__url_root, u_account, pw_reset_token):
    """
    Send user pw reset email
    
    @return: pw reset link
    @raise exception: on send error
    """

    pw_reset_link = '%spw-reset?pw_rst_tok=%s' % (req__url_root, pw_reset_token)

    msg_body = ['Hello %s %s,' % (u_account.first_name,
                                  u_account.last_name),
                '',
                'A password reset request has been received for this email address.',
                'Please follow the link below to reset the password for your account:',
                '',
                pw_reset_link,
                '',
                'Happy knowledge editing!',
                'The Rhizi team.'
                ]
    msg_body = '\n'.join(msg_body)

    send_email__flask_ctx(recipients=[u_account.email_address],
                       subject="Rhizi password reset request",
                       body=msg_body)
    return pw_reset_link
Exemplo n.º 2
0
def send_user_activation_link__email(req__url_root, us_req):
    """
    Send user feedback by email along with screen capture attachments
    
    @return: activation_link
    @raise exception: on send error
    """

    activation_link = '%ssignup?v_tok=%s' % (req__url_root, us_req['validation_key'])

    msg_body = ['Hello %s %s,' % (us_req['first_name'],
                                  us_req['last_name']),
                '',
                'Thank you for your joining the Rhizi community!',
                '',
                'Below is a sign up confirmation link - open it in your browser to activate your account:',
                '',
                activation_link,
                '',
                'Happy knowledge editing!',
                'The Rhizi team.'
                ]
    msg_body = '\n'.join(msg_body)

    send_email__flask_ctx(recipients=[us_req['email_address']],
                       subject="Rhizi sign up request",
                       body=msg_body)
    return activation_link
Exemplo n.º 3
0
def rest__send_user_feedback__email():
    """
    REST API endpoint: send user feedback by email along with screen capture attachments
    """
    def sanitize_input(req):
        req_dict = req.get_json()
        url = req_dict['url']
        note = req_dict['note']
        img = decode_base64_uri(req_dict['img'])
        html = req_dict['html']
        user_agent = req_dict['browser']['userAgent']
        return RZ_User_Feedback(url=url,
                                note=note,
                                img=img,
                                html=html,
                                user_agent=user_agent)

    try:
        u_feedback = sanitize_input(request)
    except:
        log.warn('failed to sanitize inputs. request: %s' % request)
        return make_response__json(status=400)  # bad Request

    # FIXME: should be async via celery (or another method)
    session_user = session.get('username')

    msg_body = [
        'Feedback from user:'******'',
        'user: %s' % (session_user if session_user else "<not-logged-in>"),
        'user-agent: %s' % (u_feedback.user_agent),
        'watching URL: %s' % (u_feedback.url),
        'user-note: %s' % (u_feedback.note), ''
    ]
    msg_body = '\n'.join(msg_body)

    try:
        send_email__flask_ctx(
            recipients=[current_app.rz_config.feedback_recipient],
            subject="User Feedback",
            body=msg_body,
            attachments=[
                ('feedback_screenshot.png', 'image/png', u_feedback.img),
                ('feedback_page.html', 'text/html',
                 u_feedback.html.encode('utf-8')),
            ])
        return make_response__json()  # return empty json response

    except Exception:
        log.exception(
            'send_user_feedback__email: exception while sending email'
        )  # exception derived from stack
        return make_response__json(status=500)
Exemplo n.º 4
0
def rest__send_user_feedback__email():
    """
    REST API endpoint: send user feedback by email along with screen capture attachments
    """

    def sanitize_input(req):
        req_dict = req.get_json()
        url = req_dict['url']
        note = req_dict['note']
        img = decode_base64_uri(req_dict['img'])
        html = req_dict['html']
        user_agent = req_dict['browser']['userAgent']
        return RZ_User_Feedback(url=url,
                                note=note,
                                img=img,
                                html=html,
                                user_agent=user_agent)

    try:
        u_feedback = sanitize_input(request)
    except:
        log.warn('failed to sanitize inputs. request: %s' % request)
        return make_response__json(status=400)  # bad Request

    # FIXME: should be async via celery (or another method)
    session_user = session.get('username')

    msg_body = ['Feedback from user:'******'',
                     'user: %s' % (session_user if session_user else "<not-logged-in>"),
                     'user-agent: %s' % (u_feedback.user_agent),
                     'watching URL: %s' % (u_feedback.url),
                     'user-note: %s' % (u_feedback.note),
                     ''
                     ]
    msg_body = '\n'.join(msg_body)

    try:
        send_email__flask_ctx(recipients=[current_app.rz_config.feedback_recipient],
                           subject="User Feedback",
                           body=msg_body,
                           attachments=[('feedback_screenshot.png', 'image/png', u_feedback.img),
                                        ('feedback_page.html', 'text/html', u_feedback.html.encode('utf-8')),
                                        ])
        return make_response__json()  # return empty json response

    except Exception:
        log.exception('send_user_feedback__email: exception while sending email')  # exception derived from stack
        return make_response__json(status=500)
Exemplo n.º 5
0
def send_user_pw_reset__email(req__url_root, u_account, pw_reset_token):
    """
    Send user pw reset email
    
    @return: pw reset link
    @raise exception: on send error
    """

    pw_reset_link = '%spw-reset?pw_rst_tok=%s' % (req__url_root,
                                                  pw_reset_token)

    msg_body = [
        'Hello %s %s,' % (u_account.first_name, u_account.last_name), '',
        'A password reset request has been received for this email address.',
        'Please follow the link below to reset the password for your account:',
        '', pw_reset_link, '', 'Happy knowledge editing!', 'The Rhizi team.'
    ]
    msg_body = '\n'.join(msg_body)

    send_email__flask_ctx(recipients=[u_account.email_address],
                          subject="Rhizi password reset request",
                          body=msg_body)
    return pw_reset_link
Exemplo n.º 6
0
def send_user_activation_link__email(req__url_root, us_req):
    """
    Send user feedback by email along with screen capture attachments
    
    @return: activation_link
    @raise exception: on send error
    """

    activation_link = '%ssignup?v_tok=%s' % (req__url_root,
                                             us_req['validation_key'])

    msg_body = [
        'Hello %s %s,' % (us_req['first_name'], us_req['last_name']), '',
        'Thank you for your joining the Rhizi community!', '',
        'Below is a sign up confirmation link - open it in your browser to activate your account:',
        '', activation_link, '', 'Happy knowledge editing!', 'The Rhizi team.'
    ]
    msg_body = '\n'.join(msg_body)

    send_email__flask_ctx(recipients=[us_req['email_address']],
                          subject="Rhizi sign up request",
                          body=msg_body)
    return activation_link