#190 posting signup api (phase 1 pre verify)

This commit is contained in:
Hamid Reza Mohammadi 2021-08-18 12:03:29 +04:30
parent 89c5b2615e
commit e0b3122c58
4 changed files with 78 additions and 9 deletions

View File

@ -24,6 +24,7 @@
</div>
}
else
if (Model.SignupPhase1)
{
<form method="post">
<table>
@ -41,6 +42,9 @@
</td>
<td>
<img src="@Model.CaptchaImageUrl" />
<input type="hidden" asp-for="SignUpViewModel.ClientAppName" />
<input type="hidden" asp-for="SignUpViewModel.Language" />
<input type="hidden" asp-for="SignUpViewModel.CallbackUrl" />
<input type="hidden" asp-for="SignUpViewModel.CaptchaImageId" />
</td>
</tr>
@ -55,14 +59,39 @@
<tr>
<td colspan="2"><input type="submit" name="submit" id="submit" value="ادامه" /></td>
</tr>
</table>
<div>@Model.LastError</div>
<div><p style="color:red">@Model.LastError</p></div>
</form>
}
else
if (Model.SignupVerifyEmailPhase)
{
<form method="post">
<table>
<tr>
<td colspan="2">
<p>لطفا پست الکترونیکی خود را بررسی کنید. در صورتی که نشانی پست الکترونیکی خود را درست وارد کرده باشید نامه‌ای از گنجور دریافت کرده‌اید که حاوی یک رمز است. </p>
<p>رمز دریافتی را در کادر زیر وارد کرده، روی دکمهٔ «ادامه» کلیک کنید</p>
<p style="color:red">تذکر: ممکن است نامه به پوشه اسپم منتقل شده باشد</p>
</td>
</tr>
<tr>
<td>
<span class="inputlabel">رمز دریافتی:</span>
</td>
<td>
<input asp-for="Secret" placeholder="رمز دریافتی" />
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" id="submit" value="ادامه" /></td>
</tr>
</table>
<div><p style="color:red">@Model.LastError</p></div>
</form>
}
</div>
</div>

View File

@ -1,9 +1,10 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json;
using RSecurityBackend.Models.Auth.ViewModels;
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace GanjooRazor.Pages
@ -25,14 +26,32 @@ namespace GanjooRazor.Pages
public string CaptchaImageUrl { get; set; }
public bool SignupPhase1 { get; set; }
public bool SignupVerifyEmailPhase { get; set; }
public bool SignupFinalPhase { get; set; }
[BindProperty]
public UnverifiedSignUpViewModel SignUpViewModel { get; set; }
[BindProperty]
public string Secret { get; set; }
public async Task<IActionResult> OnGetAsync()
{
LoggedIn = !string.IsNullOrEmpty(Request.Cookies["Name"]);
LastError = Request.Query["error"];
LastError = "";
SignupPhase1 = true;
SignupVerifyEmailPhase = false;
SignupFinalPhase = false;
SignUpViewModel = new UnverifiedSignUpViewModel();
SignUpViewModel = new UnverifiedSignUpViewModel()
{
ClientAppName = "وبگاه گنجور",
Language = "fa-IR",
CallbackUrl = "https://ganjoor.net/signup"
};
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/users/captchaimage");
response.EnsureSuccessStatusCode();
@ -41,6 +60,27 @@ namespace GanjooRazor.Pages
CaptchaImageUrl = $"{APIRoot.InternetUrl}/api/rimages/{SignUpViewModel.CaptchaImageId}.jpg";
return Page();
}
public async Task<IActionResult> OnPostAsync(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());
return Page();
}
SignupPhase1 = false;
SignupVerifyEmailPhase = true;
return Page();
}
}

View File

@ -968,7 +968,7 @@ namespace RSecurityBackend.Controllers
}
/// <summary>
/// verify signup / forgot password
/// verify signup / forgot password / self delete user
/// </summary>
/// <param name="type"></param>
/// <param name="secret"></param>

View File

@ -231,7 +231,7 @@
</member>
<member name="M:RSecurityBackend.Controllers.AppUserControllerBase.VerifySignUp(RSecurityBackend.Models.Auth.Db.RVerifyQueueType,System.String)">
<summary>
verify signup / forgot password
verify signup / forgot password / self delete user
</summary>
<param name="type"></param>
<param name="secret"></param>