/// <summary> /// Determines if the user is a technician /// </summary> public static bool IsUserTechnician(string username) { //set if they are a tech right off the bat var settingsFactory = new SettingsFactory(); int userId = (new UserFactory()).GetUserId(username); var isTech = settingsFactory.Get(userId, Constants.User.IsTechnician); bool isTECH = false; if (isTech != null) { bool.TryParse(isTech.Value, out isTECH); } return(isTECH); }
/// <summary> /// Updates a user's profile /// </summary> public void UpdateUserProfile(UserModel model, bool isActive) { var profile = RbacEntities.UserProfiles.FirstOrDefault(u => u.UserName == model.Username); if (profile == null) { return; } profile.FirstName = model.FirstName; profile.LastName = model.LastName; profile.MiddleName = model.MiddleInitial; profile.Email = model.EmailAddress; profile.Phone = model.PhoneNumber; profile.Membership.IsActive = isActive; RbacEntities.SaveChanges(); //now set the settings that arent a part of the profile(company name, secondary type id and value, etc int userID = GetUserId(model.Username); var settingsFactory = new SettingsFactory(); settingsFactory.Set(userID, Constants.User.OrganizaitonNameField, model.OrganizationName); settingsFactory.Set(userID, Constants.User.SecondaryIDType, model.SecondaryIDType); settingsFactory.Set(userID, Constants.User.SecondaryIDValue, model.SecondaryIDValue); }
/// <summary> /// Gets a users profile /// </summary> public ProfileModel GetProfileModel(string username, PemsCity CurrentCity) { //populate the fields from the database var profile = RbacEntities.UserProfiles.FirstOrDefault(u => u.UserName == username); if (profile != null) { var model = new ProfileModel { Groups = (new RoleFactory()).GetGroups(username, CurrentCity), Username = username, EmailAddress = profile.Email, MiddleInitial = profile.MiddleName, FirstName = profile.FirstName, LastName = profile.LastName, PhoneNumber = profile.Phone, Active = false }; //update memebership information if (profile.Membership != null) { model.Active = profile.Membership.IsActive.HasValue && profile.Membership.IsActive.Value; model.BadLoginCount = profile.Membership.PasswordFailuresSinceLastSuccess; model.CreationDate = profile.Membership.CreateDate.HasValue ? profile.Membership.CreateDate.Value : DateTime.MinValue; model.LastLoginFailure = profile.Membership.LastPasswordFailureDate.HasValue ? profile.Membership.LastPasswordFailureDate.Value : DateTime.MinValue; model.LastPasswordChangeDate = profile.Membership.PasswordChangedDate.HasValue ? profile.Membership.PasswordChangedDate.Value : DateTime.MinValue; int daysPwValidFor; var validForConfig = ConfigurationManager.AppSettings["DaysPWValidFor"]; int.TryParse(validForConfig, out daysPwValidFor); if (daysPwValidFor == 0) { daysPwValidFor = 90; } model.PasswordExipration = profile.Membership.PasswordChangedDate != null?profile.Membership.PasswordChangedDate.Value.AddDays(daysPwValidFor) : DateTime.Now; } //role model.Role = SecurityMgr.GetGroupForUser(CurrentCity, model.Username); //status model.Status = GetStatus(model.Active, model.Username); //user settings var settingsFactory = new SettingsFactory(); var lastLogin = settingsFactory.GetValue(profile.UserId, Constants.User.LastLoginTime); model.LastLoginDate = lastLogin != null?Convert.ToDateTime(lastLogin) : DateTime.MinValue; var orgName = settingsFactory.GetValue(profile.UserId, Constants.User.OrganizaitonNameField); model.OrganizationName = orgName ?? string.Empty; var secType = settingsFactory.GetValue(profile.UserId, Constants.User.SecondaryIDType); model.SecondaryIDType = secType ?? string.Empty; var secValue = settingsFactory.GetValue(profile.UserId, Constants.User.SecondaryIDValue); model.SecondaryIDValue = secValue ?? string.Empty; //is technician var isTech = settingsFactory.GetValue(profile.UserId, Constants.User.IsTechnician); model.IsTechnician = isTech != null && Convert.ToBoolean(isTech); //var techID = settingsFactory.GetValue(profile.UserId, Constants.User.TechnicianId); //model.TechnicianId = techID != null ? Convert.ToInt32(techID) : -1; //then fill in all the profile specific stuff var passwordManager = new PasswordManager(username); model.PasswordResetRequired = RequiresPasswordReset(username); List <PasswordQuestion> questions = passwordManager.GetQuestions(); model.Question1 = questions.Count > 0 ? questions[0] : new PasswordQuestion(1); model.Question2 = questions.Count > 1 ? questions[1] : new PasswordQuestion(2); // Set in a dummy password model.Password = new ChangePasswordModel(); return(model); } return(null); }