blob: 6bc5a66ea8a32d9645fcdc1fa25f461143532297 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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);
}
}
}
|