public async Task<CaptchaOutput> ValidateCaptcha(CaptchaData captchaData) { CaptchaOutput result = new CaptchaOutput() { Status = false, Msg = "" }; RecaptchaVerificationHelper verify = new RecaptchaVerificationHelper() { Challenge = captchaData.CaptchaChallenge, Response = captchaData.CaptchaResponse, PrivateKey = "6LeX2cgSAAAAAKkTWQSP6lO7xYsq_v4UF1BM_iCi", UserHostAddress = captchaData.UserHostAddress, UseSsl = false }; RecaptchaVerificationResult response = await verify.VerifyRecaptchaResponseTaskAsync(); if (response == RecaptchaVerificationResult.Success) { result.Status = true; } else { result.Status = false; result.Msg = "Mã bảo vệ chưa đúng, bạn vui lòng nhập lại!"; } result.ClientId = string.IsNullOrEmpty(captchaData.ClientId) ? Guid.NewGuid().ToString("n") : captchaData.ClientId; result.AccessToken = string.Empty; await Task.Delay(1); return result; }
public async Task <ActionResult> Login(LoginViewModel vm, string returnUrl) { #region Recaptcha RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (String.IsNullOrEmpty(recaptchaHelper.Response)) { ModelState.AddModelError("", "Captcha answer cannot be empty."); return(View(vm)); } RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); if (recaptchaResult != RecaptchaVerificationResult.Success) { ModelState.AddModelError("", "Incorrect captcha answer."); } #endregion if (!ModelState.IsValid) { return(View(vm)); } var user = this._userSertvice.Verify(vm.EmailAddress, vm.Password); if (user != null) { this.SignIn(user, true); return(RedirectToLocal(returnUrl).Success(string.Format("Welcome back {0}!", user.Fullname))); } ModelState.AddModelError("", "Invalid email or password."); return(View(vm)); }
public async Task <ActionResult> Login(string email, string password) { Login login = new Login(); try { if (login.RecaptchaTime()) { RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (String.IsNullOrEmpty(recaptchaHelper.Response)) { throw new CustomException.EmptyRecaptcha(); } RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); if (recaptchaResult != RecaptchaVerificationResult.Success) { throw new CustomException.Recaptcha(); } } login.LoginUser(email, password); } catch (Exception ex) { if (ex is CustomException.EmptyRecaptcha || ex is CustomException.Recaptcha) { login.Error = ex.Message; } return(View(login)); } return(Redirect("/home/index")); }
public async Task <ActionResult> Index(Socioboard.Helper.Enterprise ent) { RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); string ret; if (String.IsNullOrEmpty(recaptchaHelper.Response)) { ModelState.AddModelError("", "Captcha answer cannot be empty."); //return View(model); return(View()); } RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); if (recaptchaResult != RecaptchaVerificationResult.Success) { ModelState.AddModelError("", "Incorrect captcha answer."); ViewBag.AlertMsg = "error"; return(RedirectToAction("Enterprise", "Versions", new { hint = "error" })); } else { Api.MailSender.MailSender ApiobjMailSender = new Api.MailSender.MailSender(); ret = ApiobjMailSender.SendEnterpriseMail(ent.Name, ent.Designation, ent.ContactEmailId, ent.Location, ent.Company, ent.CompanyWebsite, ent.Message, ent.Phone); return(RedirectToAction("Enterprise", "Versions", new { hint = "success" })); //return Content(ret); //return View(); } // return View(model); //return View(); }
public async Task <ActionResult> Register(string email, string password1, string password2, string name, string company) { RegisterUser userToRegister = new RegisterUser(); try { userToRegister.Setup(email, password1, password2, name, company); RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (String.IsNullOrEmpty(recaptchaHelper.Response)) { throw new CustomException.EmptyRecaptcha(); } RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); if (recaptchaResult != RecaptchaVerificationResult.Success) { throw new CustomException.Recaptcha(); } userToRegister.Save(); return(View()); } catch (Exception ex) { if (ex is CustomException.EmptyRecaptcha || ex is CustomException.Recaptcha) { userToRegister.Error = ex.Message; } return(View(userToRegister)); } }
public async Task <ContentResult> New(string name, string email, string comment, int ignorecaptcha = 0) { try { if (ignorecaptcha != 1) { RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (String.IsNullOrEmpty(recaptchaHelper.Response)) { ModelState.AddModelError("", "Captcha answer cannot be empty."); return(Content("{\"success\":false}", "text/plain")); } RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); if (recaptchaResult != RecaptchaVerificationResult.Success) { ModelState.AddModelError("", "Incorrect captcha answer."); return(Content("{\"success\":false}", "text/plain")); } } Random rnd = new Random(); int id = rnd.Next(10000, 20000); StreamReader w = new StreamReader(HostingEnvironment.MapPath("~/email.html"), true); var body = await w.ReadToEndAsync(); body = body.Replace("{name}", name).Replace("{number}", id.ToString()).Replace("{message}", comment); var message = new MailMessage(); message.To.Add(new MailAddress("*****@*****.**")); // replace with valid value message.To.Add(new MailAddress(email)); message.From = new MailAddress("*****@*****.**"); // replace with valid value message.ReplyToList.Add(email); message.Subject = "Support Request #" + id; message.Body = body; message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", // replace with valid value Password = "******" // replace with valid value }; smtp.Credentials = credential; smtp.Host = "smtp.epicapps.com.br"; smtp.Port = 587; smtp.EnableSsl = false; await smtp.SendMailAsync(message); } } catch (Exception e) { return(Content("{\"success\":false, \"message\": " + e.Message + e.ToString() + "}", "text/plain")); } return(Content("{\"success\":true}", "text/plain")); }
/// <summary> /// Verifies the user's answer to the recaptcha challenge. /// </summary> /// <returns>Returns the verification result as <see cref="RecaptchaVerificationResult"/> enum value.</returns> ///<exception cref="InvalidOperationException">The private key is null or empty.</exception> ///<exception cref="System.Net.WebException">The time-out period for the recaptcha verification request expired.</exception> public Task <RecaptchaVerificationResult> VerifyTaskAsync() { if (_verificationHelper == null) { _verificationHelper = new RecaptchaVerificationHelper(this.PrivateKey); } return(_verificationHelper.VerifyRecaptchaResponseTaskAsync()); }
private async Task ReCapchaVerification() { RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (string.IsNullOrEmpty(recaptchaHelper.Response)) { ModelState.AddModelError("", "Click the thing that says 'I'm not a robot' (unless you are actually a robot, in which case go away)"); return; } RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); if (recaptchaResult != RecaptchaVerificationResult.Success) { ModelState.AddModelError("", "Google says you're a bot. Sorry (notsorry)"); } }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } // reCaptcha RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (String.IsNullOrEmpty(recaptchaHelper.Response)) { ModelState.AddModelError("", "Captcha answer cannot be empty."); return(View(model)); } RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); if (recaptchaResult != RecaptchaVerificationResult.Success) { ModelState.AddModelError("", "Incorrect captcha answer."); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: return(RedirectToLocal(returnUrl)); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } }
public async Task <ActionResult> Register(RegisterViewModel model) { // reCaptcha RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (String.IsNullOrEmpty(recaptchaHelper.Response)) { ModelState.AddModelError("", "Captcha answer cannot be empty."); return(View(model)); } RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); if (recaptchaResult != RecaptchaVerificationResult.Success) { ModelState.AddModelError("", "Incorrect captcha answer."); } if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName, PhoneNumber = model.PhoneNumber }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> Register(RegisterViewModel vm) { #region Recaptcha RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (String.IsNullOrEmpty(recaptchaHelper.Response)) { ModelState.AddModelError("", "Captcha answer cannot be empty."); return(View(vm)); } RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); if (recaptchaResult != RecaptchaVerificationResult.Success) { ModelState.AddModelError("", "Incorrect captcha answer."); } #endregion if (!ModelState.IsValid) { return(View(vm)); } if (this._userSertvice.EmailExist(vm.EmailAddress)) { ModelState.AddModelError("EmailAddress", "Email already in use."); return(View(vm)); } var user = new User() { Firstname = vm.Firstname, Lastname = vm.Lastname, EmailAddress = vm.EmailAddress, ClearTextPassword = vm.Password }; this._userSertvice.Add(user); return(RedirectToAction("Login") .Success("Account successfully created.")); }
public async Task <ActionResult> Create(Business business) { RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); //Check if Captcha is empty if (String.IsNullOrEmpty(recaptchaHelper.Response)) { ModelState.AddModelError("", "Captcha answer cannot be empty."); return(View(business)); } RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); //Check if captcha is not a success if (recaptchaResult != RecaptchaVerificationResult.Success) { //Return user to business page with an error ModelState.AddModelError("", "Incorrect captcha answer."); return(View(business)); } else { if (ModelState.IsValid) { //Add the current datetime value business.DateTime = System.DateTime.Now; //Add business if model and captcha are valid db.Businesses.Add(business); db.SaveChanges(); return(RedirectToAction("Index")); } else { return(View(business)); } } }
public async Task <ActionResult> Register(RegisterModel model) { RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); //Check if Captcha is empty if (String.IsNullOrEmpty(recaptchaHelper.Response)) { ModelState.AddModelError("", "Captcha answer cannot be empty."); return(View(model)); } RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); //Check if captcha is not a success if (recaptchaResult != RecaptchaVerificationResult.Success) { //Return user to Register page with an error ModelState.AddModelError("", "Incorrect captcha answer."); return(View(model)); } else { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password); WebSecurity.Login(model.UserName, model.Password); return(RedirectToAction("Index", "Home")); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <JsonResult> Cadastrar(FaleConosco fale) { RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (string.IsNullOrEmpty(recaptchaHelper.Response)) { return(Json(new { result = "captcha_branco" })); } RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); if (recaptchaResult != RecaptchaVerificationResult.Success) { return(Json(new { result = "captcha_error" })); } if (ModelState.IsValid) { fale.mensagem = Utils.StripTags(fale.mensagem); fale.dataCadastro = DateTime.Now; db.FaleConosco.Add(fale); try { await db.SaveChangesAsync(); return(Json(new { result = "success" })); } catch (Exception ex) { return(Json(new { result = "error-" + ex.Message })); } } else { return(Json(new { result = "invalid" })); } }
public async Task <ActionResult> Register(string name, string ip, string contactEmail, Times verificationTime) { var loggedUser = UsersUtilities.GetLoggedUser(); if (loggedUser == null) { return(Redirect("~/User/Login")); } RegisterServer ServerToRegister = new RegisterServer(); try { ServerToRegister.Setup(name, ip, contactEmail, verificationTime, loggedUser); RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (String.IsNullOrEmpty(recaptchaHelper.Response)) { throw new CustomException.EmptyRecaptcha(); } RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); if (recaptchaResult != RecaptchaVerificationResult.Success) { throw new CustomException.Recaptcha(); } ServerToRegister.Save(); return(View(ServerToRegister)); } catch (Exception ex) { if (ex is CustomException.EmptyRecaptcha || ex is CustomException.Recaptcha) { ServerToRegister.Error = ex.Message; } return(View(ServerToRegister)); } }
public async Task <ActionResult> Create(korisnici korisnici) { //Captcha provjera RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (String.IsNullOrEmpty(recaptchaHelper.Response)) { ModelState.AddModelError("", "Captcha answer cannot be empty."); return(View(korisnici)); } RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); if (recaptchaResult != RecaptchaVerificationResult.Success) { ModelState.AddModelError("", "Incorrect captcha answer."); return(View(korisnici)); } //if (ModelState.IsValid) // Ovdje pada zbog validacije // { ModelState.AddModelError("", "Prosao valid."); korisnici.aktivan = false; db.korisnici.Add(korisnici); // db.SaveChanges(); // Ovdje pada zbog validacije ModelState.Clear(); EmailManager.SendConfirmationEmail(korisnici); korisnici = null; return(RedirectToAction("Confirmation", "Korisnici")); //} ViewBag.idTipaKorisnika = new SelectList(db.tipovikorisnika, "idTipaKorisnika", "nazivTipaKorisnika", korisnici.idTipaKorisnika); return(View(korisnici)); }
public async Task <ActionResult> Register(RegisterModel model) { RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (String.IsNullOrEmpty(recaptchaHelper.Response)) { ModelState.AddModelError("", "Captcha answer cannot be empty."); return(View(model)); } RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); if (recaptchaResult != RecaptchaVerificationResult.Success) { ModelState.AddModelError("", "Incorrect captcha answer."); } if (ModelState.IsValid) { AppUser user = new AppUser { UserName = model.Username, Email = model.Email, PhoneNumber = model.Phoneno }; IdentityResult result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { return(RedirectToAction("Main", "Home")); } else { AddErrorsFromResult(result); } } return(View(model)); }
public ActionResult Register(RegistrationVM registration) { string sitePageName = Constants.PUBLIC_PAGE_REGISTRATION; if (ModelState.IsValid) { Boolean IsModelErrorExist = false; if (ModelState["Profile.ProfileName"] != null) { ModelState["Profile.ProfileName"].Errors.Clear(); } if (ModelState["Role.RoleName"] != null) { ModelState["Role.RoleName"].Errors.Clear(); } RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); ViewBag.CultureList = GetCultureList(); ViewBag.TimeZoneList = GetTimeZoneList(); if (String.IsNullOrEmpty(recaptchaHelper.Response)) { ModelState.AddModelError("", CommonFunctions.GetGlobalizedLabel("Registration", "CaptchaAnswerRequired"));//"Captcha answer cannot be empty."); IsModelErrorExist = true; } if (IsModelErrorExist == false) { Task <RecaptchaVerificationResult> recaptchaResult = recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); if (recaptchaResult.Result != RecaptchaVerificationResult.Success) { ModelState.AddModelError("", CommonFunctions.GetGlobalizedLabel("Registration", "IncorrectCaptchaAnswer")); IsModelErrorExist = true; } } UserModel userModel; if (IsModelErrorExist == false) { userModel = userBusiness.GetUserByEmailId(registration.EmailId); if (userModel != null) { ModelState.AddModelError("", CommonFunctions.GetGlobalizedLabel("Registration", "EmailAlreadyExists")); IsModelErrorExist = true; } } if (IsModelErrorExist == true) { ViewBag.success = false; if (TempData["View"] != null && TempData["View"].ToString() == "Login") { LoginModel loginModel = new LoginModel(); ViewBag.OpenRegistrationPopup = true; TempData["View"] = "Login"; sitePageName = Constants.PUBLIC_PAGE_LOGIN; CultureSpecificSiteContentModel cultureSpecificSiteContentModel = contentApplicationBusiness.GetPageCultureSpecificContent(sitePageName); loginModel.CultureSpecificPageContent = cultureSpecificSiteContentModel.CultureSpecificPageContent; loginModel.CultureSpecificPageMetaTitle = cultureSpecificSiteContentModel.CultureSpecificPageMetaTitle; loginModel.CultureSpecificPageMetaTags = cultureSpecificSiteContentModel.CultureSpecificPageMetaTags; // return View(login); return(View("Login", loginModel)); } else { TempData["View"] = "Register"; // RegistrationVM registrationVM = new RegistrationVM(); CultureSpecificSiteContentModel cultureSpecificSiteContentModel = contentApplicationBusiness.GetPageCultureSpecificContent(sitePageName); registration.CultureSpecificPageContent = cultureSpecificSiteContentModel.CultureSpecificPageContent; registration.CultureSpecificPageMetaTitle = cultureSpecificSiteContentModel.CultureSpecificPageMetaTitle; registration.CultureSpecificPageMetaTags = cultureSpecificSiteContentModel.CultureSpecificPageMetaTags; return(View(registration)); } } userModel = new UserModel(); AutoMapper.Mapper.Map(registration, userModel); userModel = userBusiness.RegisterUser(userModel); SessionManagement.LoggedInUser.UserId = userModel.UserId; SessionManagement.LoggedInUser.UserIdEncrypted = userModel.UserId.Encrypt(); SessionManagement.LoggedInUser.UserName = (userModel.FirstName + " " + userModel.LastName); SessionManagement.LoggedInUser.Password = userModel.Password; SessionManagement.LoggedInUser.EmailId = userModel.EmailId; SessionManagement.LoggedInUser.FullName = userModel.FirstName + " " + userModel.LastName; SessionManagement.LoggedInUser.Role = (Enums.UserType)userModel.UserTypeId; SessionManagement.LoggedInUser.CompanyId = userModel.CompanyModel.CompanyId; SessionManagement.LoggedInUser.CompanyName = userModel.CompanyModel.CompanyName; SessionManagement.LoggedInUser.ProfileImageUrl = userModel.ImageURL; SessionManagement.LoggedInUser.CurrentCulture = userModel.CultureInformationModel.CultureName; string pipeSeperatedPermissions = String.Join("|", userModel.ProfileModel.ProfilePermissionModels.Where(x => x.HasAccess == true).Select(x => x.ModulePermission.Module.ModuleCONSTANT + x.ModulePermission.Permission.PermissionCONSTANT).ToList().ToArray()); CommonFunctions.SetCookie(SessionManagement.LoggedInUser, pipeSeperatedPermissions, false); ViewBag.success = true; ViewBag.StatusMessage = CommonFunctions.GetGlobalizedLabel("Registration", "RegistrationSuccessMessage"); //"Registered successfully. Please login"; ViewBag.RegistrationSuccessWelComeMessage = CommonFunctions.GetGlobalizedLabel("Registration", "RegistrationSuccessWelComeMessage"); string emailSubject = CommonFunctions.GetGlobalizedLabel("EmailTemplates", "RegistrationEmailSubject"); string emailBody = CommonFunctions.GetGlobalizedLabel("EmailTemplates", "RegistrationEmailBody"); userBusiness.SendRegistrationEmail(userModel, emailSubject, emailBody); //ServiceReference1.Service1Client mailService = new ServiceReference1.Service1Client(); //string to = string.Empty; //string subject = string.Empty; //string body = string.Empty; //to = userModel.EmailId; //subject = "Welcome to Eurca CRM"; //body = "<div style='font-face:arial;'><img src='http://erucacrm.sensationsolutions.com/Content//Content/images/logo-dashbord.png'><hr/>Dear Customer" + ",<br/><br/>Thanks for your registration to Eruca CRM. <br/> Please find the following details to login into Eruca CRM. <br/><br/>CRM URL: <a href='http://erucacrm.sensationsolutions.com'>Click here to navigate to CRM<a/><br/><br/>" + "Your Username: "******"<br/>Password: "******" <br/><br/>Thank you.<br/><br/>Customer Relations</div>"; //mailService.SendEmail( to, subject, body, true); ModelState.Clear(); } if (TempData["View"] != null && TempData["View"].ToString() == "Login") { TempData["View"] = "Login"; sitePageName = Constants.PUBLIC_PAGE_LOGIN; LoginModel loginModel = new LoginModel(); ViewBag.OpenRegistrationPopup = true; CultureSpecificSiteContentModel cultureSpecificSiteContentModel = contentApplicationBusiness.GetPageCultureSpecificContent(sitePageName); loginModel.CultureSpecificPageContent = cultureSpecificSiteContentModel.CultureSpecificPageContent; loginModel.CultureSpecificPageMetaTitle = cultureSpecificSiteContentModel.CultureSpecificPageMetaTitle; loginModel.CultureSpecificPageMetaTags = cultureSpecificSiteContentModel.CultureSpecificPageMetaTags; // return View(login); return(View("Login", loginModel)); } else { ViewBag.CultureList = GetCultureList(); ViewBag.TimeZoneList = GetTimeZoneList(); sitePageName = Constants.PUBLIC_PAGE_REGISTRATION; TempData["View"] = "Register"; // RegistrationVM registrationVM = new RegistrationVM(); CultureSpecificSiteContentModel cultureSpecificSiteContentModel = contentApplicationBusiness.GetPageCultureSpecificContent(sitePageName); registration.CultureSpecificPageContent = cultureSpecificSiteContentModel.CultureSpecificPageContent; registration.CultureSpecificPageMetaTitle = cultureSpecificSiteContentModel.CultureSpecificPageMetaTitle; registration.CultureSpecificPageMetaTags = cultureSpecificSiteContentModel.CultureSpecificPageMetaTags; return(View(registration)); } }
public async Task <ActionResult> Denuncia(Ouvintes ouvinte) { RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (string.IsNullOrEmpty(recaptchaHelper.Response)) { //return Json(new { result = "captcha_branco" }); ModelState.AddModelError("", "O Captcha não pode ser deixado em branco"); } RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); if (recaptchaResult != RecaptchaVerificationResult.Success) { // return Json(new { result = "captcha_error" }); ModelState.AddModelError("", "O captcha não foi validado! Por favor verifique!"); } if (ModelState.IsValid) { ouvinte.comentario = Utils.StripTags(ouvinte.comentario); ouvinte.DataCadastro = DateTime.Now; ouvinte.excluido = false; db.Ouvintes.Add(ouvinte); try { await db.SaveChangesAsync(); #region upload if (Request.Files.Count > 0) { string diretorio = "/admin/conteudo/ouvintes/arquivos/"; for (int i = 0; i < Request.Files.Count; i++) { var arquivo = Request.Files[i]; var fileName = Utils.RemoveAccent(Path.GetFileNameWithoutExtension(arquivo.FileName)); if (fileName != "") { var extension = Path.GetExtension(arquivo.FileName); string[] permitidos = { ".jpg", ".jpeg", ".gif", ".js", ".zip", ".png", ".rar", ".doc", ".docx", ".txt", ".mp3 ", ".pdf", ".mpeg", ".mp4", ".ogg" }; if (!permitidos.Contains(extension.ToLower())) { ModelState.AddModelError("", "Extensão não permitida!"); } else { var path = Server.MapPath(diretorio); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var j = 0; while (System.IO.File.Exists(Path.Combine(path, fileName + extension))) { j++; fileName = Path.GetFileNameWithoutExtension(arquivo.FileName) + "_" + j; } arquivo.SaveAs(path + fileName + extension); var arq = new OuvintesArquivos(); arq.Arquivo = fileName + extension; arq.DataCadastro = DateTime.Now; arq.idOuvinteDenuncia = ouvinte.id; db.OuvintesArquivos.Add(arq); await db.SaveChangesAsync(); } } } } #endregion return(RedirectToAction("Enviado")); //return Json(new { result = "success" }); } catch (Exception e) { //return Json(new { result = "error-" + ex.Message }); return(View(ouvinte)); } } else { //ViewBag.regiaoId = new SelectList(db.Regioes, "id", "titulo"); ViewBag.cidade_id = new SelectList(db.cidade.Where(e => e.estado == 11).ToList(), "id", "nome"); return(View(ouvinte)); } }
async public Task <ActionResult> Register(RegisterViewModel registerData) { RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (String.IsNullOrEmpty(recaptchaHelper.Response)) { ModelState.AddModelError("", "Captcha answer cannot be empty."); return(View(registerData)); } RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); if (recaptchaResult != RecaptchaVerificationResult.Success) { ModelState.AddModelError("", "Incorrect captcha answer."); return(View(registerData)); } if (ModelState.IsValid) { if (registerData.Password != registerData.ConfirmPassword) // check if passwords are the same { ModelState.AddModelError("", "Sorry, passwords do not match"); return(View(registerData)); } if (registerData.Password.Length < 6) // check if password length id greater than 5 { ModelState.AddModelError("", "Sorry, passwords must be at least 6 characters"); return(View(registerData)); } try { WebSecurity.CreateUserAndAccount(registerData.Username, registerData.Password); Roles.AddUserToRole(registerData.Username, "trialUser"); // send email to verify and other things //SmtpClient smtpClient = new SmtpClient("mail.MyWebsiteDomainName.com", 25); //smtpClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "myIDPassword"); //smtpClient.UseDefaultCredentials = true; //smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; //smtpClient.EnableSsl = true; //MailMessage mail = new MailMessage(); ////Setting From , To and CC //mail.From = new MailAddress("info@MyWebsiteDomainName", "MyWeb Site"); //mail.To.Add(new MailAddress("info@MyWebsiteDomainName")); //mail.CC.Add(new MailAddress("*****@*****.**")); //smtpClient.Send(mail); return(RedirectToAction("RegistrationConfirmation", "Account")); } catch { ModelState.AddModelError("", "Sorry, a user with that email already exists"); return(View(registerData)); } } // should never get here ModelState.AddModelError("", "Sorry, a user with that email already exists"); return(View(registerData)); }
public async Task <ActionResult> Register(RegisterViewModel model) { //check recaptcha RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (String.IsNullOrEmpty(recaptchaHelper.Response)) { ModelState.AddModelError("", "Captcha answer cannot be empty."); } RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync(); if (recaptchaResult != RecaptchaVerificationResult.Success) { ModelState.AddModelError("", "Incorrect captcha answer."); } if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email, CrypticTag = model.CrypticTag, JoinDate = DateTime.Today, AutoApproval = false, LockoutEnabled = false, }; user.EmailConfirmed = true; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { //commented out so they have to confirm their email await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); try { EmailHelper.ReportNewUser(user); } catch { } // Send an email with this link /* * string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); * var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); * await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); * * ViewBag.Message = "Check your email and confirm your account, you must be confirmed " + "before you can log in."; + + return View("PleaseConfirmEmail");*/ return(RedirectToAction("index", "home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }