set doctor of communication when doctor logs in

This commit is contained in:
Sem van der Hoeven
2020-10-14 14:49:53 +02:00
parent b519f33cb5
commit 91a20e0af7
5 changed files with 53 additions and 25 deletions

View File

@@ -236,7 +236,7 @@ namespace DoctorApp.Utils
string hashUser = Hashing.Hasher.HashString(username);
string hashPassword = Hashing.Hasher.HashString(password);
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(hashUser, hashPassword));
byte[] message = DataParser.getJsonMessage(DataParser.LoginAsDoctor(hashUser, hashPassword));
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);

View File

@@ -17,6 +17,7 @@ namespace DoctorApp.Utils
public const string SET_RESISTANCE = "SET RESISTANCE";
public const string NEW_CONNECTION = "NEW CONNECTION";
public const string DISCONNECT = "DISCONNECT";
public const string LOGIN_DOCTOR = "LOGIN DOCTOR";
/// <summary>
/// makes the json object with LOGIN identifier and username and password
/// </summary>
@@ -38,6 +39,21 @@ namespace DoctorApp.Utils
return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json));
}
public static byte[] LoginAsDoctor(string mUsername, string mPassword)
{
dynamic json = new
{
identifier = LOGIN_DOCTOR,
data = new
{
username = mUsername,
password = mPassword,
}
};
return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json));
}
public static bool GetUsernamePassword(byte[] jsonbytes, out string username, out string password)
{
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(jsonbytes));