Bug fixes

This commit is contained in:
Astrian Zheng 2023-09-15 17:45:40 +10:00
parent 007d56ee32
commit 8555927086

View File

@ -23,6 +23,7 @@ using System.Net.Http.Headers;
namespace FIT5032_Assignment.Controllers namespace FIT5032_Assignment.Controllers
{ {
// Endpoint Response // Endpoint Response
public class PassageUserReply public class PassageUserReply
{ {
@ -40,9 +41,26 @@ namespace FIT5032_Assignment.Controllers
public DbSet<Users> Users { get; set; } public DbSet<Users> Users { get; set; }
public DbSet<Credentials> Credentials { get; set; } public DbSet<Credentials> Credentials { get; set; }
public DbSet<Sessions> Sessions { get; set; } public DbSet<Sessions> Sessions { get; set; }
public DbSet<Patients> Patients { get; set; }
public DbSet<Doctors> Doctors { get; set; }
} }
public class HomeController : Controller 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(); private static readonly HttpClient httpClient = new HttpClient();
public static RsaSecurityKey LoadRsaSecurityKeyFromPem(string pem) public static RsaSecurityKey LoadRsaSecurityKeyFromPem(string pem)
{ {
@ -200,15 +218,8 @@ namespace FIT5032_Assignment.Controllers
string emailaddress = JsonConvert.DeserializeObject<PassageUserReply>(res).User.Email; string emailaddress = JsonConvert.DeserializeObject<PassageUserReply>(res).User.Email;
// MD5 hash email to get avatar from gravatar // MD5 hash email to get avatar from gravatar
var md5 = MD5.Create(); string md5Email = GetMd5Hash(emailaddress);
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(emailaddress); string avatarUrl = "https://www.gravatar.com/avatar/" + md5Email;
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();
// Create a new credential and a new user // Create a new credential and a new user
string userUuid = Guid.NewGuid().ToString(); string userUuid = Guid.NewGuid().ToString();
@ -232,6 +243,28 @@ namespace FIT5032_Assignment.Controllers
db.Credentials.Add(credential); db.Credentials.Add(credential);
db.SaveChanges(); 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"); return RedirectToAction("Index");
} }