Website Summary Files Commits Branches @commit @diff @stats
path: root / src / DevHive.Data / Models
diff options
context:
space:
mode:
Commit49aa10355280a614da01cebb68c96dfdd602ac6f (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2020-12-16 11:26:32 +0200
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2020-12-16 11:26:32 +0200
Files36a7fdf0d7499c1896272bb1a66aee4ff0b349c2 /src/DevHive.Data/Models
DevHive-49aa10355280a614da01cebb68c96dfdd602ac6f.tar
DevHive-49aa10355280a614da01cebb68c96dfdd602ac6f.tar.gz
DevHive-49aa10355280a614da01cebb68c96dfdd602ac6f.zip
Parentd80b44003ca03cd09bf28278bf2e243581c00332 (diff)
Fixed user input data validation upon registration
1 files changed, 3 insertions, 36 deletions
-rw-r--r--src/DevHive.Data/Models/User.cs39
diff --git a/src/DevHive.Data/Models/User.cs b/src/DevHive.Data/Models/User.cs
index a92e94d..75015e8 100644
--- a/src/DevHive.Data/Models/User.cs
+++ b/src/DevHive.Data/Models/User.cs
@@ -8,60 +8,27 @@ namespace DevHive.Data.Models
[Table("Users")]
public class User : IdentityUser<Guid>, IModel
{
- private string _firstName;
- private string _lastName;
-
[Required]
[Range(3, 50)]
[Display(Name = "Username")]
public override string UserName
{
get => base.UserName;
- set
- {
- ValidateString("Username", 3, 50, value, true);
- base.UserName = value;
- }
+ set => base.UserName = value;
}
[Required]
[Range(3, 30)]
- public string FirstName
- {
- get => this._firstName;
- set
- {
- ValidateString("FirstName", 3, 30, value, false);
- this._firstName = value;
- }
- }
+ public string FirstName { get; set; }
[Required]
[Range(3, 30)]
- public string LastName
- {
- get => this._lastName;
- set
- {
- ValidateString("LastName", 3, 30, value, false);
- this._lastName = value;
- }
- }
+ public string LastName { get; set; }
public string ProfilePicture { get; set; }
public string Role { get; set; }
//public List<User> Friends { get; set; }
-
- private static void ValidateString(string propertyName, int minLength, int maxLength, string value, bool canBeDigit)
- {
- if (value.Length < minLength || value.Length > maxLength)
- throw new ArgumentException($"{propertyName} length cannot be less than {minLength} and more than {maxLength}.");
-
- foreach (char ch in value)
- if (!Char.IsLetter(ch) && !(Char.IsDigit(ch) && canBeDigit))
- throw new ArgumentException($"{propertyName} contains invalid characters.");
- }
}
}