public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { Email = model.Email, name_key = model.name_key }); WebSecurity.Login(model.UserName, model.Password); ETSData.User user = ETSData.User.Load(ConfigurationManager.ConnectionStrings["ETSConnection"].ConnectionString, model.UserName); System.Web.HttpContext.Current.Session[ETSData.Constants.HTTPSessionNames.USER] = user; System.Web.HttpContext.Current.Session[ETSData.Constants.HTTPSessionNames.AGENCY] = ETSData.Agency.Load(ConfigurationManager.ConnectionStrings["ETSConnection"].ConnectionString, user.AgencyID); return(RedirectToAction("Index", "Home")); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form Dictionary <string, string> users = ETSData.User.GetAllUsers(ConfigurationManager.ConnectionStrings["ETSConnection"].ConnectionString); ViewBag.Users = users; return(View(model)); }
private IEnumerable <SelectListItem> GetClients() { ETSData.User user = ((ETSData.User)System.Web.HttpContext.Current.Session[ETSData.Constants.HTTPSessionNames.USER]); using (TimeLineDB db = new TimeLineDB()) { if (ConfigurationManager.AppSettings["AllowAllClients"] == "1") { IEnumerable <SelectListItem> items = from client in db.Clients orderby client.sort_name select new SelectListItem { Text = client.sort_name, Value = client.Name_Key }; return(items.ToList()); } else { IEnumerable <SelectListItem> items = from client in db.Clients join rel in db.ConsumerCoachs on client.Name_Key equals rel.ConsumerKey //where !(client.first_name == null || client.first_name.Trim() == string.Empty) where rel.CoachKey == user.NameKey orderby client.sort_name select new SelectListItem { Text = client.sort_name, Value = client.Name_Key }; return(items.ToList()); } } }
protected void Session_Start() { if (User.Identity.IsAuthenticated) { //Add the user's agency to the session context so we can use it later ETSData.User user = ETSData.User.Load(ConfigurationManager.ConnectionStrings["ETSConnection"].ConnectionString, User.Identity.Name); System.Web.HttpContext.Current.Session[ETSData.Constants.HTTPSessionNames.USER] = user; System.Web.HttpContext.Current.Session[ETSData.Constants.HTTPSessionNames.AGENCY] = ETSData.Agency.Load(ConfigurationManager.ConnectionStrings["ETSConnection"].ConnectionString, user.AgencyID); } else { //Default to 1 System.Web.HttpContext.Current.Session[ETSData.Constants.HTTPSessionNames.AGENCY] = ETSData.Agency.Load(ConfigurationManager.ConnectionStrings["ETSConnection"].ConnectionString, 1); } }
public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password)) { //Add the user's agency to the session context so we can use it later ETSData.User user = ETSData.User.Load(ConfigurationManager.ConnectionStrings["ETSConnection"].ConnectionString, model.UserName); System.Web.HttpContext.Current.Session[ETSData.Constants.HTTPSessionNames.USER] = user; if (Roles.IsUserInRole("Supervisor")) { System.Web.HttpContext.Current.Session[ETSData.Constants.HTTPSessionNames.SUPERVISOR_USER] = user; } System.Web.HttpContext.Current.Session[ETSData.Constants.HTTPSessionNames.AGENCY] = ETSData.Agency.Load(ConfigurationManager.ConnectionStrings["ETSConnection"].ConnectionString, user.AgencyID); return(RedirectToLocal(returnUrl)); } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "The user name or password provided is incorrect."); return(View(model)); }