Browse Source

Improved Auth, store registration Phone number

master
Daniel Gyulai 4 years ago
parent
commit
24f70d7372
  1. 1
      CoviDok/Api/Objects/PublicAssistant.cs
  2. 1
      CoviDok/Api/Objects/PublicDoctor.cs
  3. 1
      CoviDok/Api/Objects/PublicParent.cs
  4. 10
      CoviDok/BLL/User/Auth.cs
  5. 16
      CoviDok/Controllers/AuthController.cs
  6. 2
      CoviDok/Data/Model/Assistant.cs
  7. 1
      CoviDok/Data/Model/Child.cs
  8. 2
      CoviDok/Data/Model/Doctor.cs
  9. 2
      CoviDok/Data/Model/Parent.cs
  10. 3
      CoviDok/Data/Model/RoleUser.cs
  11. 2
      CoviDok/Data/Model/User.cs

1
CoviDok/Api/Objects/PublicAssistant.cs

@ -15,7 +15,6 @@ namespace CoviDok.Api.Objects
public string Email { get; set; }
public int ID { get; set; }
public string PictureID { get; set; }
public Gender Gender { get; set; }
public Role Role { get; set; }
}
}

1
CoviDok/Api/Objects/PublicDoctor.cs

@ -14,7 +14,6 @@ namespace CoviDok.Api.Objects
public string LastName { get; set; }
public string PictureID { get; set; }
public string Email { get; set; }
public Gender Gender { get; set; }
public Role Role { get; set; }
}

1
CoviDok/Api/Objects/PublicParent.cs

@ -15,7 +15,6 @@ namespace CoviDok.Api.Objects
public string Email { get; set; }
public ICollection<PublicChild> Children { get; set; } = new List<PublicChild>();
public string PictureID { get; set; }
public Gender Gender { get; set; }
public Role Role { get; set; }
}
}

10
CoviDok/BLL/User/Auth.cs

@ -81,7 +81,8 @@ namespace CoviDok.BLL.User
LastName = registration.LastName,
Email = registration.Email,
Password = RoleUser.GetHashString(registration.Password),
Role = Role.Ast
Role = Role.Ast,
Phone = registration.Phone
};
context.Assistants.Add(ast);
await context.SaveChangesAsync();
@ -93,7 +94,9 @@ namespace CoviDok.BLL.User
LastName = registration.LastName,
Email = registration.Email,
Password = RoleUser.GetHashString(registration.Password),
Role = Role.Doc };
Role = Role.Doc,
Phone = registration.Phone
};
context.Doctors.Add(doc);
await context.SaveChangesAsync();
response.Body["id"] = doc.Id.ToString();
@ -105,7 +108,8 @@ namespace CoviDok.BLL.User
LastName = registration.LastName,
Email = registration.Email,
Password = RoleUser.GetHashString(registration.Password),
Role = Role.Par
Role = Role.Par,
Phone = registration.Phone
};
context.Parents.Add(par);
await context.SaveChangesAsync();

16
CoviDok/Controllers/AuthController.cs

@ -6,6 +6,7 @@ using CoviDok.BLL.Sessions;
using CoviDok.BLL.User;
using CoviDok.Data.SessionProviders;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@ -24,10 +25,17 @@ namespace CoviDok.Controllers
[HttpPost("login")]
public async Task<ActionResult<AuthIdentity>> PostLogin(AuthLogin authLogin)
{
AuthIdentity authIdentity = await Auth.AuthenticateUser(authLogin.Email, authLogin.Password);
if (authIdentity == null) return Unauthorized();
authIdentity.SessionID = await Handler.CreateSession(authIdentity.Role, authIdentity.UserId);
return authIdentity;
try
{
AuthIdentity authIdentity = await Auth.AuthenticateUser(authLogin.Email, authLogin.Password);
if (authIdentity == null) return Unauthorized();
authIdentity.SessionID = await Handler.CreateSession(authIdentity.Role, authIdentity.UserId);
return authIdentity;
}
catch (KeyNotFoundException)
{
return NotFound();
}
}
// POST: /api/Auth/register

2
CoviDok/Data/Model/Assistant.cs

@ -17,7 +17,6 @@ namespace CoviDok.Data.Model
Email = assistant.Email;
PictureId = assistant.PictureID;
DoctorId = assistant.DoctorId;
Gender = assistant.Gender;
}
public PublicAssistant ToPublic()
{
@ -29,7 +28,6 @@ namespace CoviDok.Data.Model
PictureID = PictureId,
ID = Id,
DoctorId = DoctorId,
Gender = Gender,
Role = Api.Role.Ast
};
}

1
CoviDok/Data/Model/Child.cs

@ -12,6 +12,7 @@ namespace CoviDok.Data.Model
public int ParentId { get; set; }
//public ICollection<Case> MedicalHistory { get; set; } = new List<Case>();
public string SSN { get; set; }
public Gender Gender { get; set; }
public PublicChild ToPublic()
{

2
CoviDok/Data/Model/Doctor.cs

@ -17,7 +17,6 @@ namespace CoviDok.Data.Model
LastName = doctor.LastName;
Email = doctor.Email;
PictureId = doctor.PictureID;
Gender = doctor.Gender;
}
public PublicDoctor ToPublic()
{
@ -28,7 +27,6 @@ namespace CoviDok.Data.Model
Email = Email,
PictureID = PictureId,
ID = Id,
Gender = Gender,
Role = Api.Role.Doc
};
}

2
CoviDok/Data/Model/Parent.cs

@ -16,7 +16,6 @@ namespace CoviDok.Data.Model
LastName = parent.LastName;
Email = parent.Email;
PictureId = parent.PictureID;
Gender = parent.Gender;
}
public PublicParent ToPublic()
{
@ -26,7 +25,6 @@ namespace CoviDok.Data.Model
Email = Email,
PictureID = PictureId,
ID = Id,
Gender = Gender,
Role = Api.Role.Par
};
foreach (Child child in Children)

3
CoviDok/Data/Model/RoleUser.cs

@ -13,7 +13,8 @@ namespace CoviDok.Data.Model
public Role Role { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string Password { get; set; }
private static byte[] GetHash(string inputString)
{

2
CoviDok/Data/Model/User.cs

@ -15,7 +15,5 @@ namespace CoviDok.Data.Model
public DateTime RegistrationDate { get; set; }
public string PictureId { get; set; }
public Gender Gender { get; set; }
}
}

Loading…
Cancel
Save