Ejemplo n.º 1
0
 public List<dataTree> GetMenu(string modulo, string usuario)
 {
     gesMenuAdapter mg = new gesMenuAdapter();
     return mg.getOpciones(modulo, usuario);
 }
Ejemplo n.º 2
0
        protected void BtnIniciar_Click1(object sender, EventArgs e)
        {
            var userStore = new UserStore<IdentityUser>();
            var userManager = new UserManager<IdentityUser>(userStore);
            //var user = userManager.Find(UserName.Text, Password.Text);

            var user = userManager.FindByName(UserName.Text);

            if (user != null)
            {
                var validCredentials = userManager.Find(UserName.Text, Password.Text);

                if (userManager.IsLockedOut(user.Id))
                {
                    ModelState.AddModelError("", string.Format("Your account has been locked out for {0} minutes due to multiple failed login attempts.", ConfigurationManager.AppSettings["DefaultAccountLockoutTimeSpan"].ToString()));
                    StatusText.Text = string.Format("Your account has been locked out for {0} minutes due to multiple failed login attempts.", ConfigurationManager.AppSettings["DefaultAccountLockoutTimeSpan"].ToString());
                }
                else if (userManager.GetLockoutEnabled(user.Id) && validCredentials == null)
                {
                    userManager.AccessFailed(user.Id);
                    string message;
                    if (userManager.IsLockedOut(user.Id))
                    {
                        message = string.Format("Your account has been locked out for {0} minutes due to multiple failed login attempts.", ConfigurationManager.AppSettings["DefaultAccountLockoutTimeSpan"].ToString());
                        StatusText.Text = message;
                    }
                    else
                    {
                        int accessFailedCount = userManager.GetAccessFailedCount(user.Id);
                        int attemptsLeft =
                            Convert.ToInt32(
                                ConfigurationManager.AppSettings["MaxFailedAccessAttemptsBeforeLockout"].ToString()) -
                            accessFailedCount;
                        message = string.Format(
                            "Invalid credentials. You have {0} more attempt(s) before your account gets locked out.", attemptsLeft);
                        StatusText.Text = message;
                    }

                    ModelState.AddModelError("", message);
                }
                else if (validCredentials == null)
                {
                    ModelState.AddModelError("", "Invalid credentials. Please try again.");
                    StatusText.Text = "Invalid credentials. Please try again.";
                }
                else
                {

                    var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
                    var userIdentity = userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);

                    authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, userIdentity);
                    userManager.ResetAccessFailedCount(user.Id);

                    string vig = DateTime.Now.Year.ToString();
                    SetCookieUser(UserName.Text, vig);

                    string url = Request.QueryString["ReturnUrl"];
                    if (url == "" || url == null)
                    {
                        gesMenuAdapter mg = new gesMenuAdapter();
                        List<dataTree> l = mg.getOpciones("INICI", UserName.Text);
                        if (l.Where(t => t.roles == "INICIAdministrativo").FirstOrDefault() != null)
                        {
                            SetCookieRol("administrador");
                            url = "/Inicio/Administrativo/Inicio.aspx";
                        }
                        else
                        {
                            if (l.Where(t => t.roles == "INICIAcudientes").FirstOrDefault() != null)
                            {
                                SetCookieRol("acudiente");
                                url = "/Inicio/Acudientes/Inicio.aspx";
                            }
                        }
                    }
                    IdentityHelper.RedirectToReturnUrl(url, Response);
                }

            }
            else
            {
                StatusText.Text = "Invalid username or password.";
            }
        }