public ActionResult Login(LoginViewModel model, string returnUrl = null) { if (User?.Identity?.IsAuthenticated == true) { this.ShowMessage(MessageType.Warning, Resource.AlreadyLogIn); returnUrl = GetDefaultUrl(); if (Request.IsAjaxRequest()) { this.SetAjaxResponseRedirectUrl(returnUrl, true); return(new EmptyResult()); } return(Redirect(returnUrl)); } // Validate captcha control if (!captchaService.Validate(Request["g-recaptcha-response"])) { ModelState.AddModelErrorSafety(string.Empty, Resource.WrongCaptchaMessage); } else { var errors = authenticationProvider.Login(model.Username, model.Password); if (errors != null) { ModelState.Merge(errors); } } if (!ModelState.IsValid) { return(Request.IsAjaxRequest() ? PartialView("Login", model) as ActionResult : View("Login", model)); } returnUrl = returnUrl.IsNotNullOrEmpty() && Url.IsLocalUrl(returnUrl) ? returnUrl : GetDefaultUrl(); if (Request.IsAjaxRequest()) { this.SetAjaxResponseRedirectUrl(returnUrl, true); return(new EmptyResult()); } return(Redirect(returnUrl)); }
private void ValidateCaptcha(SendResetPasswordLinkCommand command) { if (!_captchaService.Validate(command.CaptchaId, command.CaptchaCode)) { throw new ValidationException(ErrorCodes.InvalidCaptcha); } }
public async Task <ApiResponse> Post([FromBody] ContactFormData value) { CaptchaResponse response = await _captchaService.Validate(value.CaptchaToken); if (!response.Success) { return(new ApiResponse() { StatusCode = StatusCodes.Status401Unauthorized, ErrorMessage = "Application Error. Please try again later." }); } if (!ModelState.IsValid) { return(new ApiResponse() { StatusCode = StatusCodes.Status400BadRequest, ErrorMessage = "Form errors. Please input correct data" }); } //Save to mongoDb this._contactRepository.AddContact(new Contact() { FullName = value.FullName, Email = value.EmailAddress, Content = value.Message, Answered = false, Submitted = DateTime.Now }); return(new ApiResponse() { StatusCode = StatusCodes.Status200OK }); }
private void ValidateCaptcha(CreateUserCommand command) { if (!_captchaService.Validate(command.CaptchaId, command.CaptchaCode)) { throw new ValidationException(ErrorCodes.InvalidCaptcha); } }
public async Task <IActionResult> SubmitCommentAsync(CommentFormViewModel model) { if (string.IsNullOrEmpty(Request.Form["_guid_"])) { return(Json(new { result = false, message = "Invalid request." })); } if (!_commentsSettings.EnableComments) { return(Json(new { result = false, message = "Comment Not Allowed! " })); } if (model.PostId <= 0) { return(Json(new { result = false, message = "Error" })); } if (_commentsSettings.EnableFormVerificationCode && !_captchaService.Validate(model.CaptchaId, model.CaptchaCode)) { return(Json(new { result = false, message = _stringLocalizer["Invalid Captcha input."].Value })); } var post = await _postService.GetByIdAsync(model.PostId, new PostIncludeOptions() { IncludeUser = true, }); if (post == null) { return(Json(new { result = false, message = "Error" })); } if (ModelState.IsValid) { var comment = new Comment() { Author = model.Author, Content = model.Content, Website = model.Website, Email = model.Email, ParentId = model.ParentId, PostId = post.Id, }; comment.UserId = _httpContextAccessor.HttpContext.User.GetUserId(); comment.IP = _httpContextAccessor.GetClientIpAddress(); comment.Country = await _iPAddressService.GetIPLocationAsync(comment.IP); comment.IsApproved = !_commentsSettings.EnableCommentsModeration; if (_commentsSettings.TrustAuthenticatedUsers) { comment.IsApproved = await _commentService.IsTrustUserAsync(comment.Email); } await _commentService.InsertAsync(comment); var spamProcessContext = new SpamProcessContext() { Category = "comment", Comment = comment }; await _spamService.ProcessAsync(spamProcessContext); if (spamProcessContext.Passed) { comment.IsApproved = true; comment.IsSpam = false; await _commentService.UpdateAsync(comment); } if (comment.IsApproved) { await _postService.IncreaseCommentsCountAsync(post.Id); } SaveCommentFormUser(new LastCommentFormUserInfo() { Author = model.Author, Email = model.Email, Website = model.Website, }); // event var eventData = new CommentApprovedEventData() { CommentUrl = Url.RouteUrl(RouteNames.Post, new { slug = post.Slug }, Request.Scheme, host: Request.Host.Value, fragment: $"comment-{comment.Id}"), Replay = comment, Post = post, PostAuthor = post.User?.GetDisplayName(), PostAuthorEmail = post.User?.Email, }; if (comment.ParentId != null) { eventData.SourceComment = await _commentService.GetByIdAsync(comment.ParentId.Value); } _eventBus.Publish(eventData); return(Json(new { result = true, commentId = comment.GuidId, parentId = comment.ParentId, url = Url.RouteUrl("Comment", new { commentId = comment.GuidId }) })); } return(Json(new { result = false, message = string.Join(" ", ModelState.Values.SelectMany(t => t.Errors.Select(e => e.ErrorMessage))) })); }
public IActionResult Validate(string id, string code) { var result = _captchaService.Validate(id, code); return(Json(result)); }