public bool CheckEmailExistence(string email) { int count = UserRepository.Find(user => user.Email == email).ToList().Count(); if (count == 0) { return(true); } return(false); }
private AuthenticateResponse AuthenticateUser(LoginRequest login) { User user = userRepositories.Find(a => a.Username == login.Username && a.Password == login.Password)?.FirstOrDefault(); if (user != null) { var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(configuration.GetSection("Secret").Value); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new Security.Claims.ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, user.Id.ToString()) }), Expires = DateTime.UtcNow.AddHours(2), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); return(new AuthenticateResponse() { User = user, Token = tokenHandler.WriteToken(token) }); } else { return(null); } }
public User User(string userID) { return(_userRepositories.Find(userID)); }