Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8589da4
Role enum, Code cleanup.
viktor436 Nov 23, 2022
047161c
Comments CRUD functionality added.
viktor436 Dec 9, 2022
e64b0a7
capthca1
viktor436 Dec 13, 2022
6674202
DI of configuration
viksuper555 Dec 13, 2022
f053d48
merge with dev
viktor436 Dec 13, 2022
6752968
Post categories, bug fixes.
viktor436 Dec 15, 2022
64e025b
Merge branch 'dev' into ViktorsTestingBranch
viktor436 Dec 15, 2022
63faf3b
Merge pull request #17 from viksuper555/ViktorsTestingBranch
viktor436 Dec 15, 2022
84aaffb
Fixed Home page + CSS
dbozova Dec 15, 2022
f522e30
RoleRequests visible only to Administrator
viktor436 Dec 15, 2022
2a4565b
Merge branch 'dev' of https://github.com/viksuper555/DoctorSystem int…
viktor436 Dec 15, 2022
24cc8e3
Display comment creator. Display post category.Code cleanup.
viktor436 Dec 15, 2022
772e684
MyPosts is working now.User can onlyvedit/delete his posts/comments.
viktor436 Dec 15, 2022
97dc7dc
Posts are displayed in the right order.
viktor436 Dec 15, 2022
4ff1317
Editing of CSS on the create post form
dbozova Dec 15, 2022
97f0be6
changed css of posting actions
dbozova Dec 15, 2022
237f668
Authorization bug fixed.
viktor436 Dec 15, 2022
9524a4d
Merge branch 'dev' of https://github.com/viksuper555/DoctorSystem int…
viktor436 Dec 15, 2022
060802f
Bug patient access denied resolved. Code improvements.
viktor436 Dec 18, 2022
8134828
"Dr." is auto displayed before full name .
viktor436 Dec 18, 2022
77adf1b
Program
viksuper555 Dec 19, 2022
8bf50c6
merge
viksuper555 Dec 19, 2022
c23ec95
Anti-XSS
viksuper555 Dec 19, 2022
744f2f9
middleware
viksuper555 Dec 19, 2022
d8a178f
No exception on Middleware detection
viksuper555 Jan 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Areas/Identity/Pages/Account/Register.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<label asp-for="Input.LastName"></label>
<span asp-validation-for="Input.LastName" class="text-danger"></span>
</div>
<div class="form-floating">
<input asp-for="Input.PhoneNumber" class="form-control" aria-required="true" />
<label asp-for="Input.PhoneNumber"></label>
<span asp-validation-for="Input.PhoneNumber" class="text-danger"></span>
</div>
<div class="form-floating">
<select asp-for="Input.Gender">
<option value="M">Male</option>
Expand Down Expand Up @@ -60,6 +65,7 @@
<label asp-for="Input.DoctorUID" style="display:none;"></label>
<span asp-validation-for="Input.DoctorUID" class="text-danger"></span>
</div>
<div class="g-recaptcha" data-sitekey="@ViewData["ReCaptchaKey"]"></div>
<button id="registerSubmit" type="submit" class="w-100 btn btn-lg btn-primary">Register</button>
</form>
</div>
Expand Down Expand Up @@ -112,4 +118,5 @@
})
})
</script>
<script src='https://www.google.com/recaptcha/api.js'></script>
}
66 changes: 58 additions & 8 deletions Areas/Identity/Pages/Account/Register.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
using DoctorSystem.Data;
using DoctorSystem.Data.Migrations;
using Microsoft.Extensions.Hosting;
using DoctorSystem.Misc;
using Newtonsoft.Json.Linq;
using System.Net;
using DoctorSystem.Singleton;
using Microsoft.Extensions.Options;

//using Microsoft.Extensions.Configuration;
//using Microsoft.Extensions.Configuration.Json;

namespace DoctorSystem.Areas.Identity.Pages.Account
{
Expand All @@ -38,8 +46,10 @@ public class RegisterModel : PageModel
private readonly RoleManager<IdentityRole> _roleManager;
private readonly ApplicationDbContext _context;

private readonly Config _config;

public RegisterModel(
IOptions<Config> config,
UserManager<DefaultUser> userManager,
IUserStore<DefaultUser> userStore,
SignInManager<DefaultUser> signInManager,
Expand All @@ -48,6 +58,7 @@ public RegisterModel(
RoleManager<IdentityRole> roleManager,
ApplicationDbContext context)
{
_config = config.Value;
_context = context;
_roleManager = roleManager;
_userManager = userManager;
Expand Down Expand Up @@ -83,7 +94,7 @@ public RegisterModel(
/// </summary>
public class InputModel
{
[Display(Name = "Doctor UID")]
[Display(Name = "Doctor UIN")]
public string DoctorUID { get; set; }

[Display(Name = "Birth Date")]
Expand All @@ -98,6 +109,11 @@ public class InputModel

[Display(Name = "Gender")]
public string Gender { get; set; }

[Phone]
[Display(Name = "Telephone Number")]
public string PhoneNumber { get; set; }

/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
Expand Down Expand Up @@ -137,27 +153,41 @@ public async Task OnGetAsync(string returnUrl = null)
{
ReturnUrl = returnUrl;
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();

ViewData["ReCaptchaKey"] = _config.CaptchaKey;

}

public async Task<IActionResult> OnPostAsync(string returnUrl = null)
{
returnUrl ??= Url.Content("~/");
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
ViewData["ReCaptchaKey"] = _config.CaptchaKey;

if (ModelState.IsValid)
{
if (!ReCaptchaPassed(
Request.Form["g-recaptcha-response"],
_config.CaptchaSecret,
_logger
))
{
ModelState.AddModelError(string.Empty, "Go home, Robot, Go home. You failed our Captcha.");
return Page();
}

var user = CreateUser();
user.DateOfBirth = Input.DateOfBirth;
user.FirstName = Input.FirstName;
user.LastName = Input.LastName;
user.Gender = Input.Gender;
if (Input.Role == "Patient")
user.PhoneNumber = Input.PhoneNumber;
if (Input.Role == Role.Patient)
{
await _userManager.AddToRoleAsync(user, "Patient");
await _userManager.AddToRoleAsync(user, Role.Patient);
}
else
{
await _userManager.AddToRoleAsync(user, "Guest");
await _userManager.AddToRoleAsync(user, Role.Guest);
user.DoctorUID = Input.DoctorUID;
}

Expand All @@ -180,16 +210,16 @@ public async Task<IActionResult> OnPostAsync(string returnUrl = null)
{
if (Input.Role == null)
{
await _userManager.AddToRoleAsync(user, "Guest");
await _userManager.AddToRoleAsync(user, Role.Guest);
}
else
{
if (Input.Role != "Doctor")
if (Input.Role != Role.Doctor)
{
await _userManager.AddToRoleAsync(user, Input.Role);

}
await _userManager.AddToRoleAsync(user, "Guest");
await _userManager.AddToRoleAsync(user, Role.Guest);
}
_logger.LogInformation("User created a new account with password.");

Expand Down Expand Up @@ -247,5 +277,25 @@ private IUserEmailStore<DefaultUser> GetEmailStore()
}
return (IUserEmailStore<DefaultUser>)_userStore;
}

public static bool ReCaptchaPassed(string gRecaptchaResponse, string secret, ILogger logger)
{
HttpClient httpClient = new HttpClient();
var res = httpClient.GetAsync($"https://www.google.com/recaptcha/api/siteverify?secret={secret}&response={gRecaptchaResponse}").Result;
if (res.StatusCode != HttpStatusCode.OK)
{
logger.LogError("Error while sending request to ReCaptcha");
return false;
}

string JSONres = res.Content.ReadAsStringAsync().Result;
dynamic JSONdata = JObject.Parse(JSONres);
if (JSONdata.success != "true")
{
return false;
}

return true;
}
}
}
24 changes: 0 additions & 24 deletions Controllers/PostingController.cs

This file was deleted.

Loading