diff options
author | crupest <crupest@outlook.com> | 2020-01-29 23:13:15 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-01-29 23:13:15 +0800 |
commit | abde51b167f17301c25e32ae247e7909c0dc9367 (patch) | |
tree | c9131a7b95fffd64bf2c26527d7f62fbdefa7e2c /Timeline/Models | |
parent | 81c261b59016e15d320ad963882afe4d9c7b5f7d (diff) | |
download | timeline-abde51b167f17301c25e32ae247e7909c0dc9367.tar.gz timeline-abde51b167f17301c25e32ae247e7909c0dc9367.tar.bz2 timeline-abde51b167f17301c25e32ae247e7909c0dc9367.zip |
...
Diffstat (limited to 'Timeline/Models')
-rw-r--r-- | Timeline/Models/Http/User.cs | 41 | ||||
-rw-r--r-- | Timeline/Models/Http/UserController.cs | 27 | ||||
-rw-r--r-- | Timeline/Models/PutResult.cs | 17 | ||||
-rw-r--r-- | Timeline/Models/User.cs | 20 | ||||
-rw-r--r-- | Timeline/Models/UserRoleConvert.cs | 44 |
5 files changed, 27 insertions, 122 deletions
diff --git a/Timeline/Models/Http/User.cs b/Timeline/Models/Http/User.cs deleted file mode 100644 index b3812f48..00000000 --- a/Timeline/Models/Http/User.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System;
-using System.ComponentModel.DataAnnotations;
-using Timeline.Models.Validation;
-
-namespace Timeline.Models.Http
-{
- [Obsolete("Remove this.")]
- public class UserPutRequest
- {
- [Required]
- public string Password { get; set; } = default!;
- [Required]
- public bool? Administrator { get; set; }
- }
-
- [Obsolete("Remove this.")]
- public class UserPatchRequest
- {
- public string? Password { get; set; }
- public bool? Administrator { get; set; }
- }
-
- public class ChangeUsernameRequest
- {
- [Required]
- [Username]
- public string OldUsername { get; set; } = default!;
-
- [Required]
- [Username]
- public string NewUsername { get; set; } = default!;
- }
-
- public class ChangePasswordRequest
- {
- [Required]
- public string OldPassword { get; set; } = default!;
- [Required]
- public string NewPassword { get; set; } = default!;
- }
-}
diff --git a/Timeline/Models/Http/UserController.cs b/Timeline/Models/Http/UserController.cs new file mode 100644 index 00000000..229ca1e5 --- /dev/null +++ b/Timeline/Models/Http/UserController.cs @@ -0,0 +1,27 @@ +using System.ComponentModel.DataAnnotations;
+using Timeline.Models.Validation;
+
+namespace Timeline.Models.Http
+{
+ public class UserPatchRequest
+ {
+ [Username]
+ public string? Username { get; set; }
+
+ [MinLength(1)]
+ public string? Password { get; set; }
+
+ [Nickname]
+ public string? Nickname { get; set; }
+
+ public bool? Administrator { get; set; }
+ }
+
+ public class ChangePasswordRequest
+ {
+ [Required(AllowEmptyStrings = false)]
+ public string OldPassword { get; set; } = default!;
+ [Required(AllowEmptyStrings = false)]
+ public string NewPassword { get; set; } = default!;
+ }
+}
diff --git a/Timeline/Models/PutResult.cs b/Timeline/Models/PutResult.cs deleted file mode 100644 index cecf86e6..00000000 --- a/Timeline/Models/PutResult.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Timeline.Models
-{
- /// <summary>
- /// Represents the result of a "put" operation.
- /// </summary>
- public enum PutResult
- {
- /// <summary>
- /// Indicates the item did not exist and now is created.
- /// </summary>
- Create,
- /// <summary>
- /// Indicates the item exists already and is modified.
- /// </summary>
- Modify
- }
-}
diff --git a/Timeline/Models/User.cs b/Timeline/Models/User.cs deleted file mode 100644 index 2cead892..00000000 --- a/Timeline/Models/User.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Timeline.Models.Validation;
-
-namespace Timeline.Models
-{
- public class User
- {
- [Username]
- public string? Username { get; set; }
- public bool? Administrator { get; set; }
- public string? Nickname { get; set; }
- public string? AvatarUrl { get; set; }
-
-
- #region secret
- public long? Id { get; set; }
- public string? Password { get; set; }
- public long? Version { get; set; }
- #endregion secret
- }
-}
diff --git a/Timeline/Models/UserRoleConvert.cs b/Timeline/Models/UserRoleConvert.cs deleted file mode 100644 index ade9a799..00000000 --- a/Timeline/Models/UserRoleConvert.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-using Timeline.Entities;
-
-namespace Timeline.Models
-{
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "No need.")]
- public static class UserRoleConvert
- {
- public const string UserRole = UserRoles.User;
- public const string AdminRole = UserRoles.Admin;
-
- public static string[] ToArray(bool administrator)
- {
- return administrator ? new string[] { UserRole, AdminRole } : new string[] { UserRole };
- }
-
- public static string[] ToArray(string s)
- {
- return s.Split(',').ToArray();
- }
-
- public static bool ToBool(IReadOnlyCollection<string> roles)
- {
- return roles.Contains(AdminRole);
- }
-
- public static string ToString(IReadOnlyCollection<string> roles)
- {
- return string.Join(',', roles);
- }
-
- public static string ToString(bool administrator)
- {
- return administrator ? UserRole + "," + AdminRole : UserRole;
- }
-
- public static bool ToBool(string s)
- {
- return s.Contains("admin", StringComparison.InvariantCulture);
- }
- }
-}
|