User account detial & login screen

This commit is contained in:
Astrian Zheng 2023-09-15 18:40:22 +10:00
parent 8555927086
commit 6340e48cf2
5 changed files with 121 additions and 31 deletions

View File

@ -154,6 +154,27 @@ namespace FIT5032_Assignment.Controllers
public ActionResult Index() public ActionResult Index()
{ {
// If user logged in, show user name
if (Request.Cookies["psg_auth_token"] != null)
{
var user = loginVerify(Request.Cookies["psg_auth_token"].Value);
if (user != null)
{
var db = new Database1Entities();
var credential = db.Credentials.Where(res => (res.uniqueIdCode == user) && (res.provider == 0));
if (credential.Count() != 0)
{
var userUuid = credential.First().user;
var dbUser = db.Users.Where(res => res.uuid == userUuid);
if (dbUser.Count() != 0)
{
ViewBag.displayname = dbUser.First().displayName;
ViewBag.avatar = dbUser.First().avatar;
ViewBag.role = dbUser.First().role == 1 ? "Patient" : "Doctor";
}
}
}
}
return View(); return View();
} }
@ -219,7 +240,7 @@ namespace FIT5032_Assignment.Controllers
// MD5 hash email to get avatar from gravatar // MD5 hash email to get avatar from gravatar
string md5Email = GetMd5Hash(emailaddress); string md5Email = GetMd5Hash(emailaddress);
string avatarUrl = "https://www.gravatar.com/avatar/" + md5Email; string avatarUrl = "https://www.gravatar.com/avatar/" + md5Email + "?s=200";
// Create a new credential and a new user // Create a new credential and a new user
string userUuid = Guid.NewGuid().ToString(); string userUuid = Guid.NewGuid().ToString();

View File

@ -309,6 +309,7 @@
<Content Include="Views\Home\InitialPasskey.cshtml" /> <Content Include="Views\Home\InitialPasskey.cshtml" />
<Content Include="Views\Home\LoginRedirect.cshtml" /> <Content Include="Views\Home\LoginRedirect.cshtml" />
<Content Include="Views\Home\CompleteProfile.cshtml" /> <Content Include="Views\Home\CompleteProfile.cshtml" />
<Content Include="Views\Home\View.cshtml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Views\Test\" /> <Folder Include="Views\Test\" />

View File

@ -12,8 +12,7 @@
<Controller_SelectedScaffolderID>MvcControllerWithContextScaffolder</Controller_SelectedScaffolderID> <Controller_SelectedScaffolderID>MvcControllerWithContextScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath> <Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
<WebStackScaffolding_ControllerDialogWidth>600</WebStackScaffolding_ControllerDialogWidth> <WebStackScaffolding_ControllerDialogWidth>600</WebStackScaffolding_ControllerDialogWidth>
<WebStackScaffolding_LayoutPageFile> <WebStackScaffolding_LayoutPageFile>~/Views/Shared/_Layout.cshtml</WebStackScaffolding_LayoutPageFile>
</WebStackScaffolding_LayoutPageFile>
<WebStackScaffolding_IsLayoutPageSelected>True</WebStackScaffolding_IsLayoutPageSelected> <WebStackScaffolding_IsLayoutPageSelected>True</WebStackScaffolding_IsLayoutPageSelected>
<WebStackScaffolding_IsPartialViewSelected>False</WebStackScaffolding_IsPartialViewSelected> <WebStackScaffolding_IsPartialViewSelected>False</WebStackScaffolding_IsPartialViewSelected>
<WebStackScaffolding_IsReferencingScriptLibrariesSelected>True</WebStackScaffolding_IsReferencingScriptLibrariesSelected> <WebStackScaffolding_IsReferencingScriptLibrariesSelected>True</WebStackScaffolding_IsReferencingScriptLibrariesSelected>

View File

@ -1,33 +1,53 @@
@{ @{
ViewBag.Title = "Home Page"; ViewBag.Title = "Home Page";
// Check login status
bool loginStatus = false;
// cookie
if (Request.Cookies["psg_auth_token"] == null)
{
loginStatus = false;
}
else
{
loginStatus = true;
}
} }
<main> @section Scripts {
<section class="row" aria-labelledby="aspnetTitle"> @Scripts.Render("~/bundles/jqueryval")
<h1 id="title">ASP.NET</h1> }
<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
<p><a href="https://asp.net" class="btn btn-primary btn-md">Learn more &raquo;</a></p>
</section>
<div class="row"> @if (loginStatus)
<section class="col-md-4" aria-labelledby="gettingStartedTitle"> {
<h2 id="gettingStartedTitle">Getting started</h2> <img src="@ViewBag.avatar" alt="Avatar" style="width:200px" />
<p> <h1>Welcome back, @ViewBag.displayname</h1>
ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that <p><b>Email address</b> <span id="emailfield">john.appleseed@mac.com</span></p>
enables a clean separation of concerns and gives you full control over markup <p><b>Role</b> @ViewBag.role</p>
for enjoyable, agile development. <p><button id="logoutbutton">Log out</button></p>
</p>
<p><a class="btn btn-outline-dark" href="https://go.microsoft.com/fwlink/?LinkId=301865">Learn more &raquo;</a></p> <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</section> <script type="module">
<section class="col-md-4" aria-labelledby="librariesTitle"> import { Passage } from "https://cdn.passage.id/passage-js.js"
<h2 id="librariesTitle">Get more libraries</h2>
<p>NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.</p> const passage = new Passage('ZHM5whW5xsZEczTn2loffzjN');
<p><a class="btn btn-outline-dark" href="https://go.microsoft.com/fwlink/?LinkId=301866">Learn more &raquo;</a></p> const user = passage.getCurrentUser();
</section> const userInfo = await user.userInfo();
<section class="col-md-4" aria-labelledby="hostingTitle"> console.log(userInfo)
<h2 id="hostingTitle">Web Hosting</h2> document.getElementById("emailfield").innerHTML = userInfo.email;
<p>You can easily find a web hosting company that offers the right mix of features and price for your applications.</p> $("#logoutbutton").on("click", async () => {
<p><a class="btn btn-outline-dark" href="https://go.microsoft.com/fwlink/?LinkId=301867">Learn more &raquo;</a></p> await passage.getCurrentSession().signOut();
</section> window.location.href = "/";
</div> });
</main> </script>
}
else
{
<h1>Login</h1>
<p>No account? <a href="/CreateAccount">Register here!</a></p>
<passage-login app-id="ZHM5whW5xsZEczTn2loffzjN" />
<script src="https://psg.so/web.js"></script>
}

View File

@ -0,0 +1,49 @@
@model FIT5032_Assignment.Models.CompleteProfileForm
@{
ViewBag.Title = "View";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>View</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>CompleteProfileForm</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.fullname, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.fullname, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.fullname, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.role, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.role, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.role, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}