public async Task <bool> CanUserLogin(LoginForm loginUser, UserRoleTypes userRole)
        {
            if (userRole == UserRoleTypes.CUSTOMER)
            {
                Customer customer = await GetCustomerByEmail(loginUser.Email);

                string inputPassword = HashedPasswordWithSalt.getHash(loginUser.Password, customer.Salt);
                if (customer.Password == inputPassword)
                {
                    return(true);
                }
            }
            else if (userRole == UserRoleTypes.DRIVER)
            {
                Driver driver = await GetDriverByEmail(loginUser.Email);

                string inputPassword = HashedPasswordWithSalt.getHash(loginUser.Password, driver.Salt);
                if (driver.Password == inputPassword)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #2
0
        public ActionResult Index()
        {
            UserProfile   currentUser     = GetCurrentUser();
            UserRoleTypes currentUserRole = (UserRoleTypes)currentUser.RoleId;

            string redirectAction = "Index";

            switch (currentUserRole)
            {
            case UserRoleTypes.Applicant:
                redirectAction = "SearchJobs";
                break;

            case UserRoleTypes.Company:
                redirectAction = "SearchApplicants";
                break;

            case UserRoleTypes.Admin:
                break;

            default:
                break;
            }

            return(RedirectToAction(redirectAction));
        }
예제 #3
0
        public bool IsUserRoleForCHGSite(long userId, long CHGSiteId, long roleId)
        {
            var roleEntity = UserRoleTypes.Find(roleId);

            //Check for CRO
            if (roleEntity.Name == "CRO")
            {
                return(true);
            }

            //Check for CAC
            if (roleEntity.Name == "CAC")
            {
                return(true);
            }

            //Check for CEO and DBD
            if (roleEntity.Name == "CEO" || roleEntity.Name == "DBD")
            {
                return(UserCHGSites.Where(p => p.UserId == UserId && p.Deleted == false && p.CHGSiteId == CHGSiteId).Count() > 0);
            }


            var items = (
                from os in OrganizationServiceTypes
                join rs in RegionServiceTypes on os.ServiceTypeId equals rs.ServiceTypeId
                join s in CHGSites on rs.RegionTypeId equals s.RegionTypeId
                where
                os.Deleted == false &&
                rs.Deleted == false &&
                s.Deleted == false
                select new
            {
                OrganizationId = os.OrganizationId,
                ServiceTypeId = os.ServiceTypeId,
                RegionTypeId = rs.RegionTypeId,
                CHGSiteId = s.CHGSiteId
            }).ToList();

            //Check for AVP
            if (roleEntity.Name == "AVP")
            {
                return((from c in UserRegions.Where(p => p.Deleted == false).ToList() join ur in UserRoles on c.UserId equals ur.UserId join i in items on c.RegionTypeId equals i.RegionTypeId where c.Deleted == false && c.UserId == userId && i.CHGSiteId == CHGSiteId && ur.User.Deleted == false && ur.User.Enabled == true && ur.UserRoleTypeId == roleId select c).Count() > 0);
            }

            //Add more permission checks here.

            return(false);
        }
예제 #4
0
        public List <User> GetRoleUsersForCHGSite(long CHGSiteId, long roleId)
        {
            var roleEntity = UserRoleTypes.Find(roleId);

            //Check for CRO
            if (roleEntity.Name == "CRO")
            {
                return(UserRoles.Include("UserRoleType").Include("User").Where(p => p.Deleted == false && p.UserRoleType.Name == "CRO" && p.User.Deleted == false && p.User.Enabled == true).Select(p => p.User).ToList());
            }

            if (roleEntity.Name == "CAC")
            {
                return(UserRoles.Include("UserRoleType").Include("User").Where(p => p.Deleted == false && p.UserRoleType.Name == "CAC" && p.User.Deleted == false && p.User.Enabled == true).Select(p => p.User).ToList());
            }


            if (roleEntity.Name == "CEO" || roleEntity.Name == "DBD")
            {
                return((from ur in UserRoles join us in UserCHGSites on ur.UserId equals us.UserId where us.Deleted == false && ur.Deleted == false && ur.UserRoleTypeId == roleId && us.CHGSiteId == CHGSiteId && us.User.Deleted == false && us.User.Enabled == true select us.User).Distinct().ToList());
            }


            var items = (
                from os in OrganizationServiceTypes
                join rs in RegionServiceTypes on os.ServiceTypeId equals rs.ServiceTypeId
                join s in CHGSites on rs.RegionTypeId equals s.RegionTypeId
                where
                os.Deleted == false &&
                rs.Deleted == false &&
                s.Deleted == false
                select new
            {
                OrganizationId = os.OrganizationId,
                ServiceTypeId = os.ServiceTypeId,
                RegionTypeId = rs.RegionTypeId,
                CHGSiteId = s.CHGSiteId
            }).ToList();


            if (roleEntity.Name == "AVP")
            {
                return((from u in UserRegions.Where(p => p.Deleted == false).ToList() join ur in UserRoles on u.UserId equals ur.UserId join i in items on u.RegionTypeId equals i.RegionTypeId where u.Deleted == false && i.CHGSiteId == CHGSiteId && ur.Deleted == false && ur.User.Deleted == false && ur.User.Enabled == true && ur.UserRoleTypeId == roleId select u.User).Distinct().ToList());
            }

            return(null);
        }
예제 #5
0
 public UserRoleType GetRole(string role)
 {
     return(UserRoleTypes.Where(p => p.Name == role && p.Deleted == false).SingleOrDefault());
 }
예제 #6
0
 public UserRoleType GetRole(long roleId)
 {
     return(UserRoleTypes.Find(roleId));
 }