public void AcceptDisclaimer() { using (UsersContext db = new UsersContext()) { UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == User.Identity.Name); user.IsDisclaimerAccepted = true; db.SaveChanges(); } }
public ActionResult Index(LoginModel model, string returnUrl) { //Validate the user name is an valid email if (!string.IsNullOrEmpty(model.UserName)) { Regex regEx = new Regex("^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"); if (!regEx.IsMatch(model.UserName)) ModelState.AddModelError("", Resources.Common.EmailFormatNotValid); } //Validate user using Simple membership if (ModelState.IsValid) { var roles = (SimpleRoleProvider)Roles.Provider; if (WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe) && (roles.GetRolesForUser(model.UserName).Contains("SuperAdmin") || roles.GetRolesForUser(model.UserName).Contains("Client"))) { using (UsersContext db = new UsersContext()) { UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower()); if (!user.IsActive) { ModelState.AddModelError("", Resources.Common.UserInactive); } else { if (user.IsDisclaimerAccepted.GetValueOrDefault()) { Session.Add("persistencia", true); return RedirectToLocal(returnUrl); } else { ViewBag.IsDisclaimerAccepted = user.IsDisclaimerAccepted.GetValueOrDefault(); return View(model); } } } } else { // If we got this far, something failed, redisplay form ModelState.AddModelError("", Resources.Common.WrongLogin); } } return View(model); }
public SimpleMembershipInitializer() { Database.SetInitializer<UsersContext>(null); try { using (var context = new UsersContext()) { if (!context.Database.Exists()) { // Create the SimpleMembership database without Entity Framework migration schema ((IObjectContextAdapter)context).ObjectContext.CreateDatabase(); } } WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true); var roles = (SimpleRoleProvider)Roles.Provider; var membership = (SimpleMembershipProvider)System.Web.Security.Membership.Provider; if (!roles.RoleExists("Admin")) roles.CreateRole("Admin"); if (!roles.RoleExists("SuperAdmin")) roles.CreateRole("SuperAdmin"); if (!roles.RoleExists("Issuer")) roles.CreateRole("Issuer"); if (!roles.RoleExists("Coordinator")) roles.CreateRole("Coordinator"); if (!roles.RoleExists("Client")) roles.CreateRole("Client"); if (!roles.RoleExists("BorderAgent")) roles.CreateRole("BorderAgent"); if (membership.GetUser("*****@*****.**", false) == null) WebSecurity.CreateUserAndAccount("*****@*****.**", "111111", new { IsActive = true }); if (!roles.GetRolesForUser("*****@*****.**").Contains("SuperAdmin")) roles.AddUsersToRoles(new[] { "*****@*****.**" }, new[] { "SuperAdmin" }); if (membership.GetUser("*****@*****.**", false) == null) WebSecurity.CreateUserAndAccount("*****@*****.**", "111111", new { IsActive = true }); if (!roles.GetRolesForUser("*****@*****.**").Contains("SuperAdmin")) roles.AddUsersToRoles(new[] { "*****@*****.**" }, new[] { "SuperAdmin" }); if (membership.GetUser("*****@*****.**", false) == null) WebSecurity.CreateUserAndAccount("*****@*****.**", "111111", new { IsActive = true }); if (!roles.GetRolesForUser("*****@*****.**").Contains("SuperAdmin")) roles.AddUsersToRoles(new[] { "*****@*****.**" }, new[] { "SuperAdmin" }); if (membership.GetUser("*****@*****.**", false) == null) WebSecurity.CreateUserAndAccount("*****@*****.**", "111111", new { IsActive = true }); if (!roles.GetRolesForUser("*****@*****.**").Contains("SuperAdmin")) roles.AddUsersToRoles(new[] { "*****@*****.**" }, new[] { "SuperAdmin" }); } catch (Exception ex) { throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex); } }