def send_mail_failed(cuID):
     """
         When a recurring payment fails, mail customer with request to pay manually
     """
     os_mail = OsMail()
     msgID = os_mail.render_email_template('payment_recurring_failed')
     os_mail.send_and_archive(msgID, cuID)
def webhook_invoice_chargeback(iID, amount, date, mollie_payment_id,
                               mollie_chargeback_id, note):
    """
    Actuall add chargeback invoice payment
    This function is separate for testability
    """
    from openstudio.os_invoice import Invoice
    invoice = Invoice(iID)

    print("note in wic")
    print(note)

    ipID = invoice.payment_add(
        amount,
        date,
        payment_methods_id=100,  # Static id for Mollie payments
        mollie_payment_id=mollie_payment_id,
        mollie_chargeback_id=mollie_chargeback_id,
        note=note)

    # Notify customer of chargeback
    cuID = invoice.get_linked_customer_id()
    os_mail = OsMail()
    msgID = os_mail.render_email_template('payment_recurring_failed')
    os_mail.send_and_archive(msgID, cuID)
Exemple #3
0
def test_osmail_render_template():
    """
        function to be used when testing rendering of OsMail messages
    """
    if not web2pytest.is_running_under_test(
            request, request.application) and not auth.has_membership(
                group_id='Admins'):
        redirect(URL('default', 'user', args=['not_authorized']))

    email_template = request.vars['email_template']
    invoices_id = request.vars['invoices_id']
    customers_orders_id = request.vars['customers_orders_id']
    invoices_payments_id = request.vars['invoices_payments_id']

    os_mail = OsMail()
    rendered_message = T('template not found...')
    if email_template == 'email_template_payment_recurring_failed':
        #TODO: write test

        pass
    elif email_template == 'email_template_order_received' or email_template == 'email_template_order_delivered':
        rendered_message = os_mail.render_email_template(
            email_template,
            customers_orders_id=customers_orders_id,
            return_html=True)
    elif email_template == 'email_template_sys_reset_password':
        rendered_message = os_mail.render_email_template(email_template,
                                                         return_html=True)

    return rendered_message
    def email_reminders_teachers_sub_request_open(self):
        """
        Send teachers reminders when a sub for their class hasn't been found yet.
        :return:
        """
        from openstudio.os_class import Class
        from openstudio.os_mail import OsMail
        from openstudio.os_sys_email_reminders import SysEmailReminders

        T = current.T
        db = current.db
        TODAY_LOCAL = current.TODAY_LOCAL

        # Check if reminders configured
        sys_reminders = SysEmailReminders('teachers_sub_request_open')
        reminders = sys_reminders.list()

        mails_sent = 0
        for reminder in reminders:
            # Get list of open classes on reminder date
            reminder_date = TODAY_LOCAL + datetime.timedelta(reminder.Days)

            query = (db.classes_otc.Status == 'open') & \
                    (db.classes_otc.ClassDate == reminder_date)

            rows = db(query).select(db.classes_otc.ALL)
            for row in rows:
                clsID = row.classes_id
                cls = Class(clsID, row.ClassDate)
                regular_teachers = cls.get_regular_teacher_ids()

                if not regular_teachers['error']:
                    auth_teacher_id = regular_teachers['auth_teacher_id']
                    teacher = db.auth_user(auth_teacher_id)

                    os_mail = OsMail()
                    result = os_mail.render_email_template(
                        'teacher_sub_request_open_reminder',
                        classes_otc_id=row.id,
                        return_html=True)

                    send_result = False
                    if not result['error']:
                        send_result = os_mail.send(
                            message_html=result['html_message'],
                            message_subject=T("Reminder - open class"),
                            auth_user_id=auth_teacher_id)

                    if send_result:
                        mails_sent += 1

            # send reminder to teacher

        return "Sent mails: %s" % mails_sent
    def email_trailcard_follow_up(self):
        """
        Send teachers reminders when a sub for their class hasn't been found yet.
        :return:
        """
        from openstudio.os_mail import OsMail

        T = current.T
        db = current.db
        os_mail = OsMail()
        TODAY_LOCAL = current.TODAY_LOCAL
        yesterday = TODAY_LOCAL - datetime.timedelta(days=1)

        left = [
            db.school_classcards.on(
                db.customers_classcards.school_classcards_id ==
                db.school_classcards.id),
            db.auth_user.on(
                db.customers_classcards.auth_customer_id == db.auth_user.id)
        ]

        query = (db.school_classcards.Trialcard == True) & \
                (db.customers_classcards.Enddate == yesterday)

        rows = db(query).select(db.customers_classcards.ALL,
                                db.auth_user.display_name,
                                left=left)

        mails_sent = 0

        for row in rows:
            result = os_mail.render_email_template(
                'trial_follow_up',
                customers_classcards_id=row.customers_classcards.id,
                return_html=True)

            os_mail.send(
                message_html=result['html_message'],
                message_subject=result['msg_subject'],
                auth_user_id=row.customers_classcards.auth_customer_id)

            mails_sent += 1

        return "Sent trial card follow up mails: %s" % mails_sent
Exemple #6
0
def test_osmail_render_sys_notification():
    """
        function to be used when testing rendering of OsMail messages
    """
    if not web2pytest.is_running_under_test(
            request, request.application) and not auth.has_membership(
                group_id='Admins'):
        redirect(URL('default', 'user', args=['not_authorized']))

    sys_notification = request.vars['sys_notification']
    invoices_id = request.vars['invoices_id']
    customers_orders_id = request.vars['customers_orders_id']
    invoices_payments_id = request.vars['invoices_payments_id']

    os_mail = OsMail()
    rendered_message = T('notification not found...')
    if sys_notification == 'order_created':
        rendered_message = os_mail.render_sys_notification(
            sys_notification, customers_orders_id=customers_orders_id)

    return rendered_message
Exemple #7
0
def webhook_invoice_chargeback(iID, chargeback_amount, chargeback_date,
                               mollie_payment_id, chargeback_id,
                               chargeback_details):
    """
    Chargebacks happen when a direct debit payment fails due to insufficient funds in the customers' bank account
    :return:
    """
    invoice = Invoice(iID)

    ipID = invoice.payment_add(
        chargeback_amount,
        chargeback_date,
        payment_methods_id=100,  # Static id for Mollie payments
        mollie_payment_id=mollie_payment_id,
        note="Mollie Chargeback (%s) - %s" %
        (chargeback_id, chargeback_details))

    # Notify customer of chargeback
    cuID = invoice.get_linked_customer_id()
    os_mail = OsMail()
    msgID = os_mail.render_email_template('payment_recurring_failed')
    os_mail.send(msgID, cuID)
    def email_teachers_sub_requests_daily_summary(self):
        """
        Send a daily summary of open sub requests to each teacher for the classtypes
        they're allowed to teach
        :return:
        """
        from .os_mail import OsMail
        from .os_teachers import Teachers

        db = current.db
        T = current.T
        os_mail = OsMail()

        # Get list of teachers
        teachers = Teachers()
        teacher_id_rows = teachers.get_teacher_ids()

        mails_sent = 0
        for row in teacher_id_rows:
            os_mail = OsMail()
            result = os_mail.render_email_template(
                'teacher_sub_requests_daily_summary',
                auth_user_id=row.id,
                return_html=True)

            send_result = False
            if not result['error']:
                send_result = os_mail.send(
                    message_html=result['html_message'],
                    message_subject=T("Daily summary - open classes"),
                    auth_user_id=row.id)

            if send_result:
                mails_sent += 1

        return "Sent mails: %s" % mails_sent
Exemple #9
0
def user():
    """
    exposes:
    http://..../[app]/default/user/login
    http://..../[app]/default/user/logout
    http://..../[app]/default/user/register
    http://..../[app]/default/user/profile
    http://..../[app]/default/user/retrieve_password
    http://..../[app]/default/user/change_password
    http://..../[app]/default/user/manage_users (requires membership in
    use @auth.requires_login()
        @auth.requires_membership('group name')
        @auth.requires_permission('read','table name',record_id)
    to decorate functions that need access control
    """
    # check if someone is looking for profile
    if 'profile' in request.args:
        redirect(URL('profile', 'index'))

    # Send styles email messages from auth
    osmail = OsMail()
    auth.messages.verify_email = osmail.render_email_template(
        'email_template_sys_verify_email', return_html=True)
    # auth.messages.reset_password = '******'
    auth.messages.reset_password = osmail.render_email_template(
        'email_template_sys_reset_password', return_html=True)
    # Log registration accepted terms (if any)

    auth.settings.register_onaccept.append(user_register_log_acceptance)
    auth.settings.login_onaccept.append(user_set_last_login)

    ## Create auth form
    if session.show_location:  # check if we need a requirement for the school_locations_id field for customers
        loc_query = (db.school_locations.AllowAPI == True)
        db.auth_user.school_locations_id.requires = IS_IN_DB(
            db(loc_query),
            'school_locations.id',
            '%(Name)s',
            error_message=T('Please select a location'),
            zero=T('Please select a location...'))
    # actually create auth form
    form = auth()

    form_login = ''
    login_link = ''
    login_title = ''
    login_message = ''
    form_register = ''
    register_link = ''
    register_title = ''
    reset_passwd = ''

    self_checkin = ''
    error_msg = ''

    try:
        organization = ORGANIZATIONS[ORGANIZATIONS['default']]
        company_name = organization['Name']
        has_terms = True if organization['TermsConditionsURL'] else False
        has_privacy_notice = True if organization['PrivacyNoticeURL'] else False
    except:
        company_name = ''
        organization = False
        has_terms = False
        has_privacy_notice = False

    if 'register' in request.args:
        register_title = T("Register")
        login_title = T("Already have an account?")
        login_link = A(T("Click here to log in"), _href=URL(args='login'))
        login_message = DIV(
            B("Can't register?"),
            BR(),
            T("In case you can't register because your email address already has an account, click"
              ),
            ' ',
            A(T("here"), _href=URL(args='request_reset_password')),
            ' ',
            T("to request a new password."),
            BR(),
            BR(),
        )
        response.view = 'default/user_login.html'
        user_registration_set_visible_fields()
        #db.auth_user.password.requires=IS_STRONG()

        first_name = form.element('#auth_user_first_name')
        first_name['_placeholder'] = T("First name...")
        last_name = form.element('#auth_user_last_name')
        last_name['_placeholder'] = T("Last name...")
        email = form.element('#auth_user_email')
        email['_placeholder'] = T("Email...")
        password = form.element('#auth_user_password')
        password['_placeholder'] = T("Password...")
        password2 = form.element('#auth_user_password_two')
        password2['_placeholder'] = T("Repeat Password...")

        location = ''
        if session.show_location:
            location = DIV(LABEL(form.custom.label.school_locations_id),
                           form.custom.widget.school_locations_id,
                           _class='form-group')

        accept_ul = UL(_id='accept_ul')
        accept_ul.append(
            LI(T('Confirm that the data above is true and complete')))
        if organization:
            if organization['TermsConditionsURL']:
                accept_ul.append(
                    SPAN(
                        T('Agree to the'), ' ',
                        A(T('Terms and conditions'),
                          _href=organization['TermsConditionsURL'],
                          _target="_blank")))

            if organization['PrivacyNoticeURL']:
                accept_ul.append(
                    SPAN(
                        T('Accept the'), ' ',
                        A(T('Privacy notice'),
                          _href=organization['PrivacyNoticeURL'],
                          _target="_blank")))

        form = DIV(
            form.custom.begin,
            DIV(LABEL(form.custom.label.first_name),
                form.custom.widget.first_name,
                _class='form-group'),
            DIV(LABEL(form.custom.label.last_name),
                form.custom.widget.last_name,
                _class='form-group'),
            DIV(LABEL(form.custom.label.email),
                form.custom.widget.email,
                _class='form-group'),
            DIV(LABEL(form.custom.label.password),
                form.custom.widget.password,
                _class='form-group'),
            DIV(LABEL(form.custom.label.password_two),
                form.custom.widget.password_two,
                _class='form-group'), location,
            SPAN(T('By signing up I'), _class='bold'), accept_ul, BR(),
            A(T('Cancel'),
              _href=URL(args='login'),
              _class='btn btn-default',
              _title=T('Back to login')),
            DIV(form.custom.submit, _class='pull-right'), form.custom.end)

        form_register = form

    # set logo
    branding_logo = os.path.join(request.folder, 'static',
                                 'plugin_os-branding', 'logos',
                                 'branding_logo_login.png')
    if os.path.isfile(branding_logo):
        logo_img = IMG(_src=URL(
            'static', 'plugin_os-branding/logos/branding_logo_login.png'))
        logo_text = ''
        logo_class = 'logo_login'
    else:
        logo_img = ''
        logo_text = SPAN(B('Open'), 'Studio')

        logo_class = ''

    logo_login = DIV(logo_img, logo_text, _class=logo_class)

    # set email placeholder
    if 'login' in request.args or 'request_reset_password' in request.args:
        email = form.element('#auth_user_email')
        email['_placeholder'] = T("Email...")

    if 'login' in request.args:
        response.view = 'default/user_login.html'
        login_title = T("Log in")
        register_title = T("New here?")

        auth.messages.login_button = T('Sign In')

        email = form.element('#auth_user_email')
        email['_placeholder'] = T("Email...")
        password = form.element('#auth_user_password')
        password['_placeholder'] = T("Password...")

        submit = form.element('input[type=submit]')
        submit['_value'] = T('Sign In')

        form = DIV(
            form.custom.begin,
            DIV(form.custom.widget.email,
                SPAN(
                    _class='glyphicon glyphicon-envelope form-control-feedback'
                ),
                _class='form-group has-feedback'),
            DIV(form.custom.widget.password,
                SPAN(_class='glyphicon glyphicon-lock form-control-feedback'),
                _class='form-group has-feedback'),
            LABEL(form.custom.widget.remember_me,
                  ' ',
                  form.custom.label.remember_me,
                  _id='label_remember'),
            DIV(form.custom.submit, _class='pull-right'),
            form.custom.end,
        )

        if not 'request_reset_password' in auth.settings.actions_disabled:
            reset_passwd = A(T('Lost password?'),
                             _href=URL(args='request_reset_password'))

        if not 'register' in auth.settings.actions_disabled:
            register_link = A(T("Click here to register"),
                              _href=URL(args='register'))

        form_login = form


    if 'request_reset_password' in request.args or \
       'reset_password' in request.args:
        submit = form.element('input[type=submit]')
        submit['_value'] = T('Reset password')

    if 'request_reset_password' in request.args:
        response.view = 'default/user_login.html'

        cancel = A(T("Cancel"),
                   _href=URL('/user', args='login'),
                   _class='btn btn-default')
        form = DIV(form.custom.begin,
                   DIV(form.custom.widget.email, _class='form-group'),
                   DIV(form.custom.submit, _class='pull-right'), cancel,
                   form.custom.end)

        form_login = form
        login_title = T("Reset password")

        register_title = T("Info")
        register_link = SPAN(
            T("After entering your email address and clicking the Reset password button"
              ), ' ',
            T("you should receive an email with a link to reset your password within a few minutes."
              ), ' ',
            T("In case you don't receive an email, please check your spam folder."
              ), BR(), BR(),
            A(T("Click here to log in"), _href=URL(args="login")))

    if 'reset_password' in request.args:
        response.view = 'default/user_login.html'

        passwd = form.element('#no_table_new_password')
        passwd['_placeholder'] = T("New password...")
        passwd2 = form.element('#no_table_new_password2')
        passwd2['_placeholder'] = T("Repeat new password...")

        form = DIV(
            form.custom.begin,
            os_gui.get_form_group(form.custom.label.new_password,
                                  form.custom.widget.new_password),
            os_gui.get_form_group(form.custom.label.new_password2,
                                  form.custom.widget.new_password2),
            form.custom.submit, form.custom.end)

        form_login = form
        login_title = T("Reset password")
        register_title = T("Info")
        register_link = SPAN(
            T("After setting a new password, you will be logged in automatically."
              ), ' ', T("Please use your new password for future logins."),
            BR(), BR(), A(T("Click here to log in"), _href=URL(args="login")))

    if 'change_password' in request.args:
        response.view = 'default/user_login.html'
        response.title = T('Change password')

        oldpwd = form.element('#no_table_old_password')
        oldpwd['_placeholder'] = T('Old password...')
        passwd = form.element('#no_table_new_password')
        passwd['_placeholder'] = T("New password...")
        passwd2 = form.element('#no_table_new_password2')
        passwd2['_placeholder'] = T("Repeat password...")

        cancel = A(T('Cancel'),
                   _href=URL('profile', 'index'),
                   _class='btn btn-default')

        form = DIV(
            form.custom.begin,
            os_gui.get_form_group(form.custom.label.old_password,
                                  form.custom.widget.old_password),
            os_gui.get_form_group(form.custom.label.new_password,
                                  form.custom.widget.new_password),
            os_gui.get_form_group(form.custom.label.new_password2,
                                  form.custom.widget.new_password2),
            DIV(form.custom.submit, _class='pull-right'), cancel,
            form.custom.end)

        form_login = form
        login_title = T("Change password")

    return dict(form=form,
                form_login=form_login,
                form_register=form_register,
                content=form,
                error_msg=error_msg,
                reset_passwd=reset_passwd,
                register_link=register_link,
                register_title=register_title,
                login_link=login_link,
                login_title=login_title,
                login_message=login_message,
                self_checkin=self_checkin,
                company_name=company_name,
                has_organization=True if organization else False,
                has_terms=has_terms,
                has_privacy_notice=has_privacy_notice,
                logo_login=logo_login)
def user():
    """
    exposes:
    http://..../[app]/default/user/login
    http://..../[app]/default/user/logout
    http://..../[app]/default/user/register
    http://..../[app]/default/user/profile
    http://..../[app]/default/user/retrieve_password
    http://..../[app]/default/user/change_password
    http://..../[app]/default/user/manage_users (requires membership in
    use @auth.requires_login()
        @auth.requires_membership('group name')
        @auth.requires_permission('read','table name',record_id)
    to decorate functions that need access control
    """

    # If saml2 is enabled, use that one
    if configuration.get('auth.saml2_auth'):
        return saml_user()

    # check if someone is looking for profile
    if 'profile' in request.args:
        redirect(URL('profile', 'index'))

    # Send styles email messages from auth
    osmail = OsMail()
    auth.messages.verify_email = osmail.render_email_template(
        'sys_verify_email', return_html=True)['html_message']
    # auth.messages.reset_password = '******'
    auth.messages.reset_password = osmail.render_email_template(
        'sys_reset_password', return_html=True)['html_message']
    # Log registration accepted terms (if any)

    auth.settings.register_onaccept.append(user_register_log_acceptance)
    auth.settings.login_onaccept.append(user_set_last_login)

    # Fetch reCAPTCHA settings
    recaptcha_enabled = get_sys_property('recaptcha_enabled')
    recaptcha_site_key = get_sys_property('recaptcha_site_key')
    recaptcha_secret_key = get_sys_property('recaptcha_secret_key')
    use_recaptcha = False
    if recaptcha_enabled == "on" and recaptcha_site_key and recaptcha_secret_key:
        use_recaptcha = True

    ## Create auth form
    if session.show_location:  # check if we need a requirement for the school_locations_id field for customers
        loc_query = (db.school_locations.AllowAPI == True)
        db.auth_user.school_locations_id.requires = IS_IN_DB(
            db(loc_query),
            'school_locations.id',
            '%(Name)s',
            error_message=T('Please select a location'),
            zero=T('Please select a location...'))

    if get_sys_property('registration_requires_mobile') == "on":
        db.auth_user.mobile.requires = IS_LENGTH(
            minsize=8, error_message=T("Please enter a valid phone number"))

    # actually create auth form
    # Set nicer error messages for name fields
    db.auth_user.first_name.requires = IS_NOT_EMPTY(
        error_message=T("Please enter your first name"))
    db.auth_user.last_name.requires = IS_NOT_EMPTY(
        error_message=T("Please enter your last name"))

    form = ''
    form_login = ''
    login_link = ''
    login_title = ''
    login_message = ''
    form_register = ''
    register_link = ''
    register_title = ''
    reset_passwd = ''
    _next = request.vars['_next'] or ""

    self_checkin = ''
    error_msg = ''

    try:
        organization = ORGANIZATIONS[ORGANIZATIONS['default']]
        company_name = B(organization['Name'])
        has_terms = True if organization['TermsConditionsURL'] else False
        has_privacy_notice = True if organization['PrivacyNoticeURL'] else False
    except:
        company_name = ''
        organization = False
        has_terms = False
        has_privacy_notice = False

    if 'register' in request.args:
        # Enforce strong passwords
        db.auth_user.password.requires.insert(0, IS_STRONG())
        recaptcha2 = ""
        if use_recaptcha:
            auth.settings.captcha = Recaptcha2(
                request,
                recaptcha_site_key,
                recaptcha_secret_key,
                error_message=T("Please verify you're not a robot"))
            form = auth()
            recaptcha2 = DIV(
                BR(),
                Recaptcha2(
                    request,
                    recaptcha_site_key,
                    recaptcha_secret_key,
                    error_message=T("Please verify you're not a robot")),
                DIV(
                    DIV(form.errors.get('captcha', ''), _class="error"),
                    _class="error-wrapper",
                ),
            )
        else:
            form = auth()

        register_title = T("Create your account")
        login_title = T("Already have an account?")
        login_link = A(T("Click here to log in"),
                       _href=URL(args='login', vars=request.vars))
        login_message = DIV(
            B("Can't register?"),
            BR(),
            T("In case you can't register because your email address already has an account, click"
              ),
            ' ',
            A(T("here"), _href=URL(args='request_reset_password')),
            ' ',
            T("to request a new password."),
            BR(),
            BR(),
        )
        response.view = 'default/user_login.html'
        user_registration_set_visible_fields()

        first_name = form.element('#auth_user_first_name')
        first_name['_placeholder'] = T("First name...")
        last_name = form.element('#auth_user_last_name')
        last_name['_placeholder'] = T("Last name...")
        email = form.element('#auth_user_email')
        email['_placeholder'] = T("Email...")
        password = form.element('#auth_user_password')
        password['_placeholder'] = T("Password...")
        password2 = form.element('#auth_user_password_two')
        password2['_placeholder'] = T("Repeat Password...")
        submit = form.element('input[type=submit]')
        submit['_value'] = T('Create account')

        location = ''
        if session.show_location:
            location = DIV(LABEL(form.custom.label.school_locations_id),
                           form.custom.widget.school_locations_id,
                           _class='form-group')

        phone = ''
        if get_sys_property('registration_requires_mobile') == "on":
            mobile = form.element('#auth_user_mobile')
            mobile['_placeholder'] = T("Phone...")

            phone = DIV(LABEL(T("Phone")),
                        form.custom.widget.mobile,
                        _class='form-group')

        accept_ul = UL(_id='accept_ul')
        accept_ul.append(
            LI(T('Confirm that the data above is true and complete')))
        if organization:
            if organization['TermsConditionsURL']:
                accept_ul.append(
                    SPAN(
                        T('Agree to the'), ' ',
                        A(T('Terms and conditions'),
                          _href=organization['TermsConditionsURL'],
                          _target="_blank")))

            if organization['PrivacyNoticeURL']:
                accept_ul.append(
                    SPAN(
                        T('Accept the'), ' ',
                        A(T('Privacy notice'),
                          _href=organization['PrivacyNoticeURL'],
                          _target="_blank")))

        form = DIV(
            form.custom.begin,
            DIV(LABEL(form.custom.label.first_name),
                form.custom.widget.first_name,
                _class='form-group'),
            DIV(LABEL(form.custom.label.last_name),
                form.custom.widget.last_name,
                _class='form-group'),
            DIV(LABEL(form.custom.label.email),
                form.custom.widget.email,
                _class='form-group'), phone,
            DIV(LABEL(form.custom.label.password),
                form.custom.widget.password,
                _class='form-group'),
            DIV(LABEL(form.custom.label.password_two),
                form.custom.widget.password_two,
                _class='form-group'), location,
            SPAN(T('By creating an account I'), _class='bold'), accept_ul,
            recaptcha2, BR(),
            A(T('Cancel'),
              _href=URL(args='login'),
              _class='btn btn-default',
              _title=T('Back to login')),
            DIV(form.custom.submit, _class='pull-right'), form.custom.end)

        form_register = form

    # set logo
    logo_login = user_get_logo_login()

    if 'logout' in request.args or 'not_authorized' in request.args or 'verify_email' in request.args:
        form = auth()

    if 'login' in request.args:
        form = auth()

        response.view = 'default/user_login.html'
        login_title = T("Log in")
        register_title = T("Create your account")

        auth.messages.login_button = T('Sign In')

        email = form.element('#auth_user_email')
        email['_placeholder'] = T("Email...")
        password = form.element('#auth_user_password')
        password['_placeholder'] = T("Password...")

        submit = form.element('input[type=submit]')
        submit['_value'] = T('Sign In')

        form = DIV(
            form.custom.begin,
            DIV(form.custom.widget.email,
                SPAN(
                    _class='glyphicon glyphicon-envelope form-control-feedback'
                ),
                _class='form-group has-feedback'),
            DIV(form.custom.widget.password,
                SPAN(_class='glyphicon glyphicon-lock form-control-feedback'),
                _class='form-group has-feedback'),
            LABEL(form.custom.widget.remember_me,
                  ' ',
                  form.custom.label.remember_me,
                  _id='label_remember'),
            DIV(form.custom.submit, _class='pull-right'),
            form.custom.end,
        )

        if not 'request_reset_password' in auth.settings.actions_disabled:
            reset_passwd = A(T('Lost password?'),
                             _href=URL(args='request_reset_password'))

        if not 'register' in auth.settings.actions_disabled:
            form_register = SPAN(
                T("Are you new here and would you like to create an account?"),
                BR(),
                T("Please click the button below to get started."),
                BR(),
            )
            register_link = A(T("Create your account"),
                              _href=URL(args='register', vars=request.vars),
                              _class='btn btn-primary btn-create_your_account')
        form_login = form

    if 'request_reset_password' in request.args:
        recaptcha2 = ""
        if use_recaptcha:
            auth.settings.captcha = Recaptcha2(
                request,
                recaptcha_site_key,
                recaptcha_secret_key,
                error_message=T("Please verify you're not a robot"))
            form = auth()
            recaptcha2 = DIV(
                BR(),
                Recaptcha2(
                    request,
                    recaptcha_site_key,
                    recaptcha_secret_key,
                    error_message=T("Please verify you're not a robot")),
                DIV(
                    DIV(form.errors.get('captcha', ''), _class="error"),
                    _class="error-wrapper",
                ),
            )
        else:
            form = auth()

        response.view = 'default/user_login.html'

        cancel = A(T("Cancel"),
                   _href=URL('/user', args='login'),
                   _class='btn btn-default')
        form = DIV(form.custom.begin,
                   DIV(form.custom.widget.email,
                       _class='form-group'), recaptcha2, BR(),
                   DIV(form.custom.submit, _class='pull-right'), cancel,
                   form.custom.end)

        form_login = form
        login_title = T("Reset password")

        register_title = T("Info")
        register_link = SPAN(
            T("After entering your email address and clicking the Reset password button"
              ), ' ',
            T("you should receive an email with a link to reset your password within a few minutes."
              ), ' ',
            T("In case you don't receive an email, please check your spam folder."
              ), BR(), BR(),
            A(T("Click here to log in"), _href=URL(args="login")))

    # set email placeholder
    if 'login' in request.args or 'request_reset_password' in request.args:
        email = form.element('#auth_user_email')
        email['_placeholder'] = T("Email...")

    if 'reset_password' in request.args:
        # Enforce strong passwords
        db.auth_user.password.requires.insert(0, IS_STRONG())
        recaptcha2 = ""
        if use_recaptcha:
            auth.settings.captcha = Recaptcha2(
                request,
                recaptcha_site_key,
                recaptcha_secret_key,
                error_message=T("Please verify you're not a robot"))
            form = auth()
            recaptcha2 = DIV(
                BR(),
                Recaptcha2(
                    request,
                    recaptcha_site_key,
                    recaptcha_secret_key,
                    error_message=T("Please verify you're not a robot")),
                DIV(
                    DIV(form.errors.get('captcha', ''), _class="error"),
                    _class="error-wrapper",
                ),
            )
        else:
            form = auth()

        response.view = 'default/user_login.html'

        passwd = form.element('#no_table_new_password')
        passwd['_placeholder'] = T("New password...")
        passwd2 = form.element('#no_table_new_password2')
        passwd2['_placeholder'] = T("Repeat new password...")

        form = DIV(
            form.custom.begin,
            os_gui.get_form_group(form.custom.label.new_password,
                                  form.custom.widget.new_password),
            os_gui.get_form_group(form.custom.label.new_password2,
                                  form.custom.widget.new_password2),
            recaptcha2, BR(), form.custom.submit, form.custom.end)

        form_login = form
        login_title = T("Reset password")
        register_title = T("Info")
        register_link = SPAN(
            T("After setting a new password, you will be logged in automatically."
              ), ' ', T("Please use your new password for future logins."),
            BR(), BR(), A(T("Click here to log in"), _href=URL(args="login")))


    if 'request_reset_password' in request.args or \
       'reset_password' in request.args:
        submit = form.element('input[type=submit]')
        submit['_value'] = T('Reset password')

    if 'change_password' in request.args:
        # Enforce strong passwords
        db.auth_user.password.requires.insert(0, IS_STRONG())
        form = auth()

        response.view = 'default/user_login.html'
        response.title = T('Change password')

        oldpwd = form.element('#no_table_old_password')
        oldpwd['_placeholder'] = T('Old password...')
        passwd = form.element('#no_table_new_password')
        passwd['_placeholder'] = T("New password...")
        passwd2 = form.element('#no_table_new_password2')
        passwd2['_placeholder'] = T("Repeat password...")

        cancel = A(T('Cancel'),
                   _href=URL('profile', 'index'),
                   _class='btn btn-default')

        form = DIV(
            form.custom.begin,
            os_gui.get_form_group(form.custom.label.old_password,
                                  form.custom.widget.old_password),
            os_gui.get_form_group(form.custom.label.new_password,
                                  form.custom.widget.new_password),
            os_gui.get_form_group(form.custom.label.new_password2,
                                  form.custom.widget.new_password2),
            DIV(form.custom.submit, _class='pull-right'), cancel,
            form.custom.end)

        form_login = form
        login_title = T("Change password")

    if "/shop/subscription" in _next:
        os_tools = OsTools()
        login_message_subscription = os_tools.get_sys_property(
            "shop_login_message_subscription") or ""

        if login_message_subscription:
            company_name = SPAN(company_name,
                                BR(),
                                BR(),
                                XML(login_message_subscription),
                                _class='center')

    if "/shop/classcard" in _next:
        os_tools = OsTools()
        login_message_classcard = os_tools.get_sys_property(
            "shop_login_message_classcard") or ""

        if login_message_classcard:
            company_name = SPAN(company_name,
                                BR(),
                                BR(),
                                XML(login_message_classcard),
                                _class='center')

    return dict(form=form,
                form_login=form_login,
                form_register=form_register,
                content=form,
                error_msg=error_msg,
                reset_passwd=reset_passwd,
                register_link=register_link,
                register_title=register_title,
                login_link=login_link,
                login_title=login_title,
                login_message=login_message,
                self_checkin=self_checkin,
                company_name=company_name,
                has_organization=True if organization else False,
                has_terms=has_terms,
                has_privacy_notice=has_privacy_notice,
                logo_login=logo_login)