This commit is contained in:
MarcEricMartel
2022-11-06 09:10:41 -08:00
parent 550239ca61
commit 107c68eb4e
5 changed files with 49 additions and 7 deletions

View File

@@ -40,13 +40,33 @@ public class UserController : Controller {
#region API Methods
[HttpPost, AllowAnonymous]
public ActionResult<ReturnUserViewModel> Post(SignUpUserModel sign) {
int x = 0;
InventoryUser usr;
try {
usr = new(sign);
usr = new() {
FirstName = sign.FirstName,
LastName = sign.LastName,
Email = sign.Email,
PhoneNumber = sign.Phone
};
} catch (Exception e){
return BadRequest($"Erreur utilisateur: {e.Message}");
}
try {
usr.Adresses.Add(new AddressModel() {
CivicNumber = sign.CivicNumber,
Appartment = sign.Appartment,
Street = sign.Street,
City = sign.City,
Province = sign.Province,
Country = sign.Country,
PostalCode = sign.PostalCode
});
} catch (Exception e) {
return BadRequest($"Erreur adresse: {e.Message}");
}
try {
usr.PasswordHash = new PasswordHasher<InventoryUser>().HashPassword(usr, sign.Password);
} catch (Exception e){

View File

@@ -19,7 +19,6 @@ public class InventoryUser : IdentityUser {
NormalizedEmail = sign.Email.ToUpper();
Email = sign.Email;
PhoneNumber = sign.Phone;
Adresses = sign.Adresses;
}
}

View File

@@ -12,6 +12,19 @@ public class SignUpUserModel {
public string Phone { get; set; }
[Required]
public string Password { get; set; }
public List<AddressModel> Adresses { get; set; }
[Required, Range(1, int.MaxValue)]
public int CivicNumber { get; set; }
public string? Appartment { get; set; }
[Required, MinLength(3), MaxLength(50)]
public string Street { get; set; }
[Required, MinLength(4), MaxLength(50)]
public string City { get; set; }
[Required, MaxLength(3)]
public string Province { get; set; }
[Required, MinLength(4), MaxLength(30)]
public string Country { get; set; }
// Source pour regex: https://stackoverflow.com/questions/15774555/efficient-regex-for-canadian-postal-code-function
//[Required, RegularExpression(@"/^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ -]?\d[ABCEGHJ-NPRSTV-Z]\d$/i")] TODO: REGEX
public string PostalCode { get; set; }
}