コード例 #1
0
        public User Login(string email, string password)
        {
            DomainUser domainUser = GetDomainUserByEmail(email);

            if (domainUser != null && PasswordEncoder.CheckPassword(password, domainUser.Salt, domainUser.Password))
            {
                return(Mapper.Map <User>(domainUser));
            }

            return(null);
        }
コード例 #2
0
        public void ChangePassword(int userID, string newPassword)
        {
            DomainUser domainUser = GetDomainUserByID(userID);

            if (domainUser != null && !string.IsNullOrEmpty(newPassword))
            {
                byte[] salt, hashedPassword;
                PasswordEncoder.EncryptPassword(newPassword, out salt, out hashedPassword);
                domainUser.Password = hashedPassword;
                domainUser.Salt     = salt;

                _context.Entry(domainUser).State = System.Data.Entity.EntityState.Modified;

                _context.SaveChanges();

                CacheController.ResetCacheItem(CacheController.CacheItemKey.UserByID);
                CacheController.ResetCacheItem(CacheController.CacheItemKey.UserByEmail);
            }
        }
コード例 #3
0
        public void UpdateUser(User user)
        {
            if (user != null)
            {
                DomainUser domainUser = GetDomainUserByID(user.UserID);

                if (domainUser != null)
                {
                    domainUser.Name = user.Name;

                    _context.Entry(domainUser).State = System.Data.Entity.EntityState.Modified;

                    _context.SaveChanges();

                    CacheController.ResetCacheItem(CacheController.CacheItemKey.UserByID);
                    CacheController.ResetCacheItem(CacheController.CacheItemKey.UserByEmail);
                }
            }
        }
コード例 #4
0
        public void AddUser(User user, string password)
        {
            if (user != null && !string.IsNullOrEmpty(password))
            {
                DomainUser domainUser = new DomainUser();

                domainUser.Name            = user.Name;
                domainUser.Email           = user.Email;
                domainUser.IsAdministrator = user.IsAdministrator;
                domainUser.IsActive        = user.IsActive;

                byte[] salt, hashedPassword;
                PasswordEncoder.EncryptPassword(password, out salt, out hashedPassword);
                domainUser.Password = hashedPassword;
                domainUser.Salt     = salt;

                _context.Users.Add(domainUser);

                _context.SaveChanges();

                CacheController.ResetCacheItem(CacheController.CacheItemKey.UserByID);
                CacheController.ResetCacheItem(CacheController.CacheItemKey.UserByEmail);
            }
        }
コード例 #5
0
        public User GetByEmail(string email)
        {
            DomainUser domainUser = GetDomainUserByEmail(email);

            return(Mapper.Map <User>(domainUser));
        }
コード例 #6
0
        public User GetByID(int userID)
        {
            DomainUser domainUser = GetDomainUserByID(userID);

            return(Mapper.Map <User>(domainUser));
        }