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); }
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); } }
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); } } }
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); } }
public User GetByEmail(string email) { DomainUser domainUser = GetDomainUserByEmail(email); return(Mapper.Map <User>(domainUser)); }
public User GetByID(int userID) { DomainUser domainUser = GetDomainUserByID(userID); return(Mapper.Map <User>(domainUser)); }