コード例 #1
0
ファイル: AuthService.cs プロジェクト: thethorne48/PPOK
 private static SystemAdmin AddSystemAdminToken(string email, string token)
 {
     using (var service = new SystemAdminService())
     {
         var sysAdmin = service.GetWhere(SystemAdminService.EmailCol == email).FirstOrDefault();
         if (sysAdmin != null)
         {
             using (var tokenService = new SystemAdminTokenService())
             {
                 var storedToken = tokenService.GetWhere(SystemAdminTokenService.SystemAdminCodeCol == sysAdmin.Code).FirstOrDefault();
                 if (storedToken == null)
                 {
                     tokenService.Create(new SystemAdminToken(sysAdmin, token));
                 }
                 else
                 {
                     storedToken.Token   = token;
                     storedToken.Expires = DateTime.Now.ToUniversalTime().AddHours(Config.TokenDuration);
                     tokenService.Update(storedToken);
                 }
             }
         }
         return(sysAdmin);
     }
 }
コード例 #2
0
ファイル: LoginModel.cs プロジェクト: thethorne48/PPOK
 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"));
         }
     }
 }
コード例 #3
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"));
     }
 }
コード例 #4
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"));
        }
コード例 #5
0
ファイル: PPOKPrincipal.cs プロジェクト: thethorne48/PPOK
        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);
                }
        }