예제 #1
0
        public ActionResult LogIn(LogOnModel model)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    EmployeeHelper employeeHelper = new EmployeeHelper();
                    Employee       employee       = employeeHelper.GetEmployeeByUsername(model.UserName);

                    if (employee != null)
                    {
                        //IEnumerable<Feature> features = employeeHelper.GetFeaturesForEmployee(employee.ID);
                        //IEnumerable<RoleFeature> roleFeatures = employeeHelper.GetRoleFeaturesForEmployee(employee.ID);
                        SmartPrincipal principal = new SmartPrincipal()
                        {
                            Name = model.UserName,
                            ID   = employee.ID
                        };

                        string userData = SmartPrincipal.GetCookieUserData(principal);
                        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, model.UserName, DateTime.Now, DateTime.Now.AddMinutes(30), model.RememberMe, userData);
                        string encTicket = FormsAuthentication.Encrypt(ticket);
                        Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
                        return(Content("Logged In Ok"));
                    }
                    //HttpCookie cookie = FormsAuthentication.GetAuthCookie(model.UserName, false);
                    //cookie.Expires = DateTime.Now.AddMinutes(20);
                    //Request.Cookies.Add(cookie);
                    //Request.Cookies.Add(new HttpCookie("Barney", "Rubble"));

                    //return Content("Logged In Ok");
                }
            }
            return(new HttpUnauthorizedResult());
        }
예제 #2
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    EmployeeHelper       employeeHelper = new EmployeeHelper();
                    Employee             employee       = employeeHelper.GetEmployeeByUsername(model.UserName);
                    DeviceSettingLibrary deviceLib      = new DeviceSettingLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());

                    if (employee != null)
                    {
                        Session["Site_Org_ID"] = employee.Site_Org_ID.ToString();
                        Session["Unique_ID"]   = deviceLib.GetBySiteIdAndDeviceId(employee.Site_Org_ID.Value, "1").Unique_ID;

                        //IEnumerable<Feature> features = employeeHelper.GetFeaturesForEmployee(employee.ID);
                        //IEnumerable<RoleFeature> roleFeatures = employeeHelper.GetRoleFeaturesForEmployee(employee.ID);
                        SmartPrincipal principal = new SmartPrincipal()
                        {
                            Name = model.UserName,
                            ID   = employee.ID
                        };

                        string userData = SmartPrincipal.GetCookieUserData(principal);
                        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, model.UserName, DateTime.Now, DateTime.Now.AddMinutes(30), model.RememberMe, userData);
                        string encTicket = FormsAuthentication.Encrypt(ticket);
                        Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));

                        //FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                        if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                            !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        {
                            return(Redirect(returnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "The user name or password provided is incorrect.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public static NavigationItemBuilder <TItem, TBuilder> ContentIf <TItem, TBuilder>(this NavigationItemBuilder <TItem, TBuilder> item, ActionDetails actionDetail)
            where TItem : NavigationItem <TItem>
            where TBuilder : NavigationItemBuilder <TItem, TBuilder>, IHideObjectMembers
        {
            SmartPrincipal user = item.ViewContext.HttpContext.User as SmartPrincipal;

            if ((actionDetail != null))
            {
                if (user.IsInFeature(actionDetail.Feature))
                {
                    return(item.Content(actionDetail.Content));
                }
            }

            item.Visible(false);
            return(item);
        }
예제 #4
0
        private void Application_AuthenticateRequest(Object source, EventArgs e)
        {
            var application = (HttpApplication)source;
            var context     = application.Context;

            // Get the authentication cookie
            string     cookieName = FormsAuthentication.FormsCookieName;
            HttpCookie authCookie = context.Request.Cookies[cookieName];

            if (authCookie == null)
            {
                return;
            }

            var authTicket = FormsAuthentication.Decrypt(authCookie.Value);

            context.User = SmartPrincipal.CreatePrincipalFromCookieData(authTicket.UserData);
        }
        public static MenuItemBuilder ActionIf(this MenuItemBuilder item, ActionDetails[] actionDetails)
        {
            SmartPrincipal user = item.ViewContext.HttpContext.User as SmartPrincipal;

            if ((actionDetails != null) && (actionDetails.Length > 0))
            {
                foreach (ActionDetails actionDetail in actionDetails)
                {
                    if (user.IsInFeature(actionDetail.Feature))
                    {
                        return(item.Action(actionDetail.Action, actionDetail.Controller));
                    }
                }
            }

            item.Visible(false);
            return(item);
        }
        public static NavigationItemBuilder <TItem, TBuilder> ActionIf <TItem, TBuilder>(this NavigationItemBuilder <TItem, TBuilder> item, ActionDetails[] actionDetails)
            where TItem : NavigationItem <TItem>
            where TBuilder : NavigationItemBuilder <TItem, TBuilder>, IHideObjectMembers
        {
            SmartPrincipal user = item.ViewContext.HttpContext.User as SmartPrincipal;

            if ((actionDetails != null) && (actionDetails.Length > 0))
            {
                foreach (ActionDetails actionDetail in actionDetails)
                {
                    if (user.IsInFeature(actionDetail.Feature))
                    {
                        return(item.Action(actionDetail.Action, actionDetail.Controller));
                    }
                }
            }

            item.Visible(true);
            return(item);
        }