You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

128 lines
3.7 KiB

  1. @page "/login"
  2. @using BootStrapComponents
  3. @using Components
  4. @using Models.Identity
  5. @layout LayoutWithoutMenu
  6. <img src="/assets/images/logo.png" class="@BT.CenterBlock m-2" style="max-width:30%;" />
  7. <style>
  8. div.login-fields-container {
  9. margin-top: 5vh;
  10. border-radius: 2em;
  11. border-top: solid 0.2em orange;
  12. height: 90vh;
  13. padding: 1em;
  14. }
  15. </style>
  16. <div class="@BT.Background(ColorType.white) login-fields-container">
  17. <EditForm Model="@OtpLoginModel" OnValidSubmit="Submit">
  18. <DataAnotationsValidator />
  19. <p class="@BT.CenterBlock @BT.TextAlign(TextAlignment.center) h4" style="margin-top:2vh">
  20. ورود / ثبت نام
  21. </p>
  22. <p class="@(BT.TextAlign(TextAlignment.center)) @BT.TextColor(ColorType.secondary) @BT.MarginTop(5) h6">
  23. @if (!WaitForOtp)
  24. {
  25. <span>
  26. لطفا شماره همراه خود را وارد کنید.
  27. </span>
  28. }
  29. else
  30. {
  31. <span>
  32. لطفا کد تائید پیامک شده را وارد کنید.
  33. </span>
  34. }
  35. </p>
  36. @if (!WaitForOtp)
  37. {
  38. <span>
  39. <input placeholder="تلفن همراه" @bind="OtpLoginModel.Username" class="@BT.Input @BT.MarginTop(5)" type="tel">
  40. </span>
  41. }
  42. else
  43. {
  44. <span>
  45. <input placeholder="کد تائید" @bind="LoginModel.Password" class="@BT.Input @BT.MarginTop(5)" type="number">
  46. </span>
  47. }
  48. <p class="h6 @BT.TextAlign(TextAlignment.center)" style="font-size:2vh;margin-top:5vh;">
  49. ورود شما به معنای پذیرش
  50. <a href="/login">
  51. شرایط حق‌تو و قوانین حریم خصوصی
  52. </a>
  53. است
  54. </p>
  55. <button type="submit" class="@BT.Button(ColorType.primary) @BT.CenterBlock" style="margin-top:5vh">
  56. ورود
  57. </button>
  58. <div class="@BT.Row @BT.TextAlign(TextAlignment.center)" style="margin-top:12vh">
  59. <hr class="@BT.TextColor(ColorType.warning)" />
  60. <p>
  61. © تمامی حقوق برای حقتو محفوظ میباشد
  62. </p>
  63. <br />
  64. <p>
  65. ورژن 1.1
  66. </p>
  67. </div>
  68. </EditForm>
  69. </div>
  70. <style>
  71. .form {
  72. display: flex;
  73. flex-direction: column;
  74. align-items: center;
  75. align-content: center;
  76. }
  77. .form-control {
  78. margin: 5px 5px;
  79. }
  80. </style>
  81. @code {
  82. private bool WaitForOtpMode { get; set; } = true;
  83. protected OTPLoginModel OtpLoginModel { get; set; } = new();
  84. protected bool WaitForOtp { set; get; } = false;
  85. public async void Submit()
  86. {
  87. if (WaitForOtp)
  88. await RequestLogin();
  89. else
  90. await RequestVerificationCode();
  91. }
  92. protected async Task RequestVerificationCode()
  93. {
  94. var response = await _userUtils.SendVerificationRequest(OtpLoginModel);
  95. if (response.IsSuccessStatusCode)
  96. WaitForOtp = true;
  97. StateHasChanged();
  98. }
  99. protected LoginModel LoginModel { get; set; } = new();
  100. protected async Task RequestLogin()
  101. {
  102. LoginModel.Username = OtpLoginModel.Username;
  103. var response = await _userUtils.LoginWithPasswordRequest(LoginModel);
  104. if (response.IsSuccessStatusCode)
  105. {
  106. var result = await response.Content.ReadFromJsonAsync<Models.Identity.PlainToken>();
  107. await LocalStorage.SetItemAsync(Statics.LoginTokenKey, result.AccessToken);
  108. NavManager.NavigateTo("/dashboard");
  109. }
  110. }
  111. }