Validate Registration

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Validate Registration

Coleen_Astalos
Is there a way in the macro validate_registration_form to check to see if the email address is in the "Members" group?  This would save me from having unauthorized members register for my site (authorized members would have already been added to the "Members" group).

Thanks,
Coleen
Reply | Threaded
Open this post in threaded view
|

Re: Validate Registration

Pedro
There are two steps: 1 - Create an exception message and 2 - edit validate_registration_form macro.
This is just my suggestion, you can use it to make your own message and code:
Step 1:
Override handle_registration_errors, adding the exception:
 <override_macro name="handle_registration_errors">
    <n.if.is_submitted_form>
        <then>
            <n.if.has_exception for="save-block">
                <then>
                    <n.handle_exception. for="save-block">
                        <div class="error-message important" style="margin:1em;padding:.5em 0">
                            <n.exception. name="user_is_not_member">
                                <t>You are not a Member.</t>                               
                            </n.exception.>
                            <n.exception. name="user_already_registered">
                                <t>You have already been registered.</t>
                                <a href="[n.forgot_password_path/]"><t>Forgot your password?</t></a>
                            </n.exception.> 
(...)

Step 2: Checking if the email given in the registration field is in the Members group:
<override_macro name="validate_registration_form">
    <n.users_in_group. group="Members">
        <n.set_var. name="in_members">
            <n.loop.>            
                <n.if.equal value1="[n.email_field.value/]" value2="[n.current_user.user_email/]">
                    <then>true<n.break/></then>
                </n.if.equal>            
            </n.loop.>
        </n.set_var.>
        <n.if.is_empty.remove_spaces.var name="in_members">
            <then.throw_template_exception name="user_is_not_member" />
        </n.if.is_empty.remove_spaces.var>
    </n.users_in_group.>
    
    <n.user_name_field.notify_if_empty/>
    <n.email_field.notify_if_empty/>
    <n.password_field.notify_if_empty/>
    <n.password2_field.notify_if_empty/>
    
    <n.if.not.equal value1="[n.password_field.value/]" value2="[n.password2_field.value/]">
        <then.throw_template_exception name="passwords_dont_match"/>
    </n.if.not.equal>  
    
    <n.if.not.accept_terms_field.is_checked>
        <then.throw_template_exception name="must_accept_terms_of_use"/>
    </n.if.not.accept_terms_field.is_checked>
    
</override_macro>
Let me know if you have any questions about the code.
My test forum.
Reply | Threaded
Open this post in threaded view
|

Re: Validate Registration

Coleen_Astalos
How do I see the rest of the first block?  At the bottom it just has ( ... )  Is it just the closing ends to the statements above (/div), etc.?
Coleen
Reply | Threaded
Open this post in threaded view
|

Re: Validate Registration

Pedro
See the macro handle_registration_errors. Then, override it adding:
<n.exception. name="user_is_not_member">  
	<t>You are not a Member.</t>                                 
</n.exception.>
You can add it at the place I did here.
My test forum.
Reply | Threaded
Open this post in threaded view
|

Re: Validate Registration

Coleen_Astalos
I'm getting this error when trying to save the handle_registration_errors macro:

Error: macro or method for 'is_submitted_form' not found in [basic, nabble, ad] stack = [basic, nabble, ad]
 in is_submitted_form(custom_tweak:handle_registration_errors:2) - <n.if.is_submitted_form>
 in if(custom_tweak:handle_registration_errors:2) - <n.if.is_submitted_form> - public static void nabble.naml.namespaces.BasicNamespace._if(nabble.naml.compiler.IPrintWriter,nabble.naml.compiler.Interpreter)
 in (custom_tweak:handle_registration_errors:1) - <override_macro name="handle_registration_errors">

I noticed it's not liking the is_submitted_form which is nothing I've changed.  So I completely removed the macro changes and then just go in to Edit the macro, change nothing and save and get the same error.

Coleen
Reply | Threaded
Open this post in threaded view
|

Re: Validate Registration

Pedro
I made the changes for you.
My test forum.
Reply | Threaded
Open this post in threaded view
|

Re: Validate Registration

Coleen_Astalos
Thanks.  Tested, works great!
Coleen