Пример #1
0
        public ActionResult LoginVenture(FormCollection frmCollection)
        {
            Debug.WriteLine("* * * AccountController.Venture LoginVenture  * * *");

            try
            {
                UAS.DataDTO.LoginInfo loginInfo = new UAS.DataDTO.LoginInfo();
                loginInfo.RememberMe = false;

                CookieData cookieData = UAS.Business.HttpFunctions.GetUserCookie();
                if (cookieData.LoginID != null)
                {
                    loginInfo.LoginID    = cookieData.LoginID;
                    loginInfo.RememberMe = true;
                }

                // * * * Need to use Cookie data if available.
                loginInfo.LoginID  = frmCollection["userName"];
                loginInfo.Password = frmCollection["pwrd"];

                LoginStatus loginStatus = null;
                loginStatus = LoginVentureLogic(loginInfo);
                Debug.WriteLine("* * * AccountController LoginVenture  next * * *");

                string userName = String.Empty;
                if (loginStatus != null)
                {
                    Debug.WriteLine("LoginStatus ErrorMessage: " + loginStatus.ErrorMessage);
                    Debug.WriteLine("LoginStatus Status: " + loginStatus.Status);
                    userName = loginStatus.FirstName + " " + loginStatus.LastName;
                    Debug.WriteLine("LoginStatus Name: " + userName);
                    // Debug.WriteLine("LoginStatus Permissions: " + loginStatus.PermissionSet);
                }
                else
                {
                    Debug.WriteLine("loginStatus is NULL !!!");
                    throw new Exception("Invalid username or password.");
                }

                loginInfo.SessionData = Session.SessionID;

                if ((loginStatus.Status == 'A') &&
                    (loginStatus.UserID > 0) &&
                    // !string.IsNullOrEmpty(loginStatus.PermissionSet)
                    (loginStatus.appGroupPermissions.Count > 0)
                    )
                {
                    loginInfo.IsLoggedIn         = true;
                    SessionHelper.IsUserLoggedIn = true;
                    SessionHelper.LoginInfo      = loginInfo;
                    SessionHelper.LoginStatus    = loginStatus;
                }

                if (loginInfo.IsLoggedIn)
                {
                    SessionHelper.SessionTotalTimeoutMinutes = Business.Timeout.GetTotalTimeoutMinutes(SessionHelper.LoginStatus.EnterpriseID);
                    // return RedirectToAction("Index", "Home");
                    SessionHelper.Write("justLoggedIn", true);
                    Assessments assmnts = new Assessments(formsRepo);
                    assmnts.DeleteOldUploadedAssessments();

                    if (SessionHelper.Read <bool>("NoServer") == true)
                    {
                        return(RedirectToAction("Index", "Search"));
                    }
                    return(RedirectToAction("Index", "DataSync"));
                }

                SessionHelper.IsUserLoggedIn = false;
                ViewBag.ErrorMessage         = loginStatus.ErrorMessage;
            }
            catch (Exception xcptn)
            {
                Debug.WriteLine("LoginVenture exception: " + xcptn.Message);
                ViewBag.ErrorMessage = xcptn.Message;
            }

            return(View("loginVenture"));
        }
Пример #2
0
        public ActionResult SsoLogin(string sessionId = "", string appId = "")
        {
            string portalSessionId = sessionId;

            // Portal Session is saved to be used when using SSO to SecureEmail or other systems that use UAS SSO
            SessionHelper.PortalSession = sessionId;

            string ipAddress    = UtilityFunction.GetUserIPAddress();
            string appSessionId = Session.SessionID;

            int applicationId = UAS.Business.Constants.APPLICATIONID;    // Get the Default Application Id (probably SIS or ADAP)

            try
            {
                if (String.IsNullOrEmpty(appId))
                {
                    appId = "3";        // Default to ADAP - this should proabably be deleted.
                }
                applicationId = Convert.ToInt32(appId);
            }
            catch (Exception excpt)
            {
                Debug.WriteLine("SsoLogin - failed getting applicationId: " + excpt.Message);
                // think DEF (Assmnts) has a specific Error screen that should be used.
                ViewBag.ErrorMessage = "Request.Cookies error: " + excpt.Message;
                return(View("loginSIS"));
            }

            AuthenticationClient webclient = new AuthenticationClient();

            string authResult = string.Empty;

            try
            {
                authResult = webclient.SsoLogin(portalSessionId, ipAddress, applicationId, appSessionId);

                Debug.WriteLine("SsoLogin XML result: " + authResult);
            }
            catch (Exception excptn)
            {
                authResult = "<record><errormessage>" + excptn.Message + "</errormessage></record>";
                Debug.WriteLine("SsoLogin webservice exception: " + excptn.Message);
                ViewBag.ErrorMessage = excptn.Message;
                return(View("loginSIS"));
            }

            try
            {
                UAS.DataDTO.LoginStatus loginStatus = ProcessSsoAuth(authResult);

                UAS.DataDTO.LoginInfo loginInfo = FillLoginInfo(loginStatus);

                string userName = String.Empty;
                Debug.WriteLine("LoginStatus ErrorMessage: " + loginStatus.ErrorMessage);
                Debug.WriteLine("LoginStatus Status: " + loginStatus.Status);
                userName = loginStatus.FirstName + " " + loginStatus.LastName;
                Debug.WriteLine("LoginStatus Name: " + userName);


                if ((loginStatus.Status == 'A') &&
                    (loginStatus.UserID > 0) &&
                    (loginStatus.appGroupPermissions.Count > 0)
                    )
                {
                    loginInfo.IsLoggedIn         = true;
                    SessionHelper.IsUserLoggedIn = true;
                    SessionHelper.LoginInfo      = loginInfo;
                    SessionHelper.LoginStatus    = loginStatus;

                    var userContext = webclient.GetUserContextLightweight(loginStatus.EnterpriseID, loginStatus.UserID);
                    if (userContext == null)
                    {
                        throw new Exception(String.Format("Unable to get UserContext for UserId = {0}.", loginStatus.UserID));
                    }
                    SessionHelper.UserSecurityContext = new UserSecurityContext
                    {
                        UserContext = userContext,
                    };

                    string clientUserId = Request["userId"] as string;
                    Session.Add("clientUserId", clientUserId);

                    if (applicationId == 3)
                    {
                        return(RedirectToAction("Index", "Adap"));
                    }
                    return(RedirectToAction("Index", "Search"));
                }

                SessionHelper.IsUserLoggedIn = false;

                ViewBag.ErrorMessage = loginStatus.ErrorMessage;
            }
            catch (Exception xcptn)
            {
                Debug.WriteLine("SsoLogin exception: " + xcptn.Message);
                ViewBag.ErrorMessage = xcptn.Message;
            }

            return(View("loginSIS"));
        }