Exemple #1
0
 public ActionResult PharmacySelect(int pharmacy)
 {
     User.setPharmacy(pharmacy);
     if (pharmacy > -1)
     {
         using (var service = new PharmacistService())
         {
             var pharmacist           = service.GetWhere(PharmacistService.EmailCol == User.Email).FirstOrDefault();
             var serializedPharmacist = new PPOKPrincipalSerializeModel(pharmacist, pharmacy);
             //serializedPharmacist.Pharmacy = User.Pharmacy;
             makeAuthTicket(serializedPharmacist);
         }
         return(RedirectToAction("Index", "LandingPage"));
     }
     else
     {
         using (var service = new SystemAdminService())
         {
             var admin           = service.GetWhere(SystemAdminService.EmailCol == User.Email).FirstOrDefault();
             var serializedAdmin = new PPOKPrincipalSerializeModel(admin);
             serializedAdmin.Pharmacy = User.Pharmacy;
             makeAuthTicket(serializedAdmin);
         }
         return(RedirectToAction("Index", "SystemAdmin"));
     }
 }
Exemple #2
0
 public static Pharmacist SendPharmacistToken(string email, string token)
 {
     using (var service = new PharmacistService())
     {
         var pharmacist = service.GetWhere(PharmacistService.EmailCol == email).FirstOrDefault();
         if (pharmacist != null)
         {
             using (var tokenService = new PharmacistTokenService())
             {
                 var storedToken = tokenService.GetWhere(PharmacistTokenService.PharmacistCodeCol == pharmacist.Code).FirstOrDefault();
                 if (storedToken == null)
                 {
                     tokenService.Create(new PharmacistToken(pharmacist, token));
                 }
                 else
                 {
                     storedToken.Token   = token;
                     storedToken.Expires = DateTime.Now.ToUniversalTime().AddHours(Config.TokenDuration);
                     tokenService.Update(storedToken);
                 }
             }
             AddSystemAdminToken(email, token);
             TwilioService.SendSMSMessage(pharmacist.Phone, "Please enter this token to login: " + token);
         }
         return(pharmacist);
     }
 }
        public ActionResult AddPharmacist(int PharmacyCode, string FirstName, string LastName, string Email, string Phone, bool IsAdmin = false, bool IsActive = false)
        {
            using (var service = new PharmacistService())
            {
                Phone = Regex.Replace(Phone, @"[^A-Za-z0-9]+", "");
                if (Phone.Length == 10)
                {
                    Phone = "1" + Phone;
                }
                Pharmacist p = service.GetWhere(PharmacistService.EmailCol == Email).FirstOrDefault();
                if (p == null)
                {
                    p = new Pharmacist(FirstName, LastName, Email, Phone, new byte[] { 0 }, new byte[] { 0 });
                    service.Create(p);
                }


                Pharmacy pharm;
                using (var pharmservice = new PharmacyService())
                {
                    pharm = pharmservice.Get(PharmacyCode);
                }
                using (var jobservice = new JobService())
                {
                    Job j = new Job(pharm, p, IsActive, IsAdmin);
                    jobservice.Create(j);
                }
            }
            using (var service = new EmailService())
            {
                service.SendEmail(Email, newAccountEmailSubject, newAccountEmailBody);
            }
            return(RedirectToAction("SinglePharmacy", new RouteValueDictionary(
                                        new { controller = "SystemAdmin", action = "SinglePharmacy", Id = PharmacyCode })));
        }
Exemple #4
0
 public LoginModel(string email)
 {
     pharmacyList = new List <Pharmacy>();
     using (var service = new PharmacistService())
     {
         var pharmacist = service.GetWhere(PharmacistService.EmailCol == email).FirstOrDefault();
         if (pharmacist != null)
         {
             var jobs = pharmacist.Jobs;
             foreach (var job in jobs)
             {
                 var pharmacy = job.Pharmacy;
                 pharmacyList.Add(job.Pharmacy);
             }
         }
     }
     using (var service = new SystemAdminService())
     {
         var admin = service.GetWhere(SystemAdminService.EmailCol == email).FirstOrDefault();
         if (admin != null)
         {
             pharmacyList.Add(new Pharmacy(-1, "System Admin", "000-000-0000", "no address"));
         }
     }
 }
        public ActionResult AddPharmacist(string FirstName, string LastName, string Email, string Phone, bool IsActive = false, bool IsAdmin = false)
        {
            Phone = Regex.Replace(Phone, @"[^A-Za-z0-9]+", "");
            if (Phone.Length == 10)
            {
                Phone = "1" + Phone;
            }
            using (var service = new PharmacistService())
            {
                Pharmacist p = service.GetWhere(PharmacistService.EmailCol == Email).FirstOrDefault();
                if (p == null)
                {
                    new Pharmacist(FirstName, LastName, Email, Phone, new byte[] { 0 }, new byte[] { 0 });
                    service.Create(p);
                }

                Pharmacy pharm;
                using (var pharmservice = new PharmacyService())
                {
                    pharm = pharmservice.Get(User.getPharmacy().Code);
                }

                using (var jobservice = new JobService())
                {
                    //these get the value, not the checked value
                    Job j = new Job(pharm, p, IsActive, IsAdmin);
                    jobservice.Create(j);
                }

                return(RedirectToAction("Pharmacy", new RouteValueDictionary(
                                            new { controller = "ManagePharmacist", action = "Pharmacy", Id = User.Pharmacy.Code })));
            }
        }
Exemple #6
0
        public ActionResult Login(string email, string password)
        {
            if (PPOKPrincipal.IsValid(email, password))
            {
                using (var PharmService = new PharmacistService())
                    using (var SysService = new SystemAdminService())
                    {
                        Pharmacist  pharmacist = PharmService.GetWhere(PharmacistService.EmailCol == email).FirstOrDefault();
                        SystemAdmin admin      = SysService.GetWhere(SystemAdminService.EmailCol == email).FirstOrDefault();
                        var         logins     = new LoginModel(email);

                        if (logins.pharmacyList.Count > 1)
                        {
                            if (admin != null)
                            {
                                makeAuthTicket(new PPOKPrincipalSerializeModel(admin));
                            }
                            else
                            {
                                makeAuthTicket(new PPOKPrincipalSerializeModel(pharmacist));
                            }
                            return(View("PharmacySelect", logins));
                        }
                        else if (admin != null)
                        {
                            var serializedAdmin = new PPOKPrincipalSerializeModel(admin);
                            makeAuthTicket(serializedAdmin);
                            return(RedirectToAction("Index", "SystemAdmin"));
                        }
                        else if (pharmacist != null)
                        {
                            var serializedPharmacist = new PPOKPrincipalSerializeModel(pharmacist);
                            makeAuthTicket(serializedPharmacist);
                            return(RedirectToAction("Index", "LandingPage"));
                        }
                    }
            }
            ViewBag.Error = "Invalid username/password combination";
            return(View("Index"));
        }
Exemple #7
0
        public static bool IsValid(string email, string password)
        {
            using (var db = new PharmacistService())
                using (var adminDB = new SystemAdminService())
                {
                    var pharmacist = db.GetWhere(PharmacistService.EmailCol == email).FirstOrDefault();
                    var admin      = adminDB.GetWhere(SystemAdminService.EmailCol == email).FirstOrDefault();
                    if (pharmacist == null && admin == null)
                    {
                        return(false);
                    }

                    if (admin != null)
                    {
                        return(CompareByteArrays(admin.PasswordHash, GenerateSaltedHash(Encoding.ASCII.GetBytes(password), admin.PasswordSalt)));
                    }
                    if (pharmacist != null)
                    {
                        return(CompareByteArrays(pharmacist.PasswordHash, GenerateSaltedHash(Encoding.ASCII.GetBytes(password), pharmacist.PasswordSalt)));
                    }
                    return(false);
                }
        }