private async Task <LoginToResponse> Login(UserToLogin userLogin, SigningConfigurations signingConfigurations, TokenConfiguration tokenConfigurations) { if (userLogin.Email.IsEmail() && !string.IsNullOrEmpty(userLogin.Password)) { var repository = UserRepository.GetInstance(_context); var user = await repository.GetUserLogin(userLogin.Email, userLogin.Password); if (user != null) { var token = GenerateToken.TokenGenerate(user.Email, signingConfigurations, tokenConfigurations); var userDisplay = user.ToDisplay(); if (user.Admin) { var repositoryBusiness = EstablishmmentRepository.GetInstance(_context); userDisplay.Establishmments = repositoryBusiness.GetByAdmin(user.Id).ToDisplay(); } return(LoginToResponse.Create(userDisplay, token)); } } return(null); }
public ActionResult GetToken([Bind(Include = "Username,Password")] UserDto user) { User result = null; //checks if username is empty if (!string.IsNullOrWhiteSpace(user.UserName)) { result = _userRepository.GetUserMyUserName(user.UserName); } //checks if any user was found or not. if (result is null) { ViewBag.Message = "Not Exist!"; return(View(user)); } //checks user password if (result.Password == user.PassWord) { ViewBag.Token = GenerateToken.TokenGenerate(result); } else { ViewBag.Message = "Wrong Password!"; } return(View(user)); }