Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 public CreateNewUser(IUserProxy userProxy, User currentUser, UserOperation userOperation)
 {
     InitializeComponent();
     VM = new CreateUserViewModel(userProxy, currentUser, userOperation);
     VM.View = this;
     DataContext = VM;
 }
Exemplo n.º 4
0
        /// <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;
        }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
 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();
     }
 }
Exemplo n.º 7
0
        public ConfigProxy(User user, IFulfillmentManager fulfillmentManager)
        {
            this.user = user;

            if (fulfillmentManager == null)
                this.fulfillmentManager = new FulfillmentManager();
            else
                this.fulfillmentManager = fulfillmentManager;
        }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
 public void InsertUser(User user)
 {
     using (var context = GetContext())
     {
         InsertUser(user, context);
         InsertRole(user, context);
         InsertHeadQuarter(user, context);
         context.SaveChanges();
     }
 }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
 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;
 }
Exemplo n.º 13
0
 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);
         }
     }
 }
Exemplo n.º 14
0
 private void InsertRole(User user, KeyStoreContext context)
 {
     user.Roles.ToList().ForEach(r => context.Roles.Attach(r));
 }
Exemplo n.º 15
0
 public ConfigProxy(User user)
     : this(user, null)
 {
 }
Exemplo n.º 16
0
 private void InsertUser(User user, KeyStoreContext context)
 {
     context.Users.Add(user);
 }
Exemplo n.º 17
0
 public List<HeadQuarter> GetHeadQuarters(User user)
 {
     return hqRepository.GetHeadQuarters(user);
 }
Exemplo n.º 18
0
 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();
     }
 }
Exemplo n.º 19
0
 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();
     }
 }
Exemplo n.º 20
0
 private void DeleteUser(KeyStoreContext context, User userToDelete)
 {
     if (context.Entry(userToDelete).State == EntityState.Detached)
         context.Users.Attach(userToDelete);
     context.Users.Remove(userToDelete);
 }
Exemplo n.º 21
0
 public KeyProxy(User user, int? hqId)
     : this(user, hqId, null, null, null, null, null)
 {
 }
Exemplo n.º 22
0
 public void UpdateUser(User user)
 {
     RenewUser(user);
     UpdateRole(user);
 }
Exemplo n.º 23
0
        /// <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);
            }
        }
Exemplo n.º 24
0
 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;
 }
Exemplo n.º 25
0
 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();
 }
Exemplo n.º 26
0
 public bool ValidateCurrentPassword(User user)
 {
     User currentUser = this.Login(user.LoginId, user.Password);
     return currentUser != null;
 }
Exemplo n.º 27
0
        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);
        }
Exemplo n.º 28
0
 /// <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");
     }
 }
Exemplo n.º 29
0
 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;
 }
Exemplo n.º 30
0
 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();
     }
 }