Making a login form

  • 5 September 2012
  • 4 replies
  • 1 view

Badge +2

I have a smartobject containing the following:


ID (autonumber)


User name


Password


Email.


 


I would like to use that smartobject (probably in a form) to present the user with a login page to enter user id and password. If they match, they are sent to the next form, that will take the ID as a parameter. If they don't match, an error message must be shown.


How can I do this?


I noticed that the Load requires the ID, so I will probably need a way to first GetList, and then check to see if there's a match in that list, and then do <something>.


4 replies

Badge +3

HI elveejay


I managed to get this set up and working on my side, I did however find a bug which I'm not too happy about and which I will log. More on that once I've provided a little more context of the setup though. Please also note that this is not the only way to configure this scenario.


I created a simple SmartBox SmO, very similar to yours, with an [Autonumber] identifier:



I then created x2 Forms, each with the following layouts:


Forms 1 - This Form serves as the "Logon Form" and contains the basic controls which you would expect, including a single hidden control (I used a [DataLabel]):



Form 2 - This Form serves as the "Home Page" to which the browser navigates to upon successful logon. It contains a few fields which I populate with the logged on Users' information (via a SmartObject LOAD method) once the Form Initializes. The method uses a Form Parameter of type Number as its input.



I then configured the following two Rules on the Logon Form, serving as the "User validation":


Rule 1 - This Rule executes the GetList method of the above created SmO:



Note in the InputMapping of the Rule, I provided both the "Username" and "Password" fields as input, as such ensuring that a unique value will be returned each time. In order to avoid duplicate username's in the DB, the "Username" field can be set to "Unique" in the SmartObject Designer. In the OutputMappings I mapped the returned "ID" field to my hidden control residing on the canvas.



Rule 2 - This is the Rule where the actual validation takes place. The Rule will execute once the value of the hidden control is changed. When it is changed, it validates it against an "Advanced Condition". This Condition verifies whether the value of the control is greater than zero, meaning that if true, a valid ID was returned. If the value is not greater than zero, it must be null, indicating that no matching ID was found.


If a matching ID was found, I navigate to the "Home Page", supplying the value of my hidden control as the new value for the Parameter on the "Home Page". If no matching ID was found, I display an appropriate message to the user and I set the value of the hidden control to anything. Note that I change it to any other text value, but I do not leave it empty, or change it to empty (*this is where the bug comes in, but more of that later):



This is how the Condition is configured:



If all goes well, you'll be presented with the following behavior at runtime (open in new tab to view the gif):



 


 


* The bug I mentioned above entails that the "On Change" event of an empty control is not fired, when an empty value is transferred to the control. I.e. the control assumes that since it's previous value was "null", and since the new value is also "null", there was no change. Ideally, the scenario should differ on the following points:


1) Instead of using the "Advanced Condition", you should be able to use simple Condition "A control contains a value"


2) The "Transfer data" Rule Action should not be necessary


Unfortunately when making these two changes, you'll notice at runtime the configured error message only displays the first time validation fails in a new browser session.

Badge +3

On a side note, in order to change the "Password Textbox" to a normal hidden-text type textbox (as would be the case with password type Textboxes), you would have to create a custom control.


This control has been documented however and is available at http://www.help.k2.com under the "Creating a custom control" section.

Badge +2

Thanks for the good answer.


 


Could I get you to attach a package from "K2 Package & Deployment" ?


 


I seem to have problems transferring data to the next form. Also, I tried to make a label that should contain some data from a parameter (as I guess you might be doing), but I can't transfer anything to the label in the Rules section.

Badge +5

I agree, great answer.

Reply