diff options
author | crupest <crupest@outlook.com> | 2020-10-27 19:21:35 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-10-27 19:21:35 +0800 |
commit | 05ccb4d8f1bbe3fb64e117136b4a89bcfb0b0b33 (patch) | |
tree | 929e514de85eb82a5acb96ecffc6e6d2d95f878f /BackEnd/Timeline/Models/Http/UserController.cs | |
parent | 986c6f2e3b858d6332eba0b42acc6861cd4d0227 (diff) | |
download | timeline-05ccb4d8f1bbe3fb64e117136b4a89bcfb0b0b33.tar.gz timeline-05ccb4d8f1bbe3fb64e117136b4a89bcfb0b0b33.tar.bz2 timeline-05ccb4d8f1bbe3fb64e117136b4a89bcfb0b0b33.zip |
Split front and back end.
Diffstat (limited to 'BackEnd/Timeline/Models/Http/UserController.cs')
-rw-r--r-- | BackEnd/Timeline/Models/Http/UserController.cs | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/BackEnd/Timeline/Models/Http/UserController.cs b/BackEnd/Timeline/Models/Http/UserController.cs new file mode 100644 index 00000000..6bc5a66e --- /dev/null +++ b/BackEnd/Timeline/Models/Http/UserController.cs @@ -0,0 +1,93 @@ +using AutoMapper;
+using System.ComponentModel.DataAnnotations;
+using Timeline.Controllers;
+using Timeline.Models.Validation;
+
+namespace Timeline.Models.Http
+{
+ /// <summary>
+ /// Request model for <see cref="UserController.Patch(UserPatchRequest, string)"/>.
+ /// </summary>
+ public class UserPatchRequest
+ {
+ /// <summary>
+ /// New username. Null if not change. Need to be administrator.
+ /// </summary>
+ [Username]
+ public string? Username { get; set; }
+
+ /// <summary>
+ /// New password. Null if not change. Need to be administrator.
+ /// </summary>
+ [MinLength(1)]
+ public string? Password { get; set; }
+
+ /// <summary>
+ /// New nickname. Null if not change. Need to be administrator to change other's.
+ /// </summary>
+ [Nickname]
+ public string? Nickname { get; set; }
+
+ /// <summary>
+ /// Whether to be administrator. Null if not change. Need to be administrator.
+ /// </summary>
+ public bool? Administrator { get; set; }
+ }
+
+ /// <summary>
+ /// Request model for <see cref="UserController.CreateUser(CreateUserRequest)"/>.
+ /// </summary>
+ public class CreateUserRequest
+ {
+ /// <summary>
+ /// Username of the new user.
+ /// </summary>
+ [Required, Username]
+ public string Username { get; set; } = default!;
+
+ /// <summary>
+ /// Password of the new user.
+ /// </summary>
+ [Required, MinLength(1)]
+ public string Password { get; set; } = default!;
+
+ /// <summary>
+ /// Whether the new user is administrator.
+ /// </summary>
+ [Required]
+ public bool? Administrator { get; set; }
+
+ /// <summary>
+ /// Nickname of the new user.
+ /// </summary>
+ [Nickname]
+ public string? Nickname { get; set; }
+ }
+
+ /// <summary>
+ /// Request model for <see cref="UserController.ChangePassword(ChangePasswordRequest)"/>.
+ /// </summary>
+ public class ChangePasswordRequest
+ {
+ /// <summary>
+ /// Old password.
+ /// </summary>
+ [Required(AllowEmptyStrings = false)]
+ public string OldPassword { get; set; } = default!;
+
+ /// <summary>
+ /// New password.
+ /// </summary>
+ [Required(AllowEmptyStrings = false)]
+ public string NewPassword { get; set; } = default!;
+ }
+
+ public class UserControllerAutoMapperProfile : Profile
+ {
+ public UserControllerAutoMapperProfile()
+ {
+ CreateMap<UserPatchRequest, User>(MemberList.Source);
+ CreateMap<CreateUserRequest, User>(MemberList.Source);
+ }
+ }
+}
|