Announcement Announcement Module
Collapse
No announcement yet.
Validatiting User data Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Validatiting User data

    Hi,
    I had a login form and want to forward to a success view once the user is valid. I wrote one class for data access. But where i can compare those values from the database with the values entered in login page.
    Please help me....

  • #2
    Hi there,

    I would do all the comparison work in a LoginValidator class which can make calls to your data-access objects. The call need not return something as plain as a boolean, how about something like a LoginAudit object which contains the user object, if username was found, and various other values (boolean - password matched, int - login failures, date - last login?, etc).

    You can then pass meaningful error messages back to your login form if the login fails.

    The onSubmit(...) may then become a very small method, but can initialise any objects required for the success-view, in all likelihood the user's homepage.

    Mike

    Comment


    • #3
      I've been doing database access in the onBindAndValidate() method in the controller object rather than the validator class. I'm not sure which method is preferrable?

      Comment


      • #4
        Originally posted by Seabamirum
        I've been doing database access in the onBindAndValidate() method in the controller object rather than the validator class. I'm not sure which method is preferrable?
        Generally, I like to put as much validation logic as I can into the Validator class. This encapsulates it better and makes it more reusable.

        However, obviously the Validator interface isn't aware of the HttpServletRequest, which sometimes you need. In that case, you can call a method on the validator passing in the request from onBindAndValidate().

        Good rule is to delegate all validation logic to a Validator, even from onBindAndValidate(). It's just not reusable inside that method.

        Comment

        Working...
        X