示例#1
0
 private void InitializeSsoSession(string username)
 {
     try
     {
         Session[SessionService.SINGLE_SIGNON_SESSION_TOKEN] = _sessionService.InsertEntryIntoSession(username);
     }
     catch (Exception ex)
     {
         CCLLogger.Log("Unable to initiate the SSO user session.", ex, Guid.NewGuid(), TraceEventType.Error);
     }
 }
示例#2
0
        public void LoginUser()
        {
            BGT.Database.UserManagement objLogin = new BGT.Database.UserManagement();

            CleanSession();

            AgentAcctInfoDto dtUserInfo  = null;
            var    userLogin             = Server.HtmlEncode(txtLogin.Value);
            var    userPasswordEncrypted = Server.HtmlEncode(txtPass.Value.ToLower()).ToSecureString().SymmetricalEncrypt().ToSecureString();
            string userValidation        = objLogin.LoginUser(userLogin, userPasswordEncrypted, out dtUserInfo);

            if ((userValidation ?? string.Empty).ToLower() == "valid")
            {
                #region Agency Restriction check
                GlobalSession.AgencyId = dtUserInfo.AgencyID;

                var agencyRestrictionForDomain = (System.Configuration.ConfigurationManager.
                                                  AppSettings["AgencyRestrictionForDoamin"] ?? string.Empty).ToUpper();

                if (!string.IsNullOrEmpty(agencyRestrictionForDomain) &&
                    HttpContext.Current.Request.Url.Host.ToUpper().Contains(agencyRestrictionForDomain))
                {
                    try
                    {
                        string AgencyAreaCode = dtUserInfo.AgencyPhoneAreaCode;
                        bool   IsvalidAgency  = false;

                        if (AgencyRestrictionNotAllowPhoneAreaCodes.Equals("*"))
                        {
                            // Means allow only AgencyRestrictionAllowPhoneAreaCodes - UK Scenario
                            if (AgencyRestrictionAllowPhoneAreaCodes.Contains(AgencyAreaCode))
                            {
                                IsvalidAgency = true;
                            }
                        }
                        else if (AgencyRestrictionAllowPhoneAreaCodes.Equals("*"))
                        {
                            // Means Allow every one except AgencyRestrictionNotAllowPhoneAreaCodes - US Scenario
                            if (!AgencyRestrictionNotAllowPhoneAreaCodes.Contains(AgencyAreaCode))
                            {
                                IsvalidAgency = true;
                            }
                        }
                        if (!IsvalidAgency)
                        {
                            userValidation = ErrorConstants.INVALID_AGENCY_LOCALITY;
                        }
                    }
                    catch (Exception ex)
                    {
                        string message = ErrorConstants.ERROR_VALIDATING_AGENCY_LOCALITY;
                        Sitecore.Diagnostics.Log.Error(message, ex, this);
                        CCLLogger.Log(message, ex, _myGuid, TraceEventType.Error);
                        userValidation = message;
                    }
                }
                #endregion
            }
            if ((userValidation ?? string.Empty).ToLower() == "valid")
            {
                // Continue with the rest of the validations
                GlobalSession.AgencyId = dtUserInfo.AgencyID;
                string userRole = dtUserInfo.Rights.ToString(CultureInfo.InvariantCulture);
                string loginId  = dtUserInfo.LoginID;
                string fullName = string.Join(" ", new[]
                {
                    dtUserInfo.FirstName,
                    dtUserInfo.LastName
                });
                string AreaCode = dtUserInfo.AreaCode;

                Auth.SetAuthentication(userRole, loginId, fullName);

                // Store Authenticated user info in session
                GlobalSession.UserFullName      = string.Concat(dtUserInfo.FirstName.ToLower(), " ", dtUserInfo.LastName.ToLower());
                GlobalSession.RightsAccessLevel = dtUserInfo.Rights.ToString(CultureInfo.InvariantCulture);
                GlobalSession.AgentProfile      = objLogin.GetAgentByLoginId(loginId);
                GlobalSession.LoginId           = userLogin;

                if (SingleSignonIsEnabled())
                {
                    InitializeSsoSession(userLogin);
                }

                if (!RedirectToReturnUrl())
                {
                    Response.Redirect("/", true);
                }
            }
            else
            {
                LblMessage.Text = userValidation;
                CleanSession();
            }
        }