public ActionResult CreateUser() { Captcha captcha = _captchaService.GenerateCaptcha(); Session["CaptchaQuestion"] = captcha.Question; Session["CaptchaAnswer"] = captcha.Answer; return(View()); }
public ActionResult CreateUser() { // _captchaService.CreateQuestion(new Captcha { Question = "2+2=?", Answer = "four", IsActive = true }); Captcha captcha = _captchaService.GenerateCaptcha(); Session["CaptchaQuestion"] = captcha.Question; Session["CaptchaAnswer"] = captcha.Answer; return(View()); }
protected override DriverResult Display(QuestionnairePart part, string displayType, dynamic shapeHelper) { if (displayType == "Summary") { return(ContentShape("Parts_Questionnaire_Summary", () => shapeHelper.Parts_Questionnaire_Summary( QuestionsCount: part.Questions.Count(c => c.Published) ))); } if (displayType == "SummaryAdmin") { return(ContentShape("Parts_Questionnaire_SummaryAdmin", () => shapeHelper.Parts_Questionnaire_SummaryAdmin( QuestionsCount: part.Questions.Count(c => c.Published), QuestionsTotalCount: part.Questions.Count() ))); } if (IsAuthorized) { var partSettings = part.Settings.TryGetModel <QuestionnairesPartSettingVM>(); if (partSettings == null) { partSettings = new QuestionnairesPartSettingVM(); } QuestionnaireWithResultsViewModel viewModel; if (_controllerContextAccessor.Context != null) { bool questionnaireHasJustBeenSubmitted; // valorizza il context var questionnaireContext = partSettings.QuestionnaireContext; var currentUser = _orchardServices.WorkContext.CurrentUser; questionnaireContext = _tokenizer.Replace(questionnaireContext, new Dictionary <string, object> { { "Content", _currentContentAccessor.CurrentContentItem } }); // TempData may contains current answers to the current questionnaire instance. // So if TempData is not null means that the current user just answered to the questionnaire. var fullModelWithAnswers = _controllerContextAccessor.Context.Controller.TempData["QuestUpdatedEditModel"]; var hasAcceptedTerms = _controllerContextAccessor.Context.Controller.TempData["HasAcceptedTerms"]; questionnaireHasJustBeenSubmitted = fullModelWithAnswers != null; viewModel = _questServices.BuildViewModelWithResultsForQuestionnairePart(part); //Modello mappato senza risposte if (currentUser != null && fullModelWithAnswers == null && partSettings.ShowLatestAnswers) { //if the current questionnaire instance has not answers and settings require to show current user's latest answers fullModelWithAnswers = _questServices.GetMostRecentAnswersInstance(part, currentUser, questionnaireContext); } viewModel.Context = questionnaireContext; // limita la lunghezza del context a 255 chars if (viewModel.Context.Length > 255) { viewModel.Context = viewModel.Context.Substring(0, 255); } // valorizza le altre proprietà del viewModel if (fullModelWithAnswers != null) // Mappo le risposte { var risposteModel = (QuestionnaireWithResultsViewModel)fullModelWithAnswers; //Mappo l'oggetto principale per evitare che mi richieda di accettare le condizioni viewModel.MustAcceptTerms = risposteModel.MustAcceptTerms; viewModel.HasAcceptedTerms = risposteModel.HasAcceptedTerms; for (var i = 0; i < viewModel.QuestionsWithResults.Count(); i++) { var question = viewModel.QuestionsWithResults[i]; // Gets the userAnswers having same question id (Id) and same question text (Question) of question of the content. // If missing, means that the current user never answered to that question. var questionWithAnswers = risposteModel.QuestionsWithResults.FirstOrDefault(x => x.Id == question.Id && x.Question == question.Question); if (questionWithAnswers != null) { switch (viewModel.QuestionsWithResults[i].QuestionType) { case QuestionType.OpenAnswer: viewModel.QuestionsWithResults[i].OpenAnswerAnswerText = questionWithAnswers.OpenAnswerAnswerText; break; case QuestionType.SingleChoice: viewModel.QuestionsWithResults[i].SingleChoiceAnswer = questionWithAnswers.SingleChoiceAnswer; break; case QuestionType.MultiChoice: for (var j = 0; j < viewModel.QuestionsWithResults[i].AnswersWithResult.Count(); j++) { var choice = question.AnswersWithResult[j]; // Gets the answers of question having same answer id (Id) and same answer text (userResponse.AnswerText > answer.Answer) of the answer of the content. // If missing, means that the current user never answered with current option. var answer = questionWithAnswers.AnswersWithResult.SingleOrDefault(x => x.Id == choice.Id && (questionnaireHasJustBeenSubmitted || x.AnswerText == choice.Answer)); viewModel.QuestionsWithResults[i].AnswersWithResult[j].Answered = answer != null ? answer.Answered : false; } break; } } } } else if (hasAcceptedTerms != null) // l'utente ha appena accettato le condizionoi { viewModel.HasAcceptedTerms = (bool)_controllerContextAccessor.Context.Controller.TempData["HasAcceptedTerms"]; } } else { // There's not a WorkContext viewModel = _questServices.BuildViewModelWithResultsForQuestionnairePart(part); //Modello mappato senza risposte } if (viewModel.UseRecaptcha) // se è previsto un recaptcha creo l'html e il js del recaptcha { viewModel.CaptchaHtmlWidget = _capthcaServices.GenerateCaptcha(); } return(ContentShape("Parts_Questionnaire_FrontEnd_Edit", () => shapeHelper.EditorTemplate(TemplateName: "Parts/Questionnaire_FrontEnd_Edit", Model: viewModel, Prefix: Prefix))); } else { throw new OrchardSecurityException(T("You have to be logged in, before answering a questionnaire!")); } }
protected override DriverResult Display(QuestionnairePart part, string displayType, dynamic shapeHelper) { if (displayType == "Summary") { return(ContentShape("Parts_Questionnaire_Summary", () => shapeHelper.Parts_Questionnaire_Summary( QuestionsCount: part.Questions.Count(c => c.Published) ))); } if (displayType == "SummaryAdmin") { return(ContentShape("Parts_Questionnaire_SummaryAdmin", () => shapeHelper.Parts_Questionnaire_SummaryAdmin( QuestionsCount: part.Questions.Count(c => c.Published), QuestionsTotalCount: part.Questions.Count() ))); } if (IsAuthorized) { var viewModel = _questServices.BuildViewModelWithResultsForQuestionnairePart(part); //Modello mappato senza risposte if (_controllerContextAccessor.Context != null) { // valorizza il context var questionnaireContext = part.Settings.GetModel <QuestionnairesPartSettingVM>().QuestionnaireContext; //questionnaireContext = _tokenizer.Replace(questionnaireContext, new Dictionary<string, object> {{ "Content", part.ContentItem}}); questionnaireContext = _tokenizer.Replace(questionnaireContext, new Dictionary <string, object> { { "Content", _currentContentAccessor.CurrentContentItem } }); viewModel.Context = questionnaireContext; // limita la lunghezza del context a 255 chars if (viewModel.Context.Length > 255) { viewModel.Context = viewModel.Context.Substring(0, 255); } // valorizza le altre proprietà del viewModel var fullModelWithAnswers = _controllerContextAccessor.Context.Controller.TempData["QuestUpdatedEditModel"]; var hasAcceptedTerms = _controllerContextAccessor.Context.Controller.TempData["HasAcceptedTerms"]; if (fullModelWithAnswers != null) // Mappo le risposte { var risposteModel = (QuestionnaireWithResultsViewModel)fullModelWithAnswers; //Mappo l'oggetto principale per evitare che mi richieda di accettare le condizioni viewModel.MustAcceptTerms = risposteModel.MustAcceptTerms; viewModel.HasAcceptedTerms = risposteModel.HasAcceptedTerms; for (var i = 0; i < viewModel.QuestionsWithResults.Count(); i++) { switch (viewModel.QuestionsWithResults[i].QuestionType) { case QuestionType.OpenAnswer: viewModel.QuestionsWithResults[i].OpenAnswerAnswerText = risposteModel.QuestionsWithResults[i].OpenAnswerAnswerText; break; case QuestionType.SingleChoice: viewModel.QuestionsWithResults[i].SingleChoiceAnswer = risposteModel.QuestionsWithResults[i].SingleChoiceAnswer; break; case QuestionType.MultiChoice: for (var j = 0; j < viewModel.QuestionsWithResults[i].AnswersWithResult.Count(); j++) { viewModel.QuestionsWithResults[i].AnswersWithResult[j].Answered = risposteModel.QuestionsWithResults[i].AnswersWithResult[j].Answered; } break; } } } else if (hasAcceptedTerms != null) // l'utente ha appena accettato le condizionoi { viewModel.HasAcceptedTerms = (bool)_controllerContextAccessor.Context.Controller.TempData["HasAcceptedTerms"]; } } if (viewModel.UseRecaptcha) // se è previsto un recaptcha creo l'html e il js del recaptcha { viewModel.CaptchaHtmlWidget = _capthcaServices.GenerateCaptcha(); } return(ContentShape("Parts_Questionnaire_FrontEnd_Edit", () => shapeHelper.Parts_Questionnaire_FrontEnd_Edit( Questionnaire: viewModel, Prefix: Prefix))); } else { throw new OrchardSecurityException(T("You have to be logged in, before answering a questionnaire!")); } }