| public static TConfig ConfigureStartupConfig<TConfig>(IServiceCollection services, IConfiguration configuration) | public static TConfig ConfigureStartupConfig<TConfig>(IServiceCollection services, IConfiguration configuration) | ||||
| where TConfig : class, new() | where TConfig : class, new() | ||||
| { | { | ||||
| if (services == null) | |||||
| if (services is null) | |||||
| throw new ArgumentNullException(nameof(services)); | throw new ArgumentNullException(nameof(services)); | ||||
| if (configuration == null) | |||||
| if (configuration is null) | |||||
| throw new ArgumentNullException(nameof(configuration)); | throw new ArgumentNullException(nameof(configuration)); | ||||
| //create instance of config | //create instance of config |
| public async Task<int> Create(MessageDto messageDto, PeriodOfValidity chosenPeriod) | public async Task<int> Create(MessageDto messageDto, PeriodOfValidity chosenPeriod) | ||||
| { | { | ||||
| var message = _mapper.Map<Message>(messageDto); | var message = _mapper.Map<Message>(messageDto); | ||||
| switch (chosenPeriod) | |||||
| message.ExpiryDate = chosenPeriod switch | |||||
| { | { | ||||
| case PeriodOfValidity.ONE_TIME: | |||||
| message.ExpiryDate = null; | |||||
| break; | |||||
| case PeriodOfValidity.ONE_DAY: | |||||
| message.ExpiryDate = DateTime.UtcNow.AddMinutes(1); | |||||
| break; | |||||
| case PeriodOfValidity.ONE_HOUR: | |||||
| message.ExpiryDate = DateTime.UtcNow.AddHours(1); | |||||
| break; | |||||
| case PeriodOfValidity.ONE_WEEK: | |||||
| message.ExpiryDate = DateTime.UtcNow.AddDays(7); | |||||
| break; | |||||
| default: | |||||
| message.ExpiryDate = null; | |||||
| break; | |||||
| } | |||||
| PeriodOfValidity.ONE_TIME => null, | |||||
| PeriodOfValidity.ONE_DAY => DateTime.UtcNow.AddMinutes(1), | |||||
| PeriodOfValidity.ONE_HOUR => DateTime.UtcNow.AddHours(1), | |||||
| PeriodOfValidity.ONE_WEEK => DateTime.UtcNow.AddDays(7), | |||||
| _ => null | |||||
| }; | |||||
| await _dbContext.Messages.AddAsync(message); | await _dbContext.Messages.AddAsync(message); | ||||
| await _dbContext.SaveChangesAsync(); | await _dbContext.SaveChangesAsync(); | ||||
| public async Task<bool> Delete(int messageId) | public async Task<bool> Delete(int messageId) | ||||
| { | { | ||||
| var messageDto = await GetById(messageId); | var messageDto = await GetById(messageId); | ||||
| if (messageDto == null) return false; | |||||
| if (messageDto is null) return false; | |||||
| _dbContext.Set<Message>().Remove(_mapper.Map<Message>(messageDto)); | _dbContext.Set<Message>().Remove(_mapper.Map<Message>(messageDto)); | ||||
| try | try | ||||
| { | { |
| public IActionResult OnGet(string code = null) | public IActionResult OnGet(string code = null) | ||||
| { | { | ||||
| if (code == null) | |||||
| if (code is null) | |||||
| { | { | ||||
| return BadRequest("A code must be supplied for password reset."); | return BadRequest("A code must be supplied for password reset."); | ||||
| } | } | ||||
| if (!ModelState.IsValid) return Page(); | if (!ModelState.IsValid) return Page(); | ||||
| var user = await _userManager.FindByEmailAsync(Input.Email); | var user = await _userManager.FindByEmailAsync(Input.Email); | ||||
| if (user == null) | |||||
| if (user is null) | |||||
| // Don't reveal that the user does not exist | // Don't reveal that the user does not exist | ||||
| return RedirectToPage("./ResetPasswordConfirmation"); | return RedirectToPage("./ResetPasswordConfirmation"); | ||||
| using System; | |||||
| using System.Threading.Tasks; | |||||
| using SecureSharing.Business.Interfaces; | |||||
| using SecureSharing.Business.Interfaces; | |||||
| using SecureSharing.Models; | using SecureSharing.Models; | ||||
| namespace SecureSharing.Infrastructure; | namespace SecureSharing.Infrastructure; |