// GET: /Account/Register public ActionResult Register() { T_OE_APP_SETTINGS_CUSTOM cust = db_Ref.GetT_OE_APP_SETTING_CUSTOM(); var model = new vmAccountRegister(); model.termsConditions = cust.TERMS_AND_CONDITIONS; return(View(model)); }
// GET: /Account/Register public ActionResult Register() { var model = new vmAccountRegister(); return(View("Register", model)); }
public ActionResult Register(vmAccountRegister model) { if (ModelState.IsValid) { if (model != null) { MembershipCreateStatus status; try { // ******************** AGENCY VALIDATION ****************************** List <T_OE_ORGANIZATION> o = db_Ref.GetT_OE_ORGANIZATION_ByEmail(model.UserName); if (o != null) { if (o.Count == 0) { // PREVENT REGISTRATION IF NON US/GOV EMAIL if (model.UserName.Substring(model.UserName.Length - 4) != ".gov" && model.UserName.Substring(model.UserName.Length - 3) != ".us") { TempData["Error"] = "Registration is only available for government employees. Please register using a government-issued email."; return(View(model)); } else { if (model.suggestAgency == null) { TempData["Error"] = "No government agency is found matching that email. Please provide an agency name below."; ModelState.AddModelError("suggestAgency", "Enter your agency name"); model.suggestAgencyInd = true; return(View(model)); } } } else if (o.Count > 1 && model.intSelOrgIDX == null) //more than one match and single hasn't been identified yet { model.ddl_Agencies = o.Select(x => new SelectListItem { Value = x.ORG_IDX.ToString(), Text = x.ORG_NAME }); TempData["Error"] = "Select the agency to which you belong."; ModelState.AddModelError("intSelOrgIDX", "Select your agency"); return(View(model)); } else if (o.Count == 1) { model.intSelOrgIDX = o.FirstOrDefault().ORG_IDX; } } // ****************** END AGENCY VALIDATION ****************************** //create user and send out verification email Membership.Provider.CreateUser(model.UserName, "", model.UserName, null, null, false, null, out status); if (status == MembershipCreateStatus.Success) { int UserIDX = (int)Membership.GetUser(model.UserName).ProviderUserKey; //create agency and email rule if new Guid?NewOrgIDX = null; if (model.intSelOrgIDX == null) { //create the agency & email rule NewOrgIDX = db_Ref.InsertUpdatetT_OE_ORGANIZATION(null, null, model.suggestAgency, null, null, null, null, true, UserIDX); db_Ref.InsertT_OE_ORGANIZATION_EMAIL_RULE(NewOrgIDX.ConvertOrDefault <Guid>(), Regex.Match(model.UserName, "@(.*)").Groups[1].Value); //notify Site Admins via email List <T_OE_USERS> Admins = db_Accounts.GetT_OE_USERSInRole(1); foreach (T_OE_USERS Admin in Admins) { Utils.SendEmail(null, Admin.EMAIL, null, null, model.UserName + " has registered a new Agency", "The user " + model.UserName + " has registered the following new agency: " + model.suggestAgency, null, "", "The user " + model.UserName + " has registered the following new agency: " + model.suggestAgency); } } //update first name, last name, and agency db_Accounts.UpdateT_OE_USERS(UserIDX, null, null, model.FirstName, model.LastName, model.UserName, null, null, null, null, null, null, null, null, model.intSelOrgIDX ?? NewOrgIDX, null); //redirect user to registration success view return(RedirectToAction("RegisterSuccess", "Account")); } else { if (status.ToString() == "DuplicateUserName") { TempData["Error"] = "An account has already been created with that email address. Please recover lost password."; } else if (status.ToString() == "InvalidEmail") { TempData["Error"] = "Unable to send verification email. Please try again later."; } else { TempData["Error"] = status; } } } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } } // Redisplay form showing error or success message return(View(model)); }