protected void btnLogin_Click(object sender, EventArgs e) { var validator = new Validator(); if (validator.isValidLogin(tbLogin.Text) && validator.isValidPassword(tbPass.Text)) { var userManager = new DbUserManager(); string pass = Encrypt.CalculateMD5Hash(tbPass.Text); if (!validator.isAvailableLogin(tbLogin.Text) && userManager.IsValidUser(tbLogin.Text, pass)) { new PageManager().SetRoles(userManager, tbLogin.Text); FormsAuthentication.SetAuthCookie(tbLogin.Text, cbRememberMe.Checked); //If Admin if (userManager.GetRoles(tbLogin.Text)[0] == new PermissionManager().GetPermission("Admin").Type) { Response.Redirect("~/Pages/AdminPages/StartPage.aspx"); } else { if (string.IsNullOrEmpty(action)) { string newRedirectUrl = "http://localhost:4308/Profile/Index"; Response.Redirect(newRedirectUrl); } else { string newRedirectUrl = "http://localhost:4308/Event/SaveEvent"; Response.Redirect(newRedirectUrl); } } } else { lbMsg.Text = LogInErrors.AuthorizationError; } } else { lbMsg.Text = LogInErrors.IncorrectLoginOrPassword; } }
private void SetRoles(DbUserManager userManager, string login) { IIdentity identity = new GenericIdentity(login); string[] roles = userManager.GetRoles(login); HttpContext.Current.User = new GenericPrincipal(identity, roles); }