Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #179 from Laixer/feature/cleanup-notification
Browse files Browse the repository at this point in the history
Feature/cleanup notification
  • Loading branch information
tabeckers authored Nov 19, 2020
2 parents 0da26a3 + 2d029d2 commit d803ef0
Show file tree
Hide file tree
Showing 59 changed files with 830 additions and 1,667 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ dotnet_diagnostic.CS1591.severity = none

# CA1031: Specify Exception type in catch block
dotnet_diagnostic.CA1031.severity = none

# CA1051: Do not declare visible instance fields
dotnet_diagnostic.CA1051.api_surface = private, internal, protected
33 changes: 12 additions & 21 deletions Swabbr.Api/Controllers/AuthenticationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class AuthenticationController : ControllerBase
private readonly ITokenService _tokenService;
private readonly UserManager<SwabbrIdentityUser> _userManager;
private readonly SignInManager<SwabbrIdentityUser> _signInManager;
private readonly IDeviceRegistrationService _deviceRegistrationService;
private readonly INotificationService _notificationService;
private readonly ILogger logger;

/// <summary>
Expand All @@ -45,14 +45,14 @@ public AuthenticationController(IUserService userService,
ITokenService tokenService,
UserManager<SwabbrIdentityUser> userManager,
SignInManager<SwabbrIdentityUser> signInManager,
IDeviceRegistrationService deviceRegistrationService,
INotificationService notificationService,
ILoggerFactory loggerFactory)
{
_userService = userService ?? throw new ArgumentNullException(nameof(userService));
_tokenService = tokenService ?? throw new ArgumentNullException(nameof(tokenService));
_userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
_signInManager = signInManager ?? throw new ArgumentNullException(nameof(signInManager));
_deviceRegistrationService = deviceRegistrationService ?? throw new ArgumentNullException(nameof(deviceRegistrationService));
_notificationService = notificationService ?? throw new ArgumentNullException(nameof(notificationService));
logger = (loggerFactory != null) ? loggerFactory.CreateLogger(nameof(AuthenticationController)) : throw new ArgumentNullException(nameof(loggerFactory));
}

Expand Down Expand Up @@ -139,10 +139,12 @@ public async Task<IActionResult> RegisterAsync([FromBody] UserRegisterInputModel
}

/// <summary>
/// Sign in an already registered user.
/// Sign in an already registered user.
/// </summary>
/// <remarks>
/// This also handles push notification registration.
/// </remarks>
/// <param name="input"><see cref="UserLoginInputModel"/></param>
/// <returns><see cref="IActionResult"/></returns>
[AllowAnonymous]
[HttpPost("login")]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(UserAuthenticationOutputModel))]
Expand All @@ -168,8 +170,8 @@ public async Task<IActionResult> LoginAsync([FromBody] UserLoginInputModel input
var tokenWrapper = _tokenService.GenerateToken(identityUser);

// Manage device registration
var pnp = (PushNotificationPlatformModel)input.PushNotificationPlatform;
await _deviceRegistrationService.RegisterOnlyThisDeviceAsync(identityUser.Id, MapperEnum.Map(pnp), input.Handle).ConfigureAwait(false);
var platform = MapperEnum.Map((PushNotificationPlatformModel)input.PushNotificationPlatform);
await _notificationService.RegisterAsync(identityUser.Id, platform, input.Handle).ConfigureAwait(false);

return Ok(new UserAuthenticationOutputModel
{
Expand All @@ -194,10 +196,9 @@ public async Task<IActionResult> LoginAsync([FromBody] UserLoginInputModel input
}

/// <summary>
/// Used to update the user password.
/// Used to update the user password.
/// </summary>
/// <param name="input"><see cref="UserChangePasswordInputModel"/></param>
/// <returns><see cref="OkResult"/></returns>
/// <param name="input"><see cref="UserChangePasswordInputModel"/>.</param>
[HttpPost("change_password")]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(UserAuthenticationOutputModel))]
[ProducesResponseType((int)HttpStatusCode.Unauthorized, Type = typeof(string))]
Expand Down Expand Up @@ -232,24 +233,14 @@ public async Task<IActionResult> ChangePasswordAsync([FromBody] UserChangePasswo
}

/// <summary>
/// Deauthorizes the authenticated user.
/// Deauthorizes the authenticated user.
/// </summary>
/// <returns><see cref="NoContentResult"/></returns>
[Authorize]
[HttpPost("logout")]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
public async Task<IActionResult> LogoutAsync()
{
try
{
using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
// Unregister device
var user = await _userManager.GetUserAsync(User).ConfigureAwait(false);
await _deviceRegistrationService.UnregisterAsync(user.Id).ConfigureAwait(false);
scope.Complete();
}

await _signInManager.SignOutAsync().ConfigureAwait(false);
return NoContent();
}
Expand Down
152 changes: 0 additions & 152 deletions Swabbr.Api/Controllers/DebugController.cs

This file was deleted.

105 changes: 0 additions & 105 deletions Swabbr.Api/Controllers/TestingEndpointsController.cs

This file was deleted.

21 changes: 15 additions & 6 deletions Swabbr.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
using Swabbr.Core.Extensions;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using System.Threading.Tasks;
using Swabbr.Core.Exceptions;
using Swabbr.Core.Extensions;
using System.Threading.Tasks;

namespace Swabbr
{

/// <summary>
/// Entry class.
/// </summary>
public static class Program
{

/// <summary>
/// Application entry point.
/// </summary>
/// <param name="args">Command line arguments.</param>
public static Task Main(string[] args)
=> CreateHostBuilder(args).Build().RunAsync();

/// <summary>
/// Creates our host builder.
/// </summary>
/// <param name="args">Command line arguments.</param>
/// <returns>Host builder instance.</returns>
public static IHostBuilder CreateHostBuilder(string[] args)
=> Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
Expand All @@ -31,5 +41,4 @@ public static IHostBuilder CreateHostBuilder(string[] args)
});
});
}

}
Loading

0 comments on commit d803ef0

Please sign in to comment.