Registration on a website that is done by user, but confirmed by administrator.

In a registration form it is a must to provide some password and user is deactivated by setting publish date to zeroes.
Sample front-end form is similar to following:

Code: Select all


<cms:form masterpage=k_user_template mode='create' enctype='multipart/form-data'  method='post'  anchor='0' >

    <cms:if k_success >

        <cms:set random_password = "<cms:excerpt count='5' trail='' truncate_chars='1'><cms:random_name /></cms:excerpt>" scope='global' />

        <cms:db_persist_form
            _invalidate_cache='0'
            k_page_title = "<cms:concat frm_first_name ' ' frm_last_name />"
            k_publish_date = '0000-00-00 00:00:00'
            extended_user_password = random_password
            extended_user_password_repeat = random_password
        />

 
            <cms:if k_success >

                <cms:send_mail from=k_email_from to=frm_extended_user_email subject='New Account Confirmation' debug='1'>
Welcome!

Thank you for the registration, you will receive the user name and password once we have verified your details.

If you have questions or if you need further information please do not hesitate to contact us at any time!

Your Team
<cms:show k_site_link />
                </cms:send_mail>

                <cms:send_mail reply_to=frm_extended_user_email from=k_email_from to=k_email_to subject='New Account Request' debug='1'>

User <cms:concat frm_first_name ' ' frm_last_name /> has requested access to the website.

<cms:show k_admin_link />

                </cms:send_mail>

                <cms:set_flash name='registration_success_msg' value='1' />
                <cms:redirect k_page_link />
            </cms:if>

    <cms:else />


    </cms:if>

    <div class="signup-input padding-top-20 padding-bottom-10">
        <cms:input type="bound" name="first_name" id="signup_first_name" placeholder="first name" />
        <cms:if k_error_first_name><div class="messages"><cms:show k_error_first_name /></div></cms:if>
    </div>
    <div class="signup-input padding-top-10 padding-bottom-10">
        <cms:input type="bound" name="last_name" id="signup_last_name" placeholder="last name" />
        <cms:if k_error_last_name><div class="messages"><cms:show k_error_last_name /></div></cms:if>
    </div>
    <div class="signup-input padding-top-10 padding-bottom-10">
        <cms:input type="bound" name="phone_number" id="signup_phone_number" placeholder="phone number" />
        <cms:if k_error_phone_number><div class="messages"><cms:show k_error_phone_number /></div></cms:if>
    </div>
    <div class="signup-input padding-top-10 padding-bottom-10">
        <cms:input type="bound" name="extended_user_email" id="signup_email_address" placeholder="email address" />
        <cms:if k_error_extended_user_email ><div class="messages"><cms:show k_error_extended_user_email /></div></cms:if>
    </div>
    <div class="signup-input padding-top-10 padding-bottom-10">
        <cms:input type="bound" name="company" id="signup_company" placeholder="company" />
        <cms:if k_error_company><div class="messages"><cms:show k_error_company /></div></cms:if>
    </div>
    <div class="signup-input padding-top-10 padding-bottom-10">
        <cms:input type="bound" name="position" id="signup_position" placeholder="position" />
        <cms:if k_error_position><div class="messages"><cms:show k_error_position /></div></cms:if>
    </div>
    <div class="signup-input padding-top-10 margin-bottom-40">
        <button id="signup-submit" type="submit" class="bg-blue">Register now</button>
    </div>

</cms:form>





Now in Users' template we can build the following picture, with required fields and a special radio button to enable account. By default such functionality (in the form of a checkbox) appears in default Couch Users section, so this effort will also make it available in our Extended Users template.

2017-10-19-112201.png
2017-10-19-112201.png (45.55 KiB) Viewed 363 times


Editable part of 'cms:template' block with 'config_form_view' is as follows for our sample (with bootstrap addon viewtopic.php?f=8&t=11023&p=28462#p28418 ):
Code: Select all

<!--
    If additional fields are required for users, they can be defined here in the usual manner.
-->

<cms:editable name='row_1' type='row' order='-10'>
    <cms:editable type='text' name='first_name' label='First Name' required='1' class='col-xs-2' />
    <cms:editable type='text' name='last_name' label='Last Name' required='1' class='col-xs-2' />
    <cms:editable type='text' name='phone_number' label='Phone Number' required='1' class='col-xs-2' />
</cms:editable>
<cms:editable name='row_2' type='row' order='-5'>
    <cms:editable type='text' name='company' label='Company' required='1' class='col-xs-3'/>
    <cms:editable type='text' name='position' label='Position' required='0' class='col-xs-3'/>
</cms:editable>

<cms:editable type='securefile' name='avatar' label='Avatar' show_preview='1' quality='95' preview_width='1' allowed_ext='png, jpg, jpeg' max_size='20480' thumb_width='260' thumb_height='260'  show_preview='0'  use_thumb_for_preview='0' />


<cms:config_form_view>
    <cms:field 'k_page_name' hide='1' />
    <cms:field 'extended_user_id' hide='1' />
    <cms:field 'extended_user_email' order='-20' label='Email' />


    <cms:persist
        k_publish_date="<cms:if frm_my_publish_status='0'>0000-00-00 00:00:00<cms:else/><cms:date format='Y-m-d H:i:s' /></cms:if>"
        _auto_title='1'
    />

    <cms:field 'my_publish_status'  no_wrapper='1' order='-30'>
        <div id="my_publish_status" style="margin-top: 15px; ">
            <label for="my_publish_status">
                <cms:if k_page_date='0000-00-00 00:00:00' >
                <span class="label label-error">Status</span>
                <cms:else />
                <span class="label label-success">Status</span>
                <span class="desc">(password is mailed out)</span>
                </cms:if>
            </label>
            <cms:input type='radio'
                  name=k_field_input_name
                  opt_selected="<cms:if k_page_date='0000-00-00 00:00:00' >0<cms:else />1</cms:if>"
                  opt_values='Disabled=0 | Enabled=1'
                  label='Status'
                />
        </div>
    </cms:field>

</cms:config_form_view>





Now, in order to mail out a password, once Status has been changed from disabled to enabled, we have to enable a theme and add 'cms:send_mail' to the admin form (as discussed in Couch 2.0 topic viewtopic.php?f=5&t=10241 and Selective Override topic viewtopic.php?f=2&t=10438&p=25693#p25696 ).

So, my extended users template is '/users/index.php' therefore the snippet is couch/theme/my/content_form_users-index-php.html.
The only modified part is k_success block, which happens once the page in backend is saved.

Code: Select all

        <cms:if k_success >

            <cms:if frm_my_publish_status = '1' && frm_k_publish_date = '0000-00-00 00:00:00'>

                <cms:set random_password = "<cms:excerpt count='5' trail='' truncate_chars='1'><cms:random_name /></cms:excerpt>" scope='global' />

                <cms:db_persist_form
                    _invalidate_cache='1'
                    _token=k_cur_token
                    extended_user_password = random_password
                    extended_user_password_repeat = random_password
                />

                    <cms:if k_success >

                        <cms:send_mail from=k_email_from to=frm_extended_user_email subject='Account Confirmation' debug='1'>
Welcome!

Your username is: <cms:show frm_extended_user_email />.
Your password is: <cms:show random_password />.

If you have questions or if you need further information please do not hesitate to contact us at any time!

Your Team
<cms:show k_site_link />
                        </cms:send_mail>

                    </cms:if>

            <cms:else />

            <cms:db_persist_form
                _invalidate_cache='1'
                _token=k_cur_token
            />

            </cms:if>




It has been successfully implemented and every time a new user is enabled in backend, he is sent a fresh password.
Thanks