public void SetUserPassword(User user) { if (user.PasswordVersion != CurrentPasswordVersion) throw new ApplicationException(string.Format("Password version of user '{0}' has expired.", user.LoginId)); user.Password = HashHelper.CreateHash<SHA512CryptoServiceProvider>(MixWithSalt(user.Password, user.Salt)); }
public void SetAsDefault(User user, HeadQuarter headQuarter) { if (user == null || headQuarter == null) throw new ArgumentException(string.Format("User {0} or HeadQuater {1} not found!", user.LoginId, headQuarter.Description)); hqRepository.UpdateUserHeadQuarter(user, headQuarter); }
public CreateNewUser(IUserProxy userProxy, User currentUser, UserOperation userOperation) { InitializeComponent(); VM = new CreateUserViewModel(userProxy, currentUser, userOperation); VM.View = this; DataContext = VM; }
/// <summary> /// /// </summary> /// <param name="userProxy"></param> /// <param name="currentUser"></param> /// <param name="userOperation"></param> public CreateUserViewModel(IUserProxy userProxy, User currentUser, UserOperation userOperation) { this.userProxy = userProxy; this.userOperation = userOperation; if (userOperation == UserOperation.Edit) { Title = MergedResources.Common_EditUser; this.currentUser = currentUser; this.LoginIdReadOnly = true; } else if (userOperation == UserOperation.Add) { Title = MergedResources.Common_AddUser; this.currentUser = new User(); this.LoginIdReadOnly = false; } else { this.currentUser = currentUser; this.LoginIdReadOnly = true; } InitializeCollections(this.currentUser); isLanguageChanged = false; IsChanged = false; IsSaved = true; }
public KeyProxy(User user, int? hqId, IConfigManager configManager, ICbrManager cbrManager, IFulfillmentManager fulfillManager, ISubsidiaryManager subsidiaryManager, IHeadQuarterManager headQuarterManager) : base(hqId) { this.user = user; if (configManager == null) this.configManager = new ConfigManager(); else this.configManager = configManager; if (cbrManager == null) this.cbrManager = new CbrManager(); else this.cbrManager = cbrManager; if (fulfillManager == null) this.fulfillManager = new FulfillmentManager(); else this.fulfillManager = fulfillManager; if (subsidiaryManager == null) this.subsidiaryManager = new SubsidiaryManager(); else this.subsidiaryManager = subsidiaryManager; if (headQuarterManager == null) this.headQuarterManager = new HeadQuarterManager(); else this.headQuarterManager = headQuarterManager; }
public List<HeadQuarter> GetHeadQuarters(User user) { using (var context = GetContext()) { return context.UserHeadQuarters.Include("HeadQuarter").Where(m => m.UserId == user.UserId) .ToList().Select(m => m.HeadQuarter).ToList(); } }
public ConfigProxy(User user, IFulfillmentManager fulfillmentManager) { this.user = user; if (fulfillmentManager == null) this.fulfillmentManager = new FulfillmentManager(); else this.fulfillmentManager = fulfillmentManager; }
public void AddUser(User user) { if (user == null) throw new ArgumentNullException("User is null"); TrimInformation(user); if (!ValidateLoginId(user.LoginId, user.UserId)) throw new DisException(Resources.UserProxy_UserAlreadyExist); resolver.SetUserPassword(user); userRepository.InsertUser(user); }
public void ChangeProfile(User user) { if (user == null) throw new ArgumentNullException("User is null"); if (!string.IsNullOrEmpty(user.Password)) resolver.SetUserPassword(user); TrimInformation(user); userRepository.UpdateUser(user); }
public void InsertUser(User user) { using (var context = GetContext()) { InsertUser(user, context); InsertRole(user, context); InsertHeadQuarter(user, context); context.SaveChanges(); } }
public void DeleteUser(User user) { if (user == null) throw new ArgumentNullException("User is null"); if ((user.RoleName == Constants.ManagerRoleName) && userRepository.SearchUsers(null, userRepository.GetRoles().SingleOrDefault(r => r.RoleName == Constants.ManagerRoleName).RoleId).Count <= 1) throw new DisException(Resources.UserProxy_CannotRemoveLastAdmin); userRepository.DeleteUser(user.UserId); }
public bool ValidateUserPassword(User userInDb, string inputPassword, out bool shouldUpdate) { shouldUpdate = (userInDb.PasswordVersion != CurrentPasswordVersion); switch (userInDb.PasswordVersion) { case PasswordVersion.Sha1: if (HashHelper.CreateHash<SHA1CryptoServiceProvider>(inputPassword) != userInDb.Password) return false; break; case PasswordVersion.Sha512WithSalt: if (HashHelper.CreateHash<SHA512CryptoServiceProvider>(MixWithSalt(inputPassword, userInDb.Salt)) != userInDb.Password) return false; break; default: throw new NotSupportedException(); } if (shouldUpdate) { userInDb.PasswordVersion = CurrentPasswordVersion; if (string.IsNullOrEmpty(userInDb.Salt)) userInDb.Salt = HashHelper.GenerateRandomString(saltLength); } return true; }
private void InsertHeadQuarter(User user, KeyStoreContext context) { if (Constants.IsMultipleEnabled) user.UserHeadQuarters.ToList().ForEach(u => context.UserHeadQuarters.Add(u)); else { if (context.HeadQuarters.Count() > 0) { var map = new UserHeadQuarter() { User = user, HeadQuarterId = context.HeadQuarters.First().HeadQuarterId, IsDefault = true }; context.UserHeadQuarters.Add(map); } } }
private void InsertRole(User user, KeyStoreContext context) { user.Roles.ToList().ForEach(r => context.Roles.Attach(r)); }
public ConfigProxy(User user) : this(user, null) { }
private void InsertUser(User user, KeyStoreContext context) { context.Users.Add(user); }
public List<HeadQuarter> GetHeadQuarters(User user) { return hqRepository.GetHeadQuarters(user); }
private void UpdateRole(User user) { using (var context = GetContext()) { var userToUpdate = GetQuery(context).FirstOrDefault(q => q.UserId == user.UserId); if (userToUpdate == null) throw new ApplicationException(string.Format("Update failed, user id: {0} didn't exist.", user.LoginId)); if (userToUpdate.Role.RoleId != user.Role.RoleId) { userToUpdate.Roles.Clear(); userToUpdate.Roles.Add(GetRole(context,user.Role.RoleId)); } context.SaveChanges(); } }
public void UpdateUserHeadQuarter(User user, HeadQuarter headQuarter) { using (var context = GetContext()) { context.UserHeadQuarters .Where(u => u.UserId == user.UserId).ToList() .ForEach(hq => hq.IsDefault = (hq.HeadQuarterId == headQuarter.HeadQuarterId)); context.SaveChanges(); } }
private void DeleteUser(KeyStoreContext context, User userToDelete) { if (context.Entry(userToDelete).State == EntityState.Detached) context.Users.Attach(userToDelete); context.Users.Remove(userToDelete); }
public KeyProxy(User user, int? hqId) : this(user, hqId, null, null, null, null, null) { }
public void UpdateUser(User user) { RenewUser(user); UpdateRole(user); }
/// <summary> /// Loads default data on window loading /// </summary> /// <param name="currentUser"></param> private void InitializeCollections(User currentUser) { try { roles = new ObservableCollection<Role>(userProxy.GetRoles()); langs = DIS.Presentation.KMT.Language.GetLangs(); SelectedRole = currentUser.Role == null ? roles.ElementAt(0) : currentUser.Role; FirstName = currentUser.FirstName; LastName = currentUser.SecondName; Department = currentUser.Department; Position = currentUser.Position; Email = currentUser.Email; Phone = currentUser.Phone; LoginID = currentUser.LoginId; CurrentPassword = string.Empty; userCreateDate = currentUser.CreatedDate; if (string.IsNullOrEmpty(currentUser.Language)) { currentUser.Language = KmtConstants.CurrentCulture.IetfLanguageTag; } SelectedLanguage = langs.SingleOrDefault(l => l.LanguageCode == currentUser.Language) ?? DIS.Presentation.KMT.Language.Default; } catch (Exception ex) { ex.ShowDialog(); ExceptionHandler.HandleException(ex); } }
private bool ValidateAdminCount(User user) { bool isValid = user.Roles.SingleOrDefault().RoleName == Constants.ManagerRoleName || user.Roles.SingleOrDefault().RoleName == userRepository.GetUser(user.LoginId).Roles.SingleOrDefault().RoleName; return isValid || userRepository.SearchUsers(null, userRepository.GetRoles().Single(r => r.RoleName == Constants.ManagerRoleName).RoleId).Count > 1; }
private void TrimInformation(User user) { if (!string.IsNullOrEmpty(user.LoginId)) user.LoginId = user.LoginId.Trim(); if (!string.IsNullOrEmpty(user.Phone)) user.Phone = user.Phone.Trim(); if (!string.IsNullOrEmpty(user.Position)) user.Position = user.Position.Trim(); if (!string.IsNullOrEmpty(user.FirstName)) user.FirstName = user.FirstName.Trim(); if (!string.IsNullOrEmpty(user.SecondName)) user.SecondName = user.SecondName.Trim(); if (!string.IsNullOrEmpty(user.Email)) user.Email = user.Email.Trim(); if (!string.IsNullOrEmpty(user.Department)) user.Department = user.Department.Trim(); if (!string.IsNullOrEmpty(user.Language)) user.Language = user.Language.Trim(); }
public bool ValidateCurrentPassword(User user) { User currentUser = this.Login(user.LoginId, user.Password); return currentUser != null; }
public void EditUser(User user) { if (user == null) throw new ArgumentNullException("User is null"); if (!string.IsNullOrEmpty(user.Password)) resolver.SetUserPassword(user); TrimInformation(user); if (!ValidateAdminCount(user)) throw new DisException(Resources.UserProxy_CannotRemoveLastAdmin); userRepository.UpdateUser(user); }
/// <summary> /// Selection changed event for each selection in user items datagrid /// Used to persist selected items information between page navigations /// </summary> private void EnableUserSelected(User SelectedUser) { if (this.selectedUserCollection != null) this.selectedUserCollection.Clear(); if (null != SelectedUser) { selectedUserCollection.Add(SelectedUser); //Notify History DIS.Presentation.KMT and Pager base.RaisePropertyChanged("SelectedUserCollection"); } }
private User BuildUser() { User user = new User(); user.UserId = currentUser.UserId; user.LoginId = loginId; user.Phone = phone; user.Position = position; user.Roles.Clear(); user.AddRole(selectedRole); user.FirstName = firstName; user.SecondName = lastName; user.Email = email; user.Department = department; user.Password = NewPassword; if (this.userOperation == UserOperation.Add) user.CreatedDate = DateTime.UtcNow; else user.CreatedDate = userCreateDate; user.UpdatedDate = DateTime.UtcNow; user.Language = Language; user.Salt = currentUser.Salt; user.PasswordVersion = PasswordVersionResolver.CurrentPasswordVersion; return user; }
private void RenewUser(User user) { using (var context = GetContext()) { User userToUpdate = GetQuery(context).FirstOrDefault(q => q.UserId == user.UserId); if (userToUpdate == null) throw new ApplicationException(string.Format("User '{0}' cannot be found.", user.UserId)); if (string.IsNullOrEmpty(user.Password)) user.Password = userToUpdate.Password; context.Entry(userToUpdate).CurrentValues.SetValues(user); context.SaveChanges(); } }