Iliad Framework, the registration form (part 2)

In the previous post we build a registration form and in this one we will attach it to our application.

We start adding an instance variable to our application to contain the registration widget and another instance variable to contain the current user:

<span class="nc">ILApplication</span> <span class="nf">subclass:</span> <span class="ss">#LcBlogProjectNotes</span>
    <span class="nf">instanceVariableNames:</span> <span class="s">'loginWidget registrationWidget currentuser'</span>
    <span class="nf">classVariableNames:</span> <span class="s">''</span>
    <span class="nf">poolDictionaries:</span> <span class="s">''</span>
    <span class="nf">category:</span> <span class="s">'LeonardoBlog'</span>

As we have done for the loginWidget, we create an accessor method that will construct the widget if it hasn’t been instanciated:

<span class="k">!</span><span class="nc">LcBlogProjectNotes</span><span class="k"> methodsFor: </span><span class="s">'accessing'</span><span class="k">!</span>
<span class="nf">registrationWidget</span>
    <span class="o">^</span> <span class="nv">registrationWidget</span> <span class="nf">ifNil:</span> [ <span class="nv">registrationWidget</span> <span class="o">:=</span> <span class="nc">PnCreateUser</span> <span class="nb">new</span> ]

We also create accessors for the current user instance variable:

<span class="k">!</span><span class="nc">LcBlogProjectNotes</span><span class="k"> methodsFor: </span><span class="s">'accessing'</span><span class="k">!</span>
<span class="nf">currentuser:</span> <span class="nv">anObject</span>
    <span class="nv">currentuser</span> <span class="o">:=</span> <span class="nv">anObject</span>

<span class="nf">!</span><span class="nc">LcBlogProjectNotes</span> <span class="nf">methodsFor:</span> <span class="s">'accessing'</span><span class="nf">!</span>
<span class="nf">currentuser</span>
    <span class="o">^</span> <span class="nv">currentuser</span>

Now we create a controller for the registration page:

<span class="k">!</span><span class="nc">LcBlogProjectNotes</span><span class="k"> methodsFor: </span><span class="s">'controllers'</span><span class="k">!</span>
<span class="nf">register</span>
    <span class="o">^</span> [ <span class="o">:</span><span class="nv">e</span> <span class="o">|</span> <span class="nv">e</span> <span class="nf">div</span> <span class="nf">class:</span><span class="s">'container'</span><span class="p">;</span> <span class="nf">build:</span> <span class="bp">self</span> <span class="nf">registrationWidget</span> ]

Now we have our new controller and we can test it from the login page. The controller name, register, match with the href in the login page.