TROIKA.ASP - the MVC framework

LoginAction.js

Summary

Contains LoginAction class.

This is part of Troika.ASP Framework - web development MVC framework for ASP 3.0. Please visit www.troika-asp.com for more details.



Version: $Revision: 1.3 $

Author: Pavel Chuchev pav@troika-asp.com


Class Summary
LoginAction This is HelloAction class command implementation.

/**
* @fileoverview Contains <tt>LoginAction</tt> class.
*
* <p>
* This is part of Troika.ASP Framework - web development MVC framework for ASP 3.0.
* Please visit {@link http://www.troika-asp.com www.troika-asp.com} for more details.
* </p>
*
* @author Pavel Chuchev pav@troika-asp.com
* @version $Revision: 1.3 $
*/
LoginAction.prototype =  new Command();
LoginAction.prototype.constructor = LoginAction;
/**
* Initializes <tt>LoginAction</tt>.
*
* @return <tt>LoginAction</tt> object instance itself.
* @param {Config} config The instance of <tt>Config</tt> class
* @type LoginAction
*/
LoginAction.prototype.init = function (config) {

    Command.prototype.init.call(this, config);
    return this;
};

/**
* Constructs a new LoginAction class.
*
* @class This is <tt>HelloAction</tt> class command implementation.
*
* @constructor
* @base Command
* @param {Config} config The instance of Config class.
*/
function LoginAction(config) {

    if (arguments.length) {

        this.init(config);
    }

    /**
    * Logs into the the database using username/password. Returns to error page is user not found.
    *
    * @param {Environment} environment The instance of <tt>Environment</tt> class.
    * @param {LoginForm} loginForm The instance of <tt>LoginForm</tt> class - RequestContext.
    * @return The instance of <tt>ResponseContext</tt> class
    * @type ResponseContext
    */
    this.execute = function (environment, loginForm) {

        var result =  new ResponseContext();

        if (environment.request.get("submit")) {

            var errors = loginForm.validate();
            if (errors.size()) {

                result.errors.addAll(errors);
                result.forward = this.findForward(loginForm, "login-form");
            }
            else {

                var dao =  new LoginDAO(this.getConnectionString("helloworld-db"));
                var vo = dao.findByUsernameAndPassword(loginForm.userName, loginForm.password);

                if (vo) {

                    environment.session.put("security.role", vo.securityRole);
                    environment.session.put("loginId", vo.loginId);
                    environment.session.put("memberId", vo.memberId);

                    result.forward = this.getNextPageForward(environment, loginForm, vo);
                }
                else {

                    this.error("Could not log you in please try again.", loginForm, result, environment);
                }
            }
        }
        else {

            result.forward = this.findForward(loginForm, "login-form");
        }

        return result;
    };

    /**
    * @private
    */
    this.getNextPageForward = function (environment, loginForm, userVO) {

        var session = environment.session;
        var nextPage = session.get("nextPageForward");

        var result = undefined;

        if (nextPage) {

            session.remove("nextPageForward");
            result =  new Forward(true, nextPage);
        }
        else {

            result = this.findForward(loginForm, "success");
        }

        return result;
    };

    /**
    * @private
    */
    this.error = function (msg, loginForm, responseCxt) {

        responseCxt.errors.add(new Error(msg));
        responseCxt.forward = this.findForward(loginForm, "login-form");
    };
}

TROIKA.ASP - the MVC framework

www.troika-asp.com
Documentation generated on Sun Jun 15 17:59:32 2008