Esempio n. 1
0
 public static Patient SendPatientToken(string phone, string token)
 {
     using (var service = new PatientService())
     {
         var patient = service.GetWhere(PatientService.PhoneCol == phone).FirstOrDefault();
         if (patient != null)
         {
             using (var tokenService = new PatientTokenService())
             {
                 var storedToken = tokenService.GetWhere(PatientTokenService.PatientCodeCol == patient.Code).FirstOrDefault();
                 if (storedToken == null)
                 {
                     tokenService.Create(new PatientToken(patient, token));
                 }
                 else
                 {
                     storedToken.Token   = token;
                     storedToken.Expires = DateTime.Now.ToUniversalTime().AddHours(Config.TokenDuration);
                     tokenService.Update(storedToken);
                 }
             }
             TwilioService.SendSMSMessage(patient.Phone, "Please enter this token to login: " + token);
         }
         return(patient);
     }
 }
Esempio n. 2
0
 public static Patient VerifyPatientToken(string token)
 {
     using (var service = new PatientTokenService())
     {
         var patientToken = service.GetWhere(PatientTokenService.TokenCol == token).FirstOrDefault();
         if (patientToken != null && patientToken.Expires > DateTime.Now.ToUniversalTime())
         {
             service.Delete(patientToken.Code);
             return(patientToken.Patient);
         }
         return(null);
     }
 }