예제 #1
0
        public UserLogin GetUserLogin()
        {
            MembershipUser loginUser = Membership.GetUser();
            UserLogin settings = new UserLogin();
            if (loginUser != null)
            {
                settings.UserName = loginUser.UserName;
                settings.UserUserId = Utilities.ToGuid(loginUser.ProviderUserKey);
                //settings.UserSiteId = SiteMethods.GetSiteIdForEmployee(settings.UserUserId);
                //settings.UserLicenseKeys = General.ListLicenseKeyByUserId(settings.UserUserId);

                OrganisationSettings orgSetting = new OrganisationSettings();
                settings.UserOrganisationId = Convert.ToInt32(orgSetting.OrganisationId);

                settings.UserOrganisation = ApartmentMethods.GetOrganisation(settings.UserOrganisationId);
                //settings.UserSite = settings.UserSiteId.HasValue ? SiteMethods.GetSite(settings.UserSiteId.Value) : null;


                //settings.ActiveModules = Role.ListActiveModules();
                settings.AspUser = GetAspUser(settings.UserUserId);
                //settings.UserEmployeeId = EmployeeMethods.GetEmployeeId(settings.UserUserId);

                settings.RoleComponentPermissions = ApartmentMethods.ListRoleComponentPermissionByUser(settings.UserUserId);
                if (!settings.AspUser.OrganisationId.HasValue)
                {
                    settings.UserRoleAuths = ApartmentMethods.ListUserRoleAuth(null, settings.UserUserId, null);
                }
                else
                {
                    settings.UserRoleAuths = ApartmentMethods.ListUserRoleAuth(settings.UserOrganisationId, settings.UserUserId, null);
                }

                if (settings.UserSite == null && settings.UserRoleAuths != null && settings.UserRoleAuths.Count > 0
                    && settings.UserRoleAuths.Count(i => i.SiteId.HasValue) > 0)
                {
                    settings.UserSiteId = settings.UserRoleAuths.FirstOrDefault(i => i.SiteId.HasValue).SiteId.Value;
                    List<Site> sites = ApartmentMethods.ListSite(null, settings.UserSiteId.Value, true, false);
                    if (sites.Count > 0)
                    {
                        settings.UserSite = sites[0];
                    }
                }
            }
            return settings;
        }
예제 #2
0
 // If we're using the combo, put combo value into the original username textbox so normal processing can occur
 private void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
 {
     Login1.UserName = _userNameCombo.AllowCustomText && _userNameCombo.Value == string.Empty ? _userNameCombo.Text : _userNameCombo.Value;
     MembershipUser userInfo = Membership.GetUser(Login1.UserName);
     if (userInfo != null)
     {
         OrganisationSettings settings = new OrganisationSettings();
         List<AspUser> aspUserList = ApartmentMethods.ListAspUser(null, (Guid)userInfo.ProviderUserKey, null);
         if (aspUserList == null || aspUserList.Count == 0 
             || (aspUserList[0].OrganisationId.HasValue && aspUserList[0].OrganisationId != Convert.ToInt32(settings.OrganisationId)))
         {
             this.ExtraErrorInformation.Text = Properties.Resources.UserLoginWrongOrg;
             e.Cancel = true;
         }
     }
     Response.Cookies["ActiveModule"].Value = string.Empty;
 }
예제 #3
0
        private List<string> ListMatchingUserName(string startsWith)
        {
            // To avoid lots of SQL calls here, we try to make use of caching as best we can

            // 1. Have we got a cached Dictionary to check yet?
            Dictionary<string, List<string>> dictionary = Cache[Globals.CacheKeys.UserNameDictionaryCacheEntry] as Dictionary<string, List<string>>;

            if (null == dictionary) // Create one            
                dictionary = new Dictionary<string, List<string>>();

            // 2. Do we have an entry in the dictionary already or do we have to fetch and store?
            List<string> resultList = null;

            if (dictionary.ContainsKey(startsWith))
            {
                resultList = dictionary[startsWith];
            }
            else
            {
                int? orgId = null;
                OrganisationSettings settings = new OrganisationSettings();
                if(!string.IsNullOrEmpty(settings.OrganisationId)) 
                    orgId = Convert.ToInt32(settings.OrganisationId);

                resultList = ApartmentMethods.ListUserName(Membership.ApplicationName, orgId, startsWith);
                dictionary.Add(startsWith, resultList);
                Cache[Globals.CacheKeys.UserNameDictionaryCacheEntry] = dictionary;
            }

            return resultList;
        }
예제 #4
0
        /// <summary>
        /// Validates if the authorisation code as passed is the code for any organisation in the db
        /// or is the special non-organisation high level portal admin password as defined in web.config
        /// </summary>
        /// <param name="authorisationCode">User entered authorisation code.</param>
        /// <returns>An OrganisationSettings with IsValid=true where authcode/password valid.
        /// Else an OrganisationSettings with IsValid=false.
        /// </returns>
        public static OrganisationSettings Validate(string authorisationCode)
        {
            OrganisationSettings result = null;

            // Portal Admins gain access to the login controls by entering config code in org authorisation code.
            // All other users need to have an organisation cookie set before logging in.
            if (authorisationCode == _portalAdminOrgCode)
            {
                result = new OrganisationSettings(true, _portalAdminDisplay, _portalAdminDisplay);
                result.Save();
            }
            else
            {
                Organisation org = ApartmentMethods.GetOrganisation(authorisationCode);
                if (null != org)
                {
                    result = new OrganisationSettings(false, org.NullableRecordId.ToString(), org.Name);
                    result.Save();
                }
            }

            return result;
        }