public override bool IsUserInRole(string username, string roleName) { using (var usersContext = new CheckingContext()) { var user = usersContext.Users.SingleOrDefault(u => u.UserName == username); if (user == null) { return(false); } return(user.Role != null && user.Role.ToString() == roleName); } }
public override string[] GetRolesForUser(string username) { using (var usersContext = new CheckingContext()) { var user = usersContext.Users.SingleOrDefault(u => u.UserName == username); if (user == null) { return new string[] { } } ; return(user.Role == null ? new string[] { } : new string[] { user.Role.ToString() }); } }
private User SetupFormsAuthTicket(string userName) { User user; using (var usersContext = new CheckingContext()) { user = usersContext.GetUser(userName); } var userId = user.UserID; var userData = userId.ToString(CultureInfo.InvariantCulture); var authTicket = new FormsAuthenticationTicket(1, //version userName, // user name DateTime.Now, //creation DateTime.Now.AddMinutes(30), //Expiration false, //persistanceFlag, //Persistent userData); var encTicket = FormsAuthentication.Encrypt(authTicket); Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)); return(user); }
public CheckingController(CheckingContext profilecontext) { _profileContext = profilecontext; if (_profileContext.checking.Count() == 0) { //Profile 1 _profileContext.checking.Add(new Checking { username = "******", description = "Members 1st Checking Account", balance = 7577.23, lastActivityDate = DateTime.Now.ToString(), }); _profileContext.SaveChanges(); //Profile 2 _profileContext.checking.Add(new Checking { username = "******", description = "Members 1st Checking Account", balance = 21456.76, lastActivityDate = DateTime.Now.ToString(), }); _profileContext.SaveChanges(); //Profile 3 _profileContext.checking.Add(new Checking { username = "******", description = "Members 1st Checking Account", balance = 25000.54, lastActivityDate = DateTime.Now.ToString(), }); _profileContext.SaveChanges(); } }