diff options
Diffstat (limited to 'BackEnd')
10 files changed, 102 insertions, 8 deletions
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/BookmarkTimelineTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/BookmarkTimelineTest.cs index 4bad700b..eb3e878d 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/BookmarkTimelineTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/BookmarkTimelineTest.cs @@ -1,4 +1,5 @@ using FluentAssertions;
+using System; using System.Collections.Generic;
using System.Threading.Tasks;
using Timeline.Models.Http;
@@ -7,6 +8,7 @@ using Xunit.Abstractions; namespace Timeline.Tests.IntegratedTests
{
+ [Obsolete("Old test.")]
public class BookmarkTimelineTest : IntegratedTestBase
{
public BookmarkTimelineTest(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/HighlightTimelineTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/HighlightTimelineTest.cs index c52ac907..f05497fd 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/HighlightTimelineTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/HighlightTimelineTest.cs @@ -1,4 +1,5 @@ using FluentAssertions;
+using System; using System.Collections.Generic;
using System.Threading.Tasks;
using Timeline.Models.Http;
@@ -7,6 +8,7 @@ using Xunit.Abstractions; namespace Timeline.Tests.IntegratedTests
{
+ [Obsolete("Old test.")]
public class HighlightTimelineTest : IntegratedTestBase
{
public HighlightTimelineTest(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/SearchTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/SearchTest.cs index 499eabbe..c9d1cb58 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/SearchTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/SearchTest.cs @@ -1,4 +1,5 @@ using FluentAssertions;
+using System; using System.Collections.Generic;
using System.Threading.Tasks;
using Timeline.Models.Http;
@@ -7,6 +8,7 @@ using Xunit.Abstractions; namespace Timeline.Tests.IntegratedTests
{
+ [Obsolete("Old test.")]
public class SearchTest : IntegratedTestBase
{
public SearchTest(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs index 5fab2bdb..4abcdb92 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -10,6 +10,7 @@ using Xunit.Abstractions; namespace Timeline.Tests.IntegratedTests
{
+ [Obsolete("Old test.")]
public class TimelineTest : BaseTimelineTest
{
public TimelineTest(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
diff --git a/BackEnd/Timeline.Tests/IntegratedTests2/SelfTest.cs b/BackEnd/Timeline.Tests/IntegratedTests2/SelfTest.cs new file mode 100644 index 00000000..9698551a --- /dev/null +++ b/BackEnd/Timeline.Tests/IntegratedTests2/SelfTest.cs @@ -0,0 +1,41 @@ +using System; +using System.Net; +using System.Net.Http; +using System.Threading.Tasks; +using Timeline.Models.Http; +using Xunit; +using Xunit.Abstractions; + +namespace Timeline.Tests.IntegratedTests2 +{ + public class SelfTest : IntegratedTestBase + { + public SelfTest(ITestOutputHelper testOutput) : base(testOutput) + { + } + + [Fact] + public async Task ChangePassword() + { + await DefaultClient.TestJsonSendAsync(HttpMethod.Post, "v2/self/changepassword", new HttpChangePasswordRequest + { + OldPassword = "abc", + NewPassword = "def" + }, expectedStatusCode: HttpStatusCode.Unauthorized); + + + await UserClient.TestJsonSendAsync(HttpMethod.Post, "v2/self/changepassword", new HttpChangePasswordRequest + { + OldPassword = "abc", + NewPassword = "def" + }, expectedStatusCode: HttpStatusCode.UnprocessableEntity); + + await UserClient.TestJsonSendAsync(HttpMethod.Post, "v2/self/changepassword", new HttpChangePasswordRequest + { + OldPassword = "userpw", + NewPassword = "def" + }, expectedStatusCode: HttpStatusCode.NoContent); + } + } +} + diff --git a/BackEnd/Timeline.Tests/IntegratedTests2/TimelineTest.cs b/BackEnd/Timeline.Tests/IntegratedTests2/TimelineTest.cs index 807314f4..84bd5264 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests2/TimelineTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests2/TimelineTest.cs @@ -25,7 +25,7 @@ namespace Timeline.Tests.IntegratedTests2 var b = await client.TestJsonSendAsync<HttpTimeline>(HttpMethod.Get, "v2/timelines/user/hello"); - a.Name.Should().Be(b.Name); + a.NameV2.Should().Be(b.NameV2); a.UniqueId.Should().Be(b.UniqueId); } diff --git a/BackEnd/Timeline.Tests/IntegratedTests2/TimelineTest2.cs b/BackEnd/Timeline.Tests/IntegratedTests2/TimelineTest2.cs index b5566ba0..a97ee6d6 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests2/TimelineTest2.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests2/TimelineTest2.cs @@ -38,7 +38,7 @@ namespace Timeline.Tests.IntegratedTests2 Color = "#FFFFFF" }); - b.Name.Should().Be("hello2"); + b.NameV2.Should().Be("hello2"); b.Title.Should().Be("Hello"); b.Description.Should().Be("A Description."); b.Visibility.Should().Be(TimelineVisibility.Public); diff --git a/BackEnd/Timeline/Controllers/V2/SelfController.cs b/BackEnd/Timeline/Controllers/V2/SelfController.cs new file mode 100644 index 00000000..1604bc67 --- /dev/null +++ b/BackEnd/Timeline/Controllers/V2/SelfController.cs @@ -0,0 +1,40 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Timeline.Models.Http; +using Timeline.Services.User; + +namespace Timeline.Controllers.V2 +{ + [ApiController] + [Route("v2/self")] + public class SelfController : V2ControllerBase + { + private readonly IUserService _userService; + + public SelfController(IUserService userService) + { + _userService = userService; + } + + [HttpPost("changepassword")] + [Authorize] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] + public async Task<ActionResult> ChangePasswordAsync([FromBody] HttpChangePasswordRequest body) + { + try + { + await _userService.ChangePassword(GetAuthUserId(), body.OldPassword, body.NewPassword); + return NoContent(); + } + catch (BadPasswordException) + { + return UnprocessableEntity(new ErrorResponse(ErrorResponse.InvalidRequest, "Old password is wrong.")); + } + } + } +} + diff --git a/BackEnd/Timeline/Models/Http/HttpTimeline.cs b/BackEnd/Timeline/Models/Http/HttpTimeline.cs index 83398baf..401d84a2 100644 --- a/BackEnd/Timeline/Models/Http/HttpTimeline.cs +++ b/BackEnd/Timeline/Models/Http/HttpTimeline.cs @@ -1,4 +1,4 @@ -using System;
+using System;
using System.Collections.Generic;
namespace Timeline.Models.Http
@@ -13,8 +13,10 @@ namespace Timeline.Models.Http public HttpTimeline(string uniqueId, string title, string name, string nameV2, DateTime nameLastModifed, string description, HttpUser owner, TimelineVisibility visibility, List<HttpUser> members, string? color, DateTime createTime, DateTime lastModified, bool isHighlight, bool isBookmark, bool manageable, bool postable, HttpTimelineLinks links)
{
UniqueId = uniqueId;
- Title = title;
- Name = name;
+ Title = title; +#pragma warning disable CS0618 // Type or member is obsolete + Name = name; +#pragma warning restore CS0618 // Type or member is obsolete NameV2 = nameV2;
NameLastModifed = nameLastModifed;
Description = description;
@@ -42,6 +44,7 @@ namespace Timeline.Models.Http /// <summary>
/// Name of timeline.
/// </summary>
+ [Obsolete("Use NameV2")]
public string Name { get; set; } = default!;
/// <summary>
/// Name of timeline.
diff --git a/BackEnd/Timeline/Models/Http/HttpTimelinePost.cs b/BackEnd/Timeline/Models/Http/HttpTimelinePost.cs index 5c6a7167..677c486f 100644 --- a/BackEnd/Timeline/Models/Http/HttpTimelinePost.cs +++ b/BackEnd/Timeline/Models/Http/HttpTimelinePost.cs @@ -1,4 +1,4 @@ -using System;
+using System;
using System.Collections.Generic;
namespace Timeline.Models.Http
@@ -21,8 +21,10 @@ namespace Timeline.Models.Http Color = color;
LastUpdated = lastUpdated;
TimelineOwnerV2 = timelineOwnerV2;
- TimelineNameV2 = timelineNameV2;
- TimelineName = timelineName;
+ TimelineNameV2 = timelineNameV2; +#pragma warning disable CS0618 // Type or member is obsolete + TimelineName = timelineName; +#pragma warning restore CS0618 // Type or member is obsolete Editable = editable;
}
@@ -67,6 +69,7 @@ namespace Timeline.Models.Http /// <summary>
/// Timeline name.
/// </summary>
+ [Obsolete("Use TimelineNameV2.")]
public string TimelineName { get; set; } = default!;
/// <summary>
/// True if you can edit this post.
|