Exemplo n.º 1
0
        public bool getUserCredentials(HttpRequestBase Request)
        {
            ADSearcher    ad   = new ADSearcher();
            UserPrincipal user = ad.findCurrentUserName(Request);

            using (var context = new PrincipalContext(ContextType.Domain))
            {
                try
                {
                    User myUser = new User();
                    myUser = ad.findByUserName(user);

                    //checks to see if the user exists in the database, if not add them
                    Queries query = new Queries();
                    query.checkExistingUser(myUser);

                    UserViewModel vmUser = new UserViewModel();
                    vmUser = myUser.userToModel(myUser);

                    if (user.IsMemberOf(GroupPrincipal.FindByIdentity(context, hrGroup)))
                    {
                        vmUser.isHR      = true;
                        vmUser.isManager = true;
                    }
                    else if (user.IsMemberOf(GroupPrincipal.FindByIdentity(context, managers)))
                    {
                        vmUser.isHR      = false;
                        vmUser.isManager = true;
                    }
                    else
                    {
                        vmUser.isManager = false;
                        vmUser.isHR      = false;
                    }

                    sessionStorage session = new sessionStorage();
                    session.setSessionUser(vmUser);
                    return(true);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
        }
Exemplo n.º 2
0
        public ActionResult Index(string error = "")
        {
            if (error != "")
            {
                ViewBag.errorMessage = error;
            }

            sessionStorage session = new sessionStorage();

            if (session.getSessionUser() != null)
            {
                return(View(session.getSessionUser()));
            }

            validation val = new validation();

            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            /// Active Directory Code

            //if (val.getUserCredentials(Request))
            //{
            //    return View(session.getSessionUser());
            //}
            //return RedirectToAction("Login");

            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            /// Non-Active Directory Code

            User myUser = new User();

            myUser = val.validate();
            UserViewModel vmUser = myUser.userToModel(myUser);

            vmUser.isHR = true;
            session.setSessionUser(vmUser);
            return(View(session.getSessionUser()));
        }