gov.va.medora.mdws.AccountLib.login C# (CSharp) Method

login() public method

Log onto a data source.
Combines authentication and authorization into a single function. It will create a new set of session credentials and a primary permission. These credentials can then be used for subsequent visits. Login requires a previous connection.
public login ( string accountId, string accountPwd, string permissionString ) : UserTO
accountId string Access code
accountPwd string Verify code
permissionString string If blank defaults to CPRS context
return gov.va.medora.mdws.dto.UserTO
        public UserTO login(string accountId, string accountPwd, string permissionString)
        {
            UserTO result = new UserTO();

            if (!mySession.HasBaseConnection)
            {
                result.fault = new FaultTO("There is no connection to log onto");
            }
            else if (accountId == "")
            {
                result.fault = new FaultTO("Missing account ID");
            }
            else if (accountPwd == "")
            {
                result.fault = new FaultTO("Missing account password");
            }
            if (result.fault != null)
            {
                return result;
            }

            try
            {
                AbstractConnection c = mySession.ConnectionSet.BaseConnection;

                AbstractCredentials credentials = AbstractCredentials.getCredentialsForCxn(c);
                credentials.AccountName = accountId;
                credentials.AccountPassword = accountPwd;

                c.Account.AuthenticationMethod = MdwsConstants.LOGIN_CREDENTIALS;

                if (String.IsNullOrEmpty(permissionString))
                {
                    permissionString = MdwsConstants.CPRS_CONTEXT;
                }
                mySession.PrimaryPermission = new MenuOption(permissionString);

                mySession.User = c.Account.authenticateAndAuthorize(credentials, mySession.PrimaryPermission);

                mySession.Credentials = credentials;

                result = new UserTO(mySession.User);
            }
            catch (Exception e)
            {
                result.fault = new FaultTO(e.Message);
            }
            return result;
        }