public async Task <IActionResult> Login( [FromBody] LoginShynee loginShynee) { var shyneeCredentials = new ShyneeCredentials( loginShynee.Email, loginShynee.Password); var shynee = await _shyneesService.FindShyneeByCredentialsAsync(shyneeCredentials); var shyneeProfile = shynee.Profile; var shyneeProfileDto = new ShyneeProfileDto( shyneeProfile.Nickname.Parameter, shyneeProfile.AvatarUri.Parameter, shyneeProfile.Name.Parameter, shyneeProfile.Dob.Parameter, shyneeProfile.Gender.Parameter, shyneeProfile.Interests.Parameter, shyneeProfile.PersonalInfo.Parameter); var shyneeCredentialsDto = new ShyneeCredentialsDto( shynee.Id, shynee.Credentials.Email, _jwtIssuer.IssueJwt(shynee.Id), shyneeProfileDto); return(Ok(shyneeCredentialsDto)); }
public async Task <IActionResult> CreateShynee( [FromBody] CreateShynee shynee) { var shyneeCredentials = new ShyneeCredentials( shynee.Email, Hasher.HashPassword(shynee.Password)); var shyneeProfile = new ShyneeProfile( shynee.Nickname, shynee.Name, shynee.Dob, shynee.Gender, shynee.Interests, shynee.PersonalInfo); var createdShynee = await _shyneesService.CreateShyneeAsync( shyneeCredentials, shyneeProfile); var shyneeProfileDto = new ShyneeProfileDto( shyneeProfile.Nickname.Parameter, shyneeProfile.AvatarUri.Parameter, shyneeProfile.Name.Parameter, shyneeProfile.Dob.Parameter, shyneeProfile.Gender.Parameter, shyneeProfile.Interests.Parameter, shyneeProfile.PersonalInfo.Parameter); var shyneeCredentialsDto = new ShyneeCredentialsDto( createdShynee.Id, createdShynee.Credentials.Email, _jwtIssuer.IssueJwt(createdShynee.Id), shyneeProfileDto); return(Ok(shyneeCredentialsDto)); }
public async Task <Shynee> FindShyneeByCredentialsAsync(ShyneeCredentials credentials) { var shynee = await _shyneesRepository.FindShyneeByCredentialsAsync(credentials); if (shynee == null) { throw new ShyneeNotFoundException(); } return(shynee); }
public async Task <Shynee> FindShyneeByCredentialsAsync(ShyneeCredentials credentials) { if (!await IsShyneeExistsAsync(credentials.Email)) { throw new ShyneeNotFoundException("Shynee with required email is not found"); } var shynee = _shyneesStore.Single(s => s.Credentials.Email == credentials.Email); var shyneeHash = shynee.Credentials.Password; if (!IsPasswordValid(shyneeHash, credentials.Password)) { throw new InvalidPasswordException(); } return(shynee); }
public async Task <Shynee> FindShyneeByCredentialsAsync(ShyneeCredentials credentials) { var builder = Builders <Shynee> .Filter; var filter = builder.Eq("Credentials.Email", credentials.Email); var shynee = await _dbContext.Shynees.Find(filter).FirstOrDefaultAsync(); if (shynee != null) { if (!IsPasswordValid(shynee.Credentials.Password, credentials.Password)) { throw new InvalidPasswordException(); } } return(shynee); }
public async Task <Shynee> CreateShyneeAsync( ShyneeCredentials shyneeCredentials, ShyneeProfile shyneeProfile) { if (await _shyneesRepository.IsShyneeExistsAsync(shyneeCredentials.Email)) { throw new ShyneeDuplicateException(); } var shynee = new Shynee( shyneeCredentials, new ShyneeCoordinates(), shyneeProfile, new ShyneeSettings()); var id = await _shyneesRepository.CreateShyneeAsync(shynee); var createdShynee = await _shyneesRepository.GetShyneeAsync(id); return(createdShynee); }
private static Shynee GetStaticShynee() { var shyneeCredentials = new ShyneeCredentials("*****@*****.**", Hasher.HashPassword("qwertyui")); var shyneeCoordinates = FakeShyneeCoordinates().Generate(); var ShyneeSettings = new ShyneeSettings(); var shyneeProfile = new ShyneeProfile( new ShyneeProfileParameter <string>(ShyneeProfileParameterStatus.Visible, "Shynee"), new ShyneeProfileParameter <string>(ShyneeProfileParameterStatus.Empty), new ShyneeProfileParameter <string>(ShyneeProfileParameterStatus.Empty), new ShyneeProfileParameter <DateTime?>(ShyneeProfileParameterStatus.Empty), new ShyneeProfileParameter <Gender>(ShyneeProfileParameterStatus.Empty), new ShyneeProfileParameter <string[]>(ShyneeProfileParameterStatus.Empty), new ShyneeProfileParameter <string>(ShyneeProfileParameterStatus.Empty)); var shynee = new Shynee( new Guid("452B5C13-E964-499C-89D4-072EEC43E7A4"), shyneeCredentials, shyneeCoordinates, shyneeProfile, ShyneeSettings); return(shynee); }