public ActionResult AddUserToClient(Security_Users viewSecuritySetup) { viewSecuritySetup.securitycompanieslist = Clients.GetClientListForDropdown(); viewSecuritySetup.adduserlist = DomainModels.Security.GetAllUsers("Active"); return(View("AddUserToClient", viewSecuritySetup)); }
public ActionResult ChangePassword(string UserName, string currentPassword, string newPassword, string confirmPassword, string newSecurityQuestion, string newSecurityAnswer) { Security_Users viewSecurity_Users = new Security_Users(); viewSecurity_Users.username = UserName; // Basic parameter validation if (String.IsNullOrEmpty(currentPassword)) { ViewData.ModelState.AddModelError("currentPassword", "You must specify a current password."); } if (newPassword == null || newPassword.Length < Provider.MinRequiredPasswordLength) { ViewData.ModelState.AddModelError("newPassword", String.Format(CultureInfo.InvariantCulture, "You must specify a new password of {0} or more characters.", Provider.MinRequiredPasswordLength)); } if (!String.Equals(newPassword, confirmPassword, StringComparison.Ordinal)) { ViewData.ModelState.AddModelError("newPassword", "The new password and confirmation password do not match."); } if (ViewData.ModelState.IsValid) { // Attempt to change password MembershipUser currentUser = Provider.GetUser(User.Identity.Name, true /* userIsOnline */); bool changeSuccessful = false; bool changeQuestionSuccessful = false; try { changeSuccessful = currentUser.ChangePassword(currentPassword, newPassword); changeQuestionSuccessful = currentUser.ChangePasswordQuestionAndAnswer(newPassword, newSecurityQuestion, newSecurityAnswer); } catch { // An exception is thrown if the new password does not meet the provider's requirements } if (changeSuccessful) { if (changeQuestionSuccessful) { return(RedirectToAction("ChangePasswordSuccess", "Security")); } else { ViewData.ModelState.AddModelError("newSecurityQuestion", "The new security question/answer combination was not accepted. Please try again."); } } else { ViewData.ModelState.AddModelError("password", "The current password is incorrect or the new password is invalid."); } } // If we got this far, something failed, redisplay form return(View(viewSecurity_Users)); }
public ActionResult ChangePassword() { Security_Users viewSecurity_Users = new Security_Users(); var user = Provider.GetUser(HttpContext.User.Identity.Name, HttpContext.User.Identity.IsAuthenticated); viewSecurity_Users.username = user.UserName; return(View(viewSecurity_Users)); }
public ActionResult Security() { Security_Users viewSecuritySetup = new Security_Users(); List <SelectListItem> clientselectlist = Clients.GetClientListForDropdown(); viewSecuritySetup.ClientID = Int32.Parse(clientselectlist.ElementAt(0).Value); viewSecuritySetup.userlist = Clients.GetClientUsers(viewSecuritySetup.ClientID); return(View(viewSecuritySetup)); }
public ActionResult CreateClientUser(Security_Users viewSecuritySetup) { viewSecuritySetup.securitycompanieslist2 = Clients.GetClientListForDropdown(); SelectListItem item1 = new SelectListItem(); item1.Text = "Client User"; item1.Value = "Client"; viewSecuritySetup.usertypelist.Add(item1); return(View("CreateClientUser", viewSecuritySetup)); }
public JsonResult GetClientSelectList(int id) //id = Current UserID { Security_Users viewSecuritySetup = new Security_Users(); List <SelectListItem> clientselectlist = Clients.GetClientListForDropdown(); var rows = clientselectlist.ToArray(); return(new JsonResult { Data = new { rows = rows } }); }
public JsonResult HandleCreateClientUserErrors(Security_Users viewSecuritySetup, FormCollection fc) { viewSecuritySetup.securitycompanieslist2 = Clients.GetClientListFromUser(SecurityExtension.GetCurrentUserID(this)); viewSecuritySetup.securitycompanieslist2.Find( delegate(SelectListItem tempitem) { return(tempitem.Value == fc["primarycompany"]); } ).Selected = true; SelectListItem item1 = new SelectListItem(); item1.Text = "Client User"; item1.Value = "Client"; viewSecuritySetup.usertypelist.Add(item1); SelectListItem item2 = new SelectListItem(); item2.Text = "Sales User"; item2.Value = "Sales"; viewSecuritySetup.usertypelist.Add(item2); viewSecuritySetup.usertypelist.Find( delegate(SelectListItem tempitem) { return(tempitem.Value == fc["usertypelist"]); } ).Selected = true; return(new JsonResult { Data = new { success = false, view = RenderToString.RenderViewToString(this, "CreateClientUser", viewSecuritySetup) } }); }
public ActionResult SecurityUserSettings(int id) { Security_Users viewSecuritySetup = new Security_Users(); viewSecuritySetup.userlist = Clients.GetClientUsers(viewSecuritySetup.ClientID); if (id != 0) { ClientContact clientContact = ClientContacts.GetClientContactFromUserID(id); viewSecuritySetup.username = clientContact.LoginUserName; viewSecuritySetup.UserID = clientContact.UserID; if (viewSecuritySetup.username != null) { MembershipUser mu = Provider.GetUser(viewSecuritySetup.username, false); if (mu != null) { viewSecuritySetup.IsApproved = mu.IsApproved; } else { viewSecuritySetup.IsApproved = true; } } else { viewSecuritySetup.username = ""; viewSecuritySetup.IsApproved = true; } } else { viewSecuritySetup.username = ""; viewSecuritySetup.IsApproved = true; } return(View(viewSecuritySetup)); }
public JsonResult CreateClientUserPost(Security_Users viewSecuritySetup, FormCollection fc) { int newuserclientid = Convert.ToInt32(fc["primarycompany"]); string newuserrole = fc["usertypelist"]; // Basic parameter validation if (String.IsNullOrEmpty(viewSecuritySetup.firstname)) { ViewData.ModelState.AddModelError("firstname", " "); ViewData.ModelState.AddModelError("*", "Please enter a firstname."); } if (String.IsNullOrEmpty(viewSecuritySetup.lastname)) { ViewData.ModelState.AddModelError("lastname", " "); ViewData.ModelState.AddModelError("*", "Please enter a lastname."); } if (String.IsNullOrEmpty(viewSecuritySetup.username)) { ViewData.ModelState.AddModelError("username", " "); ViewData.ModelState.AddModelError("*", "Please enter a username."); } if (String.IsNullOrEmpty(viewSecuritySetup.email)) { ViewData.ModelState.AddModelError("email", " "); ViewData.ModelState.AddModelError("*", "Please enter an email address."); } else { Regex emailregex = new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,7}$"); Match m = emailregex.Match(viewSecuritySetup.email); if (m.Success == false) { ViewData.ModelState.AddModelError("email", " "); ViewData.ModelState.AddModelError("*", "Invalid email format."); } } if (viewSecuritySetup.password == null || viewSecuritySetup.password.Length < Provider.MinRequiredPasswordLength) { ViewData.ModelState.AddModelError("password", " "); ViewData.ModelState.AddModelError("*", String.Format(CultureInfo.InvariantCulture, "A password of {0} or more characters is required.", Provider.MinRequiredPasswordLength)); } if (!String.Equals(viewSecuritySetup.password, viewSecuritySetup.confirmPassword, StringComparison.Ordinal)) { ViewData.ModelState.AddModelError("confirmPassword", " "); ViewData.ModelState.AddModelError("*", "The password and confirmation do not match."); } if (ViewData.ModelState.IsValid) { string subject = ConfigurationManager.AppSettings["CompanyName"] + " Billing: New Account"; string clientname = null; string clientaddr1 = null; string clientaddr2 = null; string clientcity = null; string clientstate = null; string clientzipcode = null; // Attempt to register the user MembershipCreateStatus createStatus; MembershipUser newUser = Provider.CreateUser(viewSecuritySetup.username, viewSecuritySetup.password, viewSecuritySetup.email, "client", "client", true, null, out createStatus); if (newUser != null) { var db = new UsersDataContext(); var result = db.S1_Users_CreateUser(viewSecuritySetup.username, newuserclientid, 1, viewSecuritySetup.firstname, viewSecuritySetup.lastname).SingleOrDefault(); if (result.UserID > 0) { Roles.AddUserToRole(viewSecuritySetup.username, newuserrole); if (String.IsNullOrEmpty(HttpUtility.UrlDecode(viewSecuritySetup.ReturnUrl))) { viewSecuritySetup.ReturnUrl = "/Account/Logon?portal=admin"; } var db1 = new UsersDataContext(); //The following line is creating a message with a null status on purpose. Due to the actionGUID being used in the emails following. Note also this is S1_Users instead of S1_Messages var results1 = db.S1_Users_CreateMessageWithAction(1, subject, result.UserID, 1, 0, 3, HttpUtility.UrlDecode(viewSecuritySetup.ReturnUrl), System.DateTime.Now, null).SingleOrDefault(); if (results1.ActionGUID != null) { string ReturnURL = "/Account/ConfirmEmail"; var db3 = new ClientsDataContext(); var result3 = db3.S1_Clients_GetClientsFromUser(result.UserID).SingleOrDefault(); if (result3 == null) { //todo; } else { clientname = result3.ClientName; clientaddr1 = result3.Address1; clientaddr2 = result3.Address2; clientcity = result3.City; clientstate = result3.State; clientzipcode = result3.ZipCode; } Provider.ChangePasswordQuestionAndAnswer(viewSecuritySetup.username, viewSecuritySetup.password, "What is your Company's zipcode?", clientzipcode); Dictionary <string, string> messagevalues = new Dictionary <string, string>(); messagevalues.Add("[[USER_FIRSTNAME]]", ""); messagevalues.Add("[[USER_MI]]", ""); messagevalues.Add("[[USER_LASTNAME]]", ""); messagevalues.Add("[[USER_TITLE]]", ""); messagevalues.Add("[[COMPANY_ADDRESS_LINE1]]", clientaddr1); messagevalues.Add("[[COMPANY_ADDRESS_LINE2]]", clientaddr2); messagevalues.Add("[[COMPANY_ADDRESS_CITY]]", clientcity); messagevalues.Add("[[COMPANY_ADDRESS_STATE]]", clientstate); messagevalues.Add("[[COMPANY_ADDRESS_ZIPCODE]]", clientzipcode); messagevalues.Add("[[USER_EMAIL]]", viewSecuritySetup.email); messagevalues.Add("[[USER_PHONE]]", ""); messagevalues.Add("[[USERNAME]]", viewSecuritySetup.username); messagevalues.Add("[[COMPANYNAME]]", clientname); messagevalues.Add("[[GUIDURL]]", System.Configuration.ConfigurationManager.AppSettings["DefaultPath"] + ReturnURL + "/" + results1.ActionGUID.ToString() + "?portal=client"); messagevalues.Add("[[CORPORATENAME]]", System.Configuration.ConfigurationManager.AppSettings["CompanyName"]); MailGun.SendEmailToUserFromTemplate(10, 0, "Create Client Account", 0, result.UserID.Value, 0, subject, messagevalues); return(new JsonResult { Data = new { success = true } }); /*var messageRecord = Messages.GetMessageTemplateRecord(0, "Create Client Account", messagevalues); * * string messagebody = messageRecord != null ? messageRecord.MessageText : null; * * if (messagebody != null) * { * int messageActionType = messageRecord.MessageActionTypeID.GetValueOrDefault(); * int? MessageIDOutput = new int?(); * Guid? MessageActionGuidOutput = new Guid?(); * * Messages.CreateMessageWithAction(messageActionType, subject, messagebody, result.UserID, 1, 0, 3, HttpUtility.UrlDecode(ReturnURL), System.DateTime.Now, null, "HTML", ref MessageIDOutput, ref MessageActionGuidOutput); * Messages.UpdateMessageAndMarkForSending(MessageIDOutput.Value, subject, messagebody); * * return new JsonResult { Data = new { success = true } }; * } * else * { * ModelState.AddModelError("*", "There was a problem sending the confirmation email. Please re-create a new account. We apologize for the inconvenience."); * HandleCreateClientUserErrors(viewSecuritySetup, fc); * return new JsonResult * { * Data = new * { * success = false, * view = RenderToString.RenderViewToString(this, "CreateClientUser", viewSecuritySetup) * } * }; * }*/ } ModelState.AddModelError("*", "There was a problem sending the confirmation email. Please re-create a new account. We apologize for the inconvenience."); HandleCreateClientUserErrors(viewSecuritySetup, fc); return(new JsonResult { Data = new { success = false, view = RenderToString.RenderViewToString(this, "CreateClientUser", viewSecuritySetup) } }); } else { ModelState.AddModelError("*", ErrorHandler.ErrorCodeToString(createStatus)); HandleCreateClientUserErrors(viewSecuritySetup, fc); return(new JsonResult { Data = new { success = false, view = RenderToString.RenderViewToString(this, "CreateClientUser", viewSecuritySetup) } }); } } else { ViewData.ModelState.AddModelError("*", ErrorHandler.ErrorCodeToString(createStatus)); HandleCreateClientUserErrors(viewSecuritySetup, fc); return(new JsonResult { Data = new { success = false, view = RenderToString.RenderViewToString(this, "CreateClientUser", viewSecuritySetup) } }); } } return(new JsonResult { Data = new { success = false, view = RenderToString.RenderViewToString(this, "CreateClientUser", viewSecuritySetup) } }); //return new JsonResult { Data = new { success = true } }; }