public static string xRegister(RegisterModel registerModel) { string success = "ono"; try { //success = LodgeSecretary.DataAccess.MasonMasterData.CreateUserProfile(userProfile); //if (success == "ok") //{ // //HttpCookie authCookie = System.Web.HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; // //FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); // //System.Web.HttpCookie authCookie = System.Web.HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; //} } catch (Exception ex) { success = ex.Message; } return success; }
public ActionResult Register(RegisterModel registerModel) { //WebSecurity.Login(model.UserName, model.Pass word); //WebSecurity.CreateUserAndAccount(model.UserName, model.Password); if (registerModel.Password != registerModel.ConfirmPassword) { ModelState.AddModelError("", "Passwords do not match"); } string databaseName = "SampleLodge.xml"; string success = "ono"; ActionResult rtn = RedirectToAction("Index", "Home"); if (ModelState.IsValid) { try { if (Request.Form["submitButton"] == "Register and Create a New Lodge") { rtn = RedirectToAction("LodgeCreate", "Admin"); databaseName = "Add New"; success = "ok"; } if (Request.Form["submitButton"] == "Register and log into Sample Lodge") { registerModel.LodgeId = MasonMasterData.GetSampleLodgeId(); if (registerModel.LodgeId == 0) { var sampleLodge = new Models.Lodge() { LodgeId = 0, LodgeName = "Sample Lodge", IsSample = true, DateChartered = DateTime.Today, DatabaseName = "SampleLodge.xml" }; registerModel.LodgeId = MasonMasterData.AddEditLodge(sampleLodge); if (registerModel.LodgeId == 0) success = "Failed to create Sample Lodge"; else { success = LodgeDataXml.CreateNewLodgeXmlFile(Server.MapPath("\\App_Data\\") + "SampleLodge.xml"); } } else success = "ok"; } if (Request.Form["submitButton"] == "Log In to an Existing Lodge") { if (registerModel.MasonId == 0) success = "Mason Number is required"; else { // lookup Member databaseName = MasonMasterData.GetLodge(registerModel.LodgeId.Value).DatabaseName; string lodgeFileName = Server.MapPath("\\App_Data\\") + databaseName; var memberInfo = MemberDataXml.GetMember(registerModel.MasonId.Value, lodgeFileName); if (memberInfo == null) success = "Member Information Not Found"; else { rtn = RedirectToAction("index", "Home"); success = "ok"; } } } } catch (Exception e) { success = e.Message; } if (success == "ok") { try { FormsAuthentication.SetAuthCookie(registerModel.UserName, false); UserProfile userProfile = new UserProfile(); userProfile.UserName = registerModel.UserName; userProfile.LodgeId = registerModel.LodgeId.Value; userProfile.FullName = registerModel.FullName; userProfile.Password = registerModel.Password; //userProfile.DatabaseName = databaseName; success = MasonMasterData.CreateUserProfile(userProfile); success = App_Code.CustomSecurityProvider.Login(registerModel.UserName, registerModel.Password, false); } catch (Exception ex) { success = ex.Message; } } } else { ViewBag.LodgeList = GetLodgeList(); rtn = View(registerModel); } if (success != "ok") { ViewBag.LodgeList = GetLodgeList(); ModelState.AddModelError("", success); RedirectToAction("Register", registerModel); } return rtn; }