public async Task <IActionResult> OnGetAsync() { if (!string.IsNullOrEmpty(Request.Query["secret"])) { return(await OnPostPhase2Async(Request.Query["secret"])); } LoggedIn = !string.IsNullOrEmpty(Request.Cookies["Name"]); LastError = ""; SignupPhase1 = true; SignupVerifyEmailPhase = false; SignupFinalPhase = false; SignUpViewModel = new UnverifiedSignUpViewModel() { ClientAppName = "وبگاه گنجور", Language = "fa-IR", CallbackUrl = $"{_configuration["SiteUrl"]}/signup" }; var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/users/captchaimage"); if (!response.IsSuccessStatusCode) { LastError = JsonConvert.DeserializeObject <string>(await response.Content.ReadAsStringAsync()); return(Page()); } SignUpViewModel.CaptchaImageId = JsonConvert.DeserializeObject <Guid>(await response.Content.ReadAsStringAsync()); CaptchaImageUrl = $"{APIRoot.InternetUrl}/api/rimages/{SignUpViewModel.CaptchaImageId}.jpg"; return(Page()); }
public async Task <IActionResult> OnPostPhase1Async(UnverifiedSignUpViewModel signUpViewModel) { LoggedIn = !string.IsNullOrEmpty(Request.Cookies["Name"]); LastError = ""; SignupPhase1 = true; SignupVerifyEmailPhase = false; SignupFinalPhase = false; var response = await _httpClient.PostAsync($"{APIRoot.Url}/api/users/signup", new StringContent(JsonConvert.SerializeObject(SignUpViewModel), Encoding.UTF8, "application/json")); if (!response.IsSuccessStatusCode) { LastError = JsonConvert.DeserializeObject <string>(await response.Content.ReadAsStringAsync()); response = await _httpClient.GetAsync($"{APIRoot.Url}/api/users/captchaimage"); if (!response.IsSuccessStatusCode) { LastError = JsonConvert.DeserializeObject <string>(await response.Content.ReadAsStringAsync()); return(Page()); } ModelState.Clear(); SignUpViewModel = new UnverifiedSignUpViewModel() { ClientAppName = signUpViewModel.ClientAppName, Language = signUpViewModel.Language, CallbackUrl = signUpViewModel.CallbackUrl, Email = signUpViewModel.Email }; SignUpViewModel.CaptchaImageId = JsonConvert.DeserializeObject <Guid>(await response.Content.ReadAsStringAsync()); CaptchaImageUrl = $"{APIRoot.InternetUrl}/api/rimages/{SignUpViewModel.CaptchaImageId}.jpg"; return(Page()); } SignupPhase1 = false; SignupVerifyEmailPhase = true; return(Page()); }
public async Task <IActionResult> SignUp([FromBody] UnverifiedSignUpViewModel signUpViewModel) { if (!IsSignupEnabled()) { return(BadRequest("ثبت نام غیرفعال است.")); } RServiceResult <bool> captchaRes = await _captchaService.Evaluate(signUpViewModel.CaptchaImageId, signUpViewModel.CaptchaValue); if (!string.IsNullOrEmpty(captchaRes.ExceptionString)) { return(BadRequest(captchaRes.ExceptionString)); } if (!captchaRes.Result) { return(BadRequest("مقدار تصویر امنیتی درست وارد نشده است.")); } string clientIPAddress = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(); RServiceResult <RVerifyQueueItem> res = await _appUserService.SignUp(signUpViewModel.Email, clientIPAddress, signUpViewModel.ClientAppName, signUpViewModel.Language); if (res.Result == null) { return(BadRequest(res.ExceptionString)); } try { await _emailSender.SendEmailAsync ( signUpViewModel.Email, GetSignUpEmailSubject(res.Result.Secret), GetSignUpEmailHtmlContent(res.Result.Secret, signUpViewModel.CallbackUrl) ); } catch (Exception exp) { return(BadRequest("Error sending email: " + exp.ToString())); } return(Ok(true)); }