<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.7.2" -->
<rss version="2.0">
    <channel>
        <title>registration_form[ Search for &quot;&quot;]</title>
        <description></description>
        <link>http://xataface.com/wiki/index.php?-action=single_record_search&amp;-table=wiki&amp;page_id=%3D98&amp;-cursor=0&amp;-skip=0&amp;-limit=30&amp;-mode=list&amp;--subsearch=</link>
        <lastBuildDate>Wed, 22 May 2013 01:32:46 +0100</lastBuildDate>
        <generator>FeedCreator 1.7.2</generator>
        <item>
            <title>registration_form</title>
            <link>http://www.xataface.com/wiki/registration_form</link>
            <description>&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Field&lt;/th&gt;&lt;th&gt;Value&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page name&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;registration_form&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page id&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;98&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page title&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;Setting up User Registration&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Content&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;&lt;table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;&lt;tr&gt;&lt;td&gt;
&lt;div id=&quot;toc&quot;&gt;&lt;strong&gt;Table of Contents&lt;/strong&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc0&quot;&gt;Synopsis&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc1&quot;&gt;Enabling Registration&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc2&quot;&gt;Setting up Permissions to Support Registration&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 2em;&quot;&gt;&lt;a href=&quot;#toc3&quot;&gt;Sample Permissions on Users Table&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 2em;&quot;&gt;&lt;a href=&quot;#toc4&quot;&gt;Restricting Permissions on Particular Fields&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc5&quot;&gt;Email Validation&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 2em;&quot;&gt;&lt;a href=&quot;#toc6&quot;&gt;Disabling Email Validation&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc7&quot;&gt;Triggers: Overriding Registration Workflow&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc8&quot;&gt;Preventing Spam with CAPTCHA&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;


&lt;h3 id=&quot;toc0&quot;&gt;Synopsis&lt;/h3&gt;
&lt;p&gt;Xataface optionally enables you to allow users to register for an account in your application.  If your &lt;em&gt;users&lt;/em&gt; table includes a column for email, it will also perform email validation before the account is activated.  Before tackling user registration, it is good to have an understanding of Xataface's &lt;a href=&quot;/wiki/authentication&quot;&gt;authentication&lt;/a&gt; and &lt;a href=&quot;http://xataface.com/documentation/tutorial/getting_started/permissions&quot; onclick=&quot;window.open(this.href, '_blank'); return false;&quot;&gt;permissions&lt;/a&gt; faculties.&lt;/p&gt;


&lt;h3 id=&quot;toc1&quot;&gt;Enabling Registration&lt;/h3&gt;
&lt;p&gt;To enable registration, simply add the following to the &lt;em&gt;&lt;a href=&quot;/wiki/_auth&quot;&gt;_auth&lt;/a&gt;&lt;/em&gt; section of the &lt;a href=&quot;/wiki/conf.ini_file&quot;&gt;conf.ini file&lt;/a&gt;:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;allow_register=1&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;e.g. after adding this, your &lt;em&gt;&lt;a href=&quot;/wiki/_auth&quot;&gt;_auth&lt;/a&gt;&lt;/em&gt; section might look like:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;[_auth]
     users_table=users
     username_column=username
     password_column=password
     allow_register=1&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;After doing this, you'll notice a little &lt;em&gt;Register&lt;/em&gt; link below the login form.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://media.weblite.ca/files/photos/Picture%2036.png?max_width=640&quot; alt=&quot;http://media.weblite.ca/files/photos/Picture%2036.png?max_width=640&quot; width=&quot;640&quot; height=&quot;160&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Clicking on this link will produce a registration form for the user which is essentially a &amp;quot;New Record&amp;quot; form on your &lt;em&gt;users&lt;/em&gt; table.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://media.weblite.ca/files/photos/Picture%2037.png?max_width=640&quot; alt=&quot;http://media.weblite.ca/files/photos/Picture%2037.png?max_width=640&quot; width=&quot;640&quot; height=&quot;194&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Some features of this registration form include:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt; Checks to ensure that the username is unique&lt;/li&gt;
    &lt;li&gt; If the users table contains an &lt;em&gt;email&lt;/em&gt; field, it will use the user-entered address for email validation before activation is complete.&lt;/li&gt;
&lt;/ul&gt;


&lt;h3 id=&quot;toc2&quot;&gt;Setting up Permissions to Support Registration&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Xataface &amp;lt;= 1.2.4&lt;/strong&gt;:   You must ensure that unlogged-in users have permission to add new records to the &lt;em&gt;users&lt;/em&gt; table.  This means that your getPermissions() method on the users table should, at least, provide the &lt;em&gt;new&lt;/em&gt; permission.  In addition these users must be granted the &lt;em&gt;register&lt;/em&gt; permission in order to be able to register to begin with.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Xataface &amp;gt;= 1.2.5&lt;/strong&gt;:  You no longer need to provide the &lt;em&gt;new&lt;/em&gt; permission to allow users to register.  You simply need to provide the &lt;em&gt;register&lt;/em&gt; permission.&lt;/p&gt;


&lt;h4 id=&quot;toc3&quot;&gt;Sample Permissions on Users Table&lt;/h4&gt;
&lt;p&gt;In the tables/users/users.php file (assuming my &lt;em&gt;users&lt;/em&gt; table is actually named &amp;quot;users&amp;quot;)&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;class tables_users {

    function getPermissions($record){
        if ( isAdmin() ) return null;
        $perms['register'] = 1;
        return $perms;
     
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Note that this example is only applicable for Xataface &lt;a href=&quot;http://1.2.5&quot; onclick=&quot;window.open(this.href, '_blank'); return false;&quot;&gt;1.2.5&lt;/a&gt; or higher.  In Xataface &lt;a href=&quot;http://1.2.4&quot; onclick=&quot;window.open(this.href, '_blank'); return false;&quot;&gt;1.2.4&lt;/a&gt; you needed to provide users with the ''new'' permission rather than the ''register'' permission, which opens up a small security hole since users could potentially just use the &amp;quot;new&amp;quot; action if they new the URL and by-pass the registration and activation email altogether&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Some notes on this example:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt; The isAdmin() function is not part of Xataface.  It is used as a bit of *magic* here to reduce code.  It is supposed to simply return true if the currently logged in user is an admin.  Hence if the user is an admin, this method defers to the Application Delegate class's permissions (i.e. this method should not affect administrators).&lt;/li&gt;
    &lt;li&gt; We are giving all users (logged in or not) the register permission which enables them to register for an account on the system.&lt;/li&gt;
    &lt;li&gt; Generally you will want to restrict permissions on some of the fields in the users table.  E.g. users should not be able to set their role or access level when they register.  You can define more fine-grained permissions on these fields using the &lt;a href=&quot;/wiki/fieldname__permissions&quot;&gt;fieldname__permissions&lt;/a&gt; method of the users table delegate class (per the following example).&lt;/li&gt;
&lt;/ul&gt;


&lt;h4 id=&quot;toc4&quot;&gt;Restricting Permissions on Particular Fields&lt;/h4&gt;
&lt;p&gt;You probably don't want users to be able to set their access level when the register for an account, and your &amp;quot;users&amp;quot; table will quite often contain some field like &amp;quot;role&amp;quot; which stores this information.  So the previous example is not quite realistic.  You will also need to restrict permissions on the &amp;quot;role&amp;quot; field (and any other fields that you want to prevent users from setting themselves.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;function role__permissions(&amp;amp;$record){
    if ( isAdmin() ) return null;
    return Dataface_PermissionsTool::NO_ACCESS();
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will cut off the user's ability to set their own role when they register.  You will likely want to set the default role value either in the mysql table definition or in the beforeInsert&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=beforeInsert&quot;&gt;?&lt;/a&gt; trigger.&lt;/p&gt;


&lt;h3 id=&quot;toc5&quot;&gt;Email Validation&lt;/h3&gt;
&lt;p&gt;As mentioned above, registration works by sending an activation email to the address specified in the user's registration.  This email contains a link back to the &lt;em&gt;activate&lt;/em&gt; action of your Xataface application, which will create the user account and log the user in.  This implies that your &lt;em&gt;users&lt;/em&gt; table must store an email address for your users.  If you add a field named &lt;em&gt;email&lt;/em&gt; to the &lt;em&gt;users&lt;/em&gt; table, Xataface will assume that you mean to use this field as the user's email address, and thus, for email validation.  However you can override this functionality and use *any* field as an email field by setting the &lt;em&gt;email&lt;/em&gt; directive of the appropriate field in the &lt;a href=&quot;/wiki/fields.ini_file&quot;&gt;fields.ini file&lt;/a&gt; for the &lt;em&gt;users&lt;/em&gt; table.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Assigning the my_addr field of the users table to be used for email validation&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;In the tables/users/fields.ini file: 
&lt;pre&gt;&lt;code&gt;[my_addr]
    email=1&lt;/code&gt;&lt;/pre&gt;

&lt;/p&gt;


&lt;h4 id=&quot;toc6&quot;&gt;Disabling Email Validation&lt;/h4&gt;
&lt;p&gt;99% of the time, email validation is the preferred way of ensuring that people who register are who they say they are.  You may, however, prefer to let users register directly without requiring the email activation step.  You can disable email validation by overriding the &lt;em&gt;register&lt;/em&gt; action in the &lt;a href=&quot;/wiki/actions.ini_file&quot;&gt;actions.ini file&lt;/a&gt; as follows:&lt;/p&gt;

&lt;p&gt;In your application's &lt;a href=&quot;/wiki/actions.ini_file&quot;&gt;actions.ini file&lt;/a&gt;: 
&lt;pre&gt;&lt;code&gt;[register &amp;gt; register]
    email_validation=0&lt;/code&gt;&lt;/pre&gt;

&lt;/p&gt;

&lt;p&gt;After setting this, the user account will automatically be created, and the user logged in upon saving the registration form.&lt;/p&gt;


&lt;h3 id=&quot;toc7&quot;&gt;Triggers: Overriding Registration Workflow&lt;/h3&gt;
&lt;p&gt;Xataface provides a number of triggers in the &lt;a href=&quot;/wiki/Application_Delegate_Class&quot;&gt;Application Delegate Class&lt;/a&gt; to override and extend the behavior of the user registration and activation process.  For a list of available triggers see &lt;a href=&quot;/wiki/Application_Delegate_Class%23registration&quot;&gt;Application Delegate Class&lt;/a&gt;.&lt;/p&gt;


&lt;h3 id=&quot;toc8&quot;&gt;Preventing Spam with CAPTCHA&lt;/h3&gt;
&lt;p&gt;One problem with enabling automatic registration is that it invites SPAM in the form of bots that can learn how to automatically register for user accounts and then leave unwanted input into your application.  The Xataface &lt;a href=&quot;/wiki/reCAPTCHA_module&quot;&gt;reCAPTCHA module&lt;/a&gt; allows you to avoid these problems to some extent by forcing users who aren't logged in to fill a CAPTCHA field in order to successfully submit the form.  This is especially helpful for registration forms.&lt;/p&gt;

&lt;p&gt;After installing the &lt;a href=&quot;/wiki/reCAPTCHA_module&quot;&gt;reCAPTCHA module&lt;/a&gt; the registration form will include a CAPTCHA field like the one depicted below:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://media.weblite.ca/files/photos/Picture%2038.png?max_width=640&quot; alt=&quot;http://media.weblite.ca/files/photos/Picture%2038.png?max_width=640&quot; width=&quot;640&quot; height=&quot;298&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For more information about the reCAPTCHA module &lt;a href=&quot;/wiki/reCAPTCHA_module&quot;&gt;click here&lt;/a&gt;.&lt;/p&gt;

&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Keywords&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;registration form, _auth, authentication&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Language&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;en&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;</description>
            <author>registration_form</author>
        </item>
    </channel>
</rss>
