public IActionResult Login([FromBody] LoginCredentials credentials) { var errors = credentials.Validate(); if (errors.Any()) { return(BadRequest(errors)); } var encryptedPassword = PasswordEncrypter.Encrypt(credentials.Password); var user = Context.Users.SingleOrDefault(x => x.Email.Equals(credentials.Email) && x.Password.Equals(encryptedPassword)); if (user == null) { return(Unauthorized()); } var longLivedToken = TokenStore.GiveToken(DateTime.Now.AddSeconds(LongLivedTokenTimeInSeconds), SecurityKeyBuilder, GetClaims(user)); var shortLivedToken = TokenStore.GiveToken(DateTime.Now.AddSeconds(ShortLivedTokenTimeInSeconds), SecurityKeyBuilder, GetClaims(user)); return(Ok(new LoginResponse { LongLivedToken = longLivedToken, ShortLivedToken = shortLivedToken, IsAdmin = user.Role.Equals(Role.ADMIN) })); }
public void test_04_empty_login_credentials_dto_is_not_valid() { var dto = new LoginCredentials(); var errors = dto.Validate(); errors.Should().NotBeEmpty(); errors.Count.Should().Be(2); }
public void test_01_complete_login_credentials_dto_is_valid() { var dto = new LoginCredentials { Email = "email", Password = "******" }; var noErrors = dto.Validate(); noErrors.Should().BeEmpty(); }
public void test_03_login_credentials_dto_without_password_is_not_valid() { var dto = new LoginCredentials { Email = "email" }; var errors = dto.Validate(); errors.Should().NotBeEmpty(); errors.Count.Should().Be(1); }
void ILoginCredentialsCommand.UpdateCredentials(Guid userId, LoginCredentials credentials, Guid updatedById) { credentials.Validate(); _repository.UpdateCredentials(userId, credentials); }
void ILoginCredentialsCommand.CreateCredentials(Guid userId, LoginCredentials credentials) { credentials.Prepare(); credentials.Validate(); _repository.UpdateCredentials(userId, credentials); }