Merge branch 'react-version' of https://github.com/MarcEricMartel/420-5DW-HY-TP into react-version
This commit is contained in:
commit
481e2ad858
@ -40,13 +40,33 @@ public class UserController : Controller {
|
|||||||
#region API Methods
|
#region API Methods
|
||||||
[HttpPost, AllowAnonymous]
|
[HttpPost, AllowAnonymous]
|
||||||
public ActionResult<ReturnUserViewModel> Post(SignUpUserModel sign) {
|
public ActionResult<ReturnUserViewModel> Post(SignUpUserModel sign) {
|
||||||
|
int x = 0;
|
||||||
InventoryUser usr;
|
InventoryUser usr;
|
||||||
try {
|
try {
|
||||||
usr = new(sign);
|
usr = new() {
|
||||||
|
FirstName = sign.FirstName,
|
||||||
|
LastName = sign.LastName,
|
||||||
|
Email = sign.Email,
|
||||||
|
PhoneNumber = sign.Phone
|
||||||
|
};
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
return BadRequest($"Erreur utilisateur: {e.Message}");
|
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 {
|
try {
|
||||||
usr.PasswordHash = new PasswordHasher<InventoryUser>().HashPassword(usr, sign.Password);
|
usr.PasswordHash = new PasswordHasher<InventoryUser>().HashPassword(usr, sign.Password);
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
|
@ -19,7 +19,6 @@ public class InventoryUser : IdentityUser {
|
|||||||
NormalizedEmail = sign.Email.ToUpper();
|
NormalizedEmail = sign.Email.ToUpper();
|
||||||
Email = sign.Email;
|
Email = sign.Email;
|
||||||
PhoneNumber = sign.Phone;
|
PhoneNumber = sign.Phone;
|
||||||
Adresses = sign.Adresses;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,19 @@ public class SignUpUserModel {
|
|||||||
public string Phone { get; set; }
|
public string Phone { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string Password { get; set; }
|
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; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import { useCookies } from "react-cookie";
|
|||||||
const Topbar = () => {
|
const Topbar = () => {
|
||||||
const [cookies, setCookie, removeCookie] = useCookies(['name']);
|
const [cookies, setCookie, removeCookie] = useCookies(['name']);
|
||||||
const [user, setLogin] = useState(null);
|
const [user, setLogin] = useState(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function reset() {
|
async function reset() {
|
||||||
await setLogin(await cookies.GMGM ?? null);
|
await setLogin(await cookies.GMGM ?? null);
|
||||||
@ -22,9 +23,8 @@ const Topbar = () => {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'include'
|
credentials: 'include'
|
||||||
})
|
})
|
||||||
|
await removeCookie("GMGM");
|
||||||
await removeCookie("GMGM");
|
await setLogin(null); // Y U NO WORK?!?
|
||||||
await setLogin(null); // Y U NO WORK?!?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -25,7 +25,17 @@ import { useForm } from "react-hook-form";
|
|||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const { register, handleSubmit, watch, formState: { errors } } = useForm();
|
const { register, handleSubmit, watch, formState: { errors } } = useForm();
|
||||||
const onSubmit = data => console.log(data);
|
const onSubmit = data => {
|
||||||
|
const response = fetch(`https://localhost:7292/api/User`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'text/json',
|
||||||
|
'Content-Type': 'text/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className="inventaire-form-container">
|
<div className="inventaire-form-container">
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
Loading…
Reference in New Issue
Block a user