diff --git a/FIT5032-Assignment/Controllers/HomeController.cs b/FIT5032-Assignment/Controllers/HomeController.cs index f0352d9..b0cd8de 100644 --- a/FIT5032-Assignment/Controllers/HomeController.cs +++ b/FIT5032-Assignment/Controllers/HomeController.cs @@ -154,6 +154,27 @@ namespace FIT5032_Assignment.Controllers 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(); } @@ -219,7 +240,7 @@ namespace FIT5032_Assignment.Controllers // MD5 hash email to get avatar from gravatar 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 string userUuid = Guid.NewGuid().ToString(); diff --git a/FIT5032-Assignment/FIT5032-Assignment.csproj b/FIT5032-Assignment/FIT5032-Assignment.csproj index 7bf90dc..12f8ac6 100644 --- a/FIT5032-Assignment/FIT5032-Assignment.csproj +++ b/FIT5032-Assignment/FIT5032-Assignment.csproj @@ -309,6 +309,7 @@ + diff --git a/FIT5032-Assignment/FIT5032-Assignment.csproj.user b/FIT5032-Assignment/FIT5032-Assignment.csproj.user index 971363c..ed08c2e 100644 --- a/FIT5032-Assignment/FIT5032-Assignment.csproj.user +++ b/FIT5032-Assignment/FIT5032-Assignment.csproj.user @@ -12,8 +12,7 @@ MvcControllerWithContextScaffolder root/Common/MVC/Controller 600 - - + ~/Views/Shared/_Layout.cshtml True False True diff --git a/FIT5032-Assignment/Views/Home/Index.cshtml b/FIT5032-Assignment/Views/Home/Index.cshtml index f1948a7..b322e8d 100644 --- a/FIT5032-Assignment/Views/Home/Index.cshtml +++ b/FIT5032-Assignment/Views/Home/Index.cshtml @@ -1,33 +1,53 @@ @{ ViewBag.Title = "Home Page"; + // Check login status + bool loginStatus = false; + + // cookie + + if (Request.Cookies["psg_auth_token"] == null) + { + loginStatus = false; + } + else + { + loginStatus = true; + } + } -
-
-

ASP.NET

-

ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.

-

Learn more »

-
+@section Scripts { + @Scripts.Render("~/bundles/jqueryval") +} -
-
-

Getting started

-

- ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that - enables a clean separation of concerns and gives you full control over markup - for enjoyable, agile development. -

-

Learn more »

-
-
-

Get more libraries

-

NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.

-

Learn more »

-
-
-

Web Hosting

-

You can easily find a web hosting company that offers the right mix of features and price for your applications.

-

Learn more »

-
-
-
\ No newline at end of file +@if (loginStatus) +{ + Avatar +

Welcome back, @ViewBag.displayname

+

Email address john.appleseed@mac.com

+

Role @ViewBag.role

+

+ + + +} +else +{ +

Login

+

No account? Register here!

+ + + +} \ No newline at end of file diff --git a/FIT5032-Assignment/Views/Home/View.cshtml b/FIT5032-Assignment/Views/Home/View.cshtml new file mode 100644 index 0000000..91813ec --- /dev/null +++ b/FIT5032-Assignment/Views/Home/View.cshtml @@ -0,0 +1,49 @@ +@model FIT5032_Assignment.Models.CompleteProfileForm + +@{ + ViewBag.Title = "View"; + Layout = "~/Views/Shared/_Layout.cshtml"; +} + +

View

+ + +@using (Html.BeginForm()) +{ + @Html.AntiForgeryToken() + +
+

CompleteProfileForm

+
+ @Html.ValidationSummary(true, "", new { @class = "text-danger" }) +
+ @Html.LabelFor(model => model.fullname, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.fullname, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.fullname, "", new { @class = "text-danger" }) +
+
+ +
+ @Html.LabelFor(model => model.role, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.role, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.role, "", new { @class = "text-danger" }) +
+
+ +
+
+ +
+
+
+} + +
+ @Html.ActionLink("Back to List", "Index") +
+ +@section Scripts { + @Scripts.Render("~/bundles/jqueryval") +}