0

I am using an html form that queries a DB to check security. It is valid for the password to be NULL, but the user should get a warning that the password is blank and that it should be updated.

Every time a page is loaded, I want to warn is the password is NULL.

My question is: where is the best place to do this checking. the layout file is where the message is shown, but I don't think the layout file should be querying the DB.

4

3 回答 3

0

If the intent is to check on every page load, then the onRequestStart() method of your Application.cfc file seems as good a place as any. You would need some conditional logic so that the check doesn't start taking place until after the person has logged in, but that's rather simple.

Also, you can use a session variable to indicate if the person has a password. You don't have to query the db each time.

于 2013-03-31T02:47:53.417 回答
0

FW/1 has a method named setUpRequest(), which functions similarly to onRequestStart().

You could use setUpRequest() to make calls to a controller that checks is password is NULL and adds a message to the request context (rc), that would then be available in all your controller and view code later in the request. Here is some sample code from an app I am working on. You could easily put your check for a password in the default method of the setup controller.

function setupRequest( rc ) {
    if( structkeyExists( url, "reload" ) ){
        setupApplication();
    }
    controller( 'setup.default' );
}
于 2013-04-01T12:17:40.150 回答
-1

Onrequeststart as suggested. Another tip is to create an array of structs where you store all notifications or alerts and other info such as alert type or state etc, then in your view you loop over that array and display all notifications to use. If there are any alerts which should affect a business logic decision then you can also loop over this array elsewhere in your mvc.

于 2013-03-31T14:24:29.877 回答