diff --git a/FIT5032-Assignment/Controllers/HomeController.cs b/FIT5032-Assignment/Controllers/HomeController.cs index cad3f24..f0352d9 100644 --- a/FIT5032-Assignment/Controllers/HomeController.cs +++ b/FIT5032-Assignment/Controllers/HomeController.cs @@ -23,6 +23,7 @@ using System.Net.Http.Headers; namespace FIT5032_Assignment.Controllers { + // Endpoint Response public class PassageUserReply { @@ -40,9 +41,26 @@ namespace FIT5032_Assignment.Controllers public DbSet Users { get; set; } public DbSet Credentials { get; set; } public DbSet Sessions { get; set; } + public DbSet Patients { get; set; } + public DbSet Doctors { get; set; } } public class HomeController : Controller { + public static string GetMd5Hash(string input) + { + using (MD5 md5 = MD5.Create()) + { + byte[] data = md5.ComputeHash(Encoding.UTF8.GetBytes(input)); + + StringBuilder sBuilder = new StringBuilder(); + for (int i = 0; i < data.Length; i++) + { + sBuilder.Append(data[i].ToString("x2")); + } + + return sBuilder.ToString(); + } + } private static readonly HttpClient httpClient = new HttpClient(); public static RsaSecurityKey LoadRsaSecurityKeyFromPem(string pem) { @@ -200,15 +218,8 @@ namespace FIT5032_Assignment.Controllers string emailaddress = JsonConvert.DeserializeObject(res).User.Email; // MD5 hash email to get avatar from gravatar - var md5 = MD5.Create(); - byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(emailaddress); - byte[] hash = md5.ComputeHash(inputBytes); - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < hash.Length; i++) - { - sb.Append(hash[i].ToString("X2")); // X2 means uppercase - } - string avatarUrl = "https://www.gravatar.com/avatar/" + sb.ToString(); + string md5Email = GetMd5Hash(emailaddress); + string avatarUrl = "https://www.gravatar.com/avatar/" + md5Email; // Create a new credential and a new user string userUuid = Guid.NewGuid().ToString(); @@ -232,6 +243,28 @@ namespace FIT5032_Assignment.Controllers db.Credentials.Add(credential); db.SaveChanges(); + if (model.role == "1") + { + // Create patient profile + db.Patients.Add(new Patients + { + phone = "", + address = "", + user = userUuid, + notes = "" + }); + db.SaveChanges(); + } + else + { + db.Doctors.Add(new Doctors + { + user = userUuid, + bio = "", + }); + db.SaveChanges(); + } + return RedirectToAction("Index"); }