示例#1
0
        public void Authentication(string username, string clearTextPassword)
        {
            var userData = userRepository.Login(username, HashConverter.CalculateHash(clearTextPassword, username));

            if (userData == null)
            {
                throw new UnauthorizedAccessException("Access denied. Please provide some valid credentials.");
            }

            //#region Handheld != Access Denied
            //if (userData.RoleID.HasValue && userData.Role.RoleCode != "ADMINISTRATOR")
            //{
            //    if (DisableAccessForHandheldUser(userData.RoleID.Value))
            //        throw new UnauthorizedAccessException("Access denied. This role was not authorized to access the system.");
            //}
            //#endregion Handheld User != Access Denied

            CustomPrincipal customPrincipal = Thread.CurrentPrincipal as CustomPrincipal;

            if (customPrincipal == null)
            {
                throw new ArgumentException("The application's default thread principal must be set to a CustomPrincipal object on startup.");
            }

            customPrincipal.Identity = new CustomIdentity(userData.Username, userData.Role.RoleCode, userData.Email);
        }
示例#2
0
        private List <User> Update(List <UserExt> toUpdateList)
        {
            List <User> updateObj = new List <User>();

            foreach (var u in toUpdateList)
            {
                if (!u.Password.Contains("*"))
                {
                    var tempPass = HashConverter.CalculateHash(u.Password, u.Username);

                    var user = UserServices.GetUser(u.ID);
                    if (user != null && (user.Username != u.Username ||
                                         user.Name != u.Name ||
                                         user.RoleID != u.RoleID ||
                                         user.Email != u.Email ||
                                         user.Address != u.Address ||
                                         user.Password != tempPass))
                    {
                        user.Username   = u.Username;
                        user.Password   = tempPass;
                        user.Name       = u.Name;
                        user.Role       = RoleServices.GetRole(u.RoleID.GetValueOrDefault());
                        user.RoleID     = u.RoleID;
                        user.Email      = u.Email;
                        user.Address    = u.Address;
                        user.ModifiedOn = DateTime.Now;
                        user.ModifiedBy = AuthenticatedUser;
                        updateObj.Add(user);
                    }
                }
            }
            return(updateObj);
        }
示例#3
0
 private User Add(User data)
 {
     return(new User
     {
         Username = UsernameAlias,
         Password = HashConverter.CalculateHash(Password, UsernameAlias),
         RoleID = SelectedRole.ID,
         Name = data.Name,
         Email = data.Email,
         Address = data.Address,
         CreatedOn = DateTime.Now,
         CreatedBy = AuthenticatedUser,
         ModifiedOn = DateTime.Now,
         ModifiedBy = AuthenticatedUser
     });
 }
示例#4
0
        private User Update(User data)
        {
            var userUpdate = UserServices.GetUser(data.ID);

            if (userUpdate != null)
            {
                userUpdate.Username   = UsernameAlias;
                userUpdate.Password   = !string.IsNullOrEmpty(Password) ? HashConverter.CalculateHash(Password, UsernameAlias) : data.Password;
                userUpdate.Role       = SelectedRole;
                userUpdate.RoleID     = SelectedRole.ID;
                userUpdate.Name       = data.Name;
                userUpdate.Email      = data.Email;
                userUpdate.Address    = data.Address;
                userUpdate.ModifiedOn = DateTime.Now;
                userUpdate.ModifiedBy = AuthenticatedUser;
            }
            return(userUpdate);
        }
示例#5
0
        private List <User> Add(List <UserExt> toSaveList)
        {
            List <User> addObj = new List <User>();

            foreach (var o in toSaveList)
            {
                var reason = new User
                {
                    Username   = o.Username,
                    Password   = HashConverter.CalculateHash(o.Password, o.Username),
                    Name       = o.Name,
                    RoleID     = o.RoleID,
                    Email      = o.Email,
                    Address    = o.Address,
                    CreatedOn  = DateTime.Now,
                    CreatedBy  = AuthenticatedUser,
                    ModifiedOn = o.ModifiedOn,
                    ModifiedBy = AuthenticatedUser
                };
                addObj.Add(reason);
            }
            return(addObj);
        }