public ActionResult Manage(UserProfile userProfile)
        {
            string success = "nono";
            //bool hasLocalAccount = OAuthWebSecurity.HasLocalAccount(WebSecurity.GetUserId(User.Identity.Name));
            //ViewBag.HasLocalPassword = hasLocalAccount;
            ViewBag.ReturnUrl = Url.Action("Manage");
            if (Request.Form["submitButton"] == "Change password")
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        if (userProfile.NewPassword != userProfile.ConfirmPassword)
                            success = "The new password and confirmation password do not match.";
                        //changePasswordSucceeded = WebSecurity.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword);
                        success = App_Code.CustomSecurityProvider.ChangePassword(userProfile.UserName, userProfile.Password, userProfile.NewPassword);
                    }
                    catch (Exception ex) { success = ex.Message; }

                    if (success=="ok")
                    {
                        return RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess });
                    }
                    else
                    {
                        ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
                        ViewBag.LodgeList = GetLodgeList();
                        return View(userProfile);
                    }
                }
            }
            if (Request.Form["submitButton"] == "Log In to an Existing Lodge")
            {
                if (userProfile.MasonId == 0)
                {
                    ModelState.AddModelError("", "Mason Number is required.");
                    ViewBag.LodgeList = GetLodgeList();
                    return RedirectToAction("Manage", new { Message = ManageMessageId.MasonIdRequired });
                }
                else
                {
                    if (userProfile.DatabaseName == null)
                    {
                    }
                    var memberInfo = MemberDataXml.GetMember(userProfile.MasonId, Server.MapPath("\\App_Data\\") + userProfile.DatabaseName);
                    //var memberInfo = DataAccess.MemberData.GetMember(model.MasonId, "");
                    if (memberInfo == null)
                    {
                        //ModelState.AddModelError("", "Member Information Not Found");
                        ViewBag.LodgeList = GetLodgeList();
                        return RedirectToAction("Manage", new { Message = ManageMessageId.MasonIdNotFound });
                    }
                    else
                    {
                        var p = MasonMasterData.GetUserProfile(User.Identity.Name);
                        p.LodgeId = userProfile.LodgeId; ;
                        MasonMasterData.UpdateUserProfile(p);
                        ViewBag.LodgeList = GetLodgeList();
                        return RedirectToAction("Manage", new { Message = ManageMessageId.AssignToLodgeSuccess });
                    }
                }
            }
            if (Request.Form["submitButton"] == "Create a New Lodge")
            {
                return RedirectToAction("LodgeCreate", "Admin");
            }
            // If we got this far, something failed, redisplay form
            ViewBag.LodgeList = GetLodgeList();
            return View(userProfile);
        }
 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;
 }