diff --git a/MangoAPI.BusinessLogic/ApiCommands/Sessions/LogoutAllCommand.cs b/MangoAPI.BusinessLogic/ApiCommands/Sessions/LogoutAllCommand.cs deleted file mode 100644 index df7a8e689..000000000 --- a/MangoAPI.BusinessLogic/ApiCommands/Sessions/LogoutAllCommand.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; -using MangoAPI.BusinessLogic.Responses; -using MediatR; - -namespace MangoAPI.BusinessLogic.ApiCommands.Sessions; - -public record LogoutAllCommand(Guid UserId) - : IRequest>; diff --git a/MangoAPI.BusinessLogic/ApiCommands/Sessions/LogoutAllCommandHandler.cs b/MangoAPI.BusinessLogic/ApiCommands/Sessions/LogoutAllCommandHandler.cs deleted file mode 100644 index c3331fc71..000000000 --- a/MangoAPI.BusinessLogic/ApiCommands/Sessions/LogoutAllCommandHandler.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using MangoAPI.BusinessLogic.Responses; -using MangoAPI.Infrastructure.Database; -using MediatR; - -namespace MangoAPI.BusinessLogic.ApiCommands.Sessions; - -public class LogoutAllCommandHandler - : IRequestHandler> -{ - private readonly MangoDbContext dbContext; - private readonly ResponseFactory responseFactory; - - public LogoutAllCommandHandler( - MangoDbContext dbContext, - ResponseFactory responseFactory) - { - this.dbContext = dbContext; - this.responseFactory = responseFactory; - } - - public async Task> Handle( - LogoutAllCommand request, - CancellationToken cancellationToken) - { - var userSessions = dbContext.Sessions - .Where(entity => entity.UserId == request.UserId); - - dbContext.Sessions.RemoveRange(userSessions); - - await dbContext.SaveChangesAsync(cancellationToken); - - return responseFactory.SuccessResponse(ResponseBase.SuccessResponse); - } -} diff --git a/MangoAPI.BusinessLogic/MangoAPI.BusinessLogic.csproj b/MangoAPI.BusinessLogic/MangoAPI.BusinessLogic.csproj index 53a64066d..4793b5521 100644 --- a/MangoAPI.BusinessLogic/MangoAPI.BusinessLogic.csproj +++ b/MangoAPI.BusinessLogic/MangoAPI.BusinessLogic.csproj @@ -9,8 +9,8 @@ - - - + + + diff --git a/MangoAPI.Client/src/app/components/settings/settings.component.html b/MangoAPI.Client/src/app/components/settings/settings.component.html index aa30f65cc..2e7db1700 100644 --- a/MangoAPI.Client/src/app/components/settings/settings.component.html +++ b/MangoAPI.Client/src/app/components/settings/settings.component.html @@ -32,9 +32,6 @@
Profile
- @@ -158,7 +155,7 @@
Account
type="text" id="UserName" placeholder="Type your user name" - [(ngModel)]="currentUser.username" + [(ngModel)]="currentUserForUpdating.username" /> @@ -169,7 +166,7 @@
Account
type="text" id="DisplayName" placeholder="Type your display name" - [(ngModel)]="currentUser.displayName" + [(ngModel)]="currentUserForUpdating.displayName" /> @@ -180,7 +177,7 @@
Account
type="text" id="Bio" placeholder="Type your bio" - [(ngModel)]="currentUser.bio" + [(ngModel)]="currentUserForUpdating.bio" />
@@ -190,7 +187,7 @@
Account
type="text" id="Address" placeholder="Type your address" - [(ngModel)]="currentUser.address" + [(ngModel)]="currentUserForUpdating.address" />
@@ -215,7 +212,7 @@
Social network profiles
type="text" id="Facebook" placeholder="Username" - [(ngModel)]="currentUser.facebook" + [(ngModel)]="currentUserForUpdating.facebook" /> @@ -226,7 +223,7 @@
Social network profiles
type="text" id="Twitter" placeholder="Username" - [(ngModel)]="currentUser.twitter" + [(ngModel)]="currentUserForUpdating.twitter" /> @@ -238,7 +235,7 @@
Social network profiles
type="text" id="Instagram" placeholder="Username" - [(ngModel)]="currentUser.instagram" + [(ngModel)]="currentUserForUpdating.instagram" /> @@ -249,7 +246,7 @@
Social network profiles
type="text" id="LinkedIn" placeholder="Username" - [(ngModel)]="currentUser.linkedIn" + [(ngModel)]="currentUserForUpdating.linkedIn" /> diff --git a/MangoAPI.Client/src/app/components/settings/settings.component.ts b/MangoAPI.Client/src/app/components/settings/settings.component.ts index 55cb66705..428c88ba2 100644 --- a/MangoAPI.Client/src/app/components/settings/settings.component.ts +++ b/MangoAPI.Client/src/app/components/settings/settings.component.ts @@ -51,6 +51,26 @@ export class SettingsComponent implements OnInit, OnDestroy { publicKey: 0, pictureUrl: '' }; + + public currentUserForUpdating: User = { + userId: '', + displayName: '', + displayNameColour: 0, + birthdayDate: '', + email: '', + website: '', + username: '', + bio: '', + userNameChanged: false, + address: '', + facebook: '', + twitter: '', + instagram: '', + linkedIn: '', + publicKey: 0, + pictureUrl: '' + }; + public currentUserId = ''; public changePasswordCommand: ChangePasswordCommand = { currentPassword: '', @@ -80,6 +100,7 @@ export class SettingsComponent implements OnInit, OnDestroy { .subscribe({ next: (response) => { this.currentUser = response.user; + this.currentUserForUpdating = {...response.user}; if (response.user.userNameChanged === false) { this.currentUser.username = ''; @@ -133,29 +154,14 @@ export class SettingsComponent implements OnInit, OnDestroy { }); } - onLogoutAllClick(): void { - this._sessionService - .deleteAllSessions() - .pipe(takeUntil(this.componentDestroyed$)) - .subscribe({ - next: (_) => { - this._tokensService.clearTokens(); - this._router.navigateByUrl('login').then((r) => r); - }, - error: (error) => { - this._errorNotificationService.notifyOnError(error); - } - }); - } - onSaveChangesAccountInfoClick(): void { const command: UpdateAccountInformationCommand = { - username: this.currentUser.username, - birthdayDate: this.currentUser.birthdayDate, - website: this.currentUser.website, - address: this.currentUser.address, - bio: this.currentUser.bio, - displayName: this.currentUser.displayName + username: this.currentUserForUpdating.username, + birthdayDate: this.currentUserForUpdating.birthdayDate, + website: this.currentUserForUpdating.website, + address: this.currentUserForUpdating.address, + bio: this.currentUserForUpdating.bio, + displayName: this.currentUserForUpdating.displayName }; this._usersService @@ -163,6 +169,7 @@ export class SettingsComponent implements OnInit, OnDestroy { .pipe(takeUntil(this.componentDestroyed$)) .subscribe({ next: (response) => { + this.currentUser = {...this.currentUserForUpdating}; this.currentUser.userNameChanged = true; alert(response.message); }, diff --git a/MangoAPI.Client/src/app/interceptors/auth-interceptor.service.ts b/MangoAPI.Client/src/app/interceptors/auth-interceptor.service.ts index 79faf909a..9fc7630b3 100644 --- a/MangoAPI.Client/src/app/interceptors/auth-interceptor.service.ts +++ b/MangoAPI.Client/src/app/interceptors/auth-interceptor.service.ts @@ -29,7 +29,7 @@ export class AuthInterceptor implements HttpInterceptor { err.status === 401 && request.headers.has('Authorization') && request.headers.get('Authorization')?.startsWith('Bearer'); - + if (shouldHandle) { const refreshToken = this.tokensService.getTokens()?.refreshToken ?? ''; diff --git a/MangoAPI.IntegrationTests/ApiCommandsTests/LogoutAllCommandHandlerTests/LogoutAllTestSuccess.cs b/MangoAPI.IntegrationTests/ApiCommandsTests/LogoutAllCommandHandlerTests/LogoutAllTestSuccess.cs deleted file mode 100644 index 3a1f908d3..000000000 --- a/MangoAPI.IntegrationTests/ApiCommandsTests/LogoutAllCommandHandlerTests/LogoutAllTestSuccess.cs +++ /dev/null @@ -1,34 +0,0 @@ -using MangoAPI.BusinessLogic; -using System.Threading; -using System.Threading.Tasks; -using MangoAPI.BusinessLogic.ApiCommands.Sessions; -using MangoAPI.BusinessLogic.Responses; -using MangoAPI.IntegrationTests.Helpers; -using Xunit; - -namespace MangoAPI.IntegrationTests.ApiCommandsTests.LogoutAllCommandHandlerTests; - -public class LogoutAllTestSuccess : IntegrationTestBase -{ - private readonly Assert assert = new(); - - [Fact] - public async Task LogoutAllCommandHandlerTestSuccessAsync() - { - var user = await MangoModule.RequestAsync( - request: CommandHelper.RegisterPetroCommand(), - cancellationToken: CancellationToken.None); - var userId = user.Response.Tokens.UserId; - await MangoModule.RequestAsync( - request: CommandHelper.CreateLoginCommand("kolosovp95@gmail.com", "Bm3-`dPRv-/w#3)cw^97"), - cancellationToken: CancellationToken.None); - await MangoModule.RequestAsync( - request: CommandHelper.CreateLoginCommand("kolosovp95@gmail.com", "Bm3-`dPRv-/w#3)cw^97"), - cancellationToken: CancellationToken.None); - var command = new LogoutAllCommand(UserId: userId); - - var result = await MangoModule.RequestAsync(command, CancellationToken.None); - - assert.Pass(result); - } -} diff --git a/MangoAPI.Presentation/Controllers/SessionsController.cs b/MangoAPI.Presentation/Controllers/SessionsController.cs index 55d719028..db37248ad 100644 --- a/MangoAPI.Presentation/Controllers/SessionsController.cs +++ b/MangoAPI.Presentation/Controllers/SessionsController.cs @@ -96,26 +96,4 @@ public async Task LogoutAsync( return await RequestAsync(command, cancellationToken); } - - /// - /// Deletes all current user's sessions. - /// - /// Cancellation token instance. - /// Possible codes: 200, 400, 409. - [HttpDelete] - [Authorize] - [SwaggerOperation( - Description = "Deletes all current user's sessions.", - Summary = "Deletes all current user's sessions.")] - [ProducesResponseType(typeof(ResponseBase), StatusCodes.Status200OK)] - [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)] - [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status409Conflict)] - public async Task LogoutAllAsync(CancellationToken cancellationToken) - { - var userId = CorrelationContext.GetUserId(); - - var command = new LogoutAllCommand(userId); - - return await RequestAsync(command, cancellationToken); - } } diff --git a/MangoAPI.Presentation/Interfaces/ISessionsController.cs b/MangoAPI.Presentation/Interfaces/ISessionsController.cs index f3d4dcf1c..b5f7ef284 100644 --- a/MangoAPI.Presentation/Interfaces/ISessionsController.cs +++ b/MangoAPI.Presentation/Interfaces/ISessionsController.cs @@ -13,6 +13,4 @@ public interface ISessionsController Task RefreshSession(Guid refreshToken, CancellationToken cancellationToken); Task LogoutAsync(Guid refreshToken, CancellationToken cancellationToken); - - Task LogoutAllAsync(CancellationToken cancellationToken); } \ No newline at end of file