1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

Fixed login redirect and added dedicated login page.

Fixed blog url routing
This commit is contained in:
Uncled1023 2015-12-19 21:21:02 -08:00
parent 344985e14a
commit 25673d8570
9 changed files with 57 additions and 8 deletions

View File

@ -19,7 +19,7 @@ namespace Teknik.Areas.Blog
"Blog_dev_blog", // Route name
"dev",
"Blog/{username}", // URL with parameters
new { controller = "Blog", action = "Blog", username = UrlParameter.Optional }, // Parameter defaults
new { controller = "Blog", action = "Blog", username = string.Empty }, // Parameter defaults
new[] { typeof(Controllers.BlogController).Namespace }
);
context.MapSubdomainRoute(
@ -40,7 +40,7 @@ namespace Teknik.Areas.Blog
"Blog_default_blog", // Route name
"blog",
"{username}", // URL with parameters
new { controller = "Blog", action = "Blog", username = UrlParameter.Optional }, // Parameter defaults
new { controller = "Blog", action = "Blog", username = string.Empty }, // Parameter defaults
new[] { typeof(Controllers.BlogController).Namespace }
);
context.MapSubdomainRoute(

View File

@ -29,9 +29,12 @@ namespace Teknik.Areas.Profile.Controllers
[HttpGet]
[AllowAnonymous]
// GET: Profile
public ActionResult Login()
public ActionResult Login(string ReturnUrl)
{
return View(new LoginViewModel());
LoginViewModel model = new LoginViewModel();
model.ReturnUrl = ReturnUrl;
return View("/Areas/Profile/Views/Profile/ViewLogin.cshtml", model);
}
[HttpPost]
@ -46,7 +49,14 @@ namespace Teknik.Areas.Profile.Controllers
if (userValid)
{
FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);
return Json(new { result = "true" });
if (string.IsNullOrEmpty(model.ReturnUrl))
{
return Json(new { result = "true" });
}
else
{
return Redirect(model.ReturnUrl);
}
}
}
return Json(new { error = "Invalid User name or Password." });

View File

@ -14,11 +14,18 @@ namespace Teknik.Areas.Profile
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapSubdomainRoute(
"Profile_dev_login", // Route name
"dev",
"Profile/Login", // URL with parameters
new { controller = "Profile", action = "Login" }, // Parameter defaults
new[] { typeof(Controllers.ProfileController).Namespace }
);
context.MapSubdomainRoute(
"Profile_dev", // Route name
"dev",
"Profile/{username}", // URL with parameters
new { controller = "Profile", action = "Index", username = UrlParameter.Optional }, // Parameter defaults
new { controller = "Profile", action = "Index" }, // Parameter defaults
new[] { typeof(Controllers.ProfileController).Namespace }
);
context.MapSubdomainRoute(
@ -35,6 +42,13 @@ namespace Teknik.Areas.Profile
new { controller = "Profile", action = "Index", username = UrlParameter.Optional }, // Parameter defaults
new[] { typeof(Controllers.ProfileController).Namespace }
);
context.MapSubdomainRoute(
"Profile_default_login", // Route name
"profile",
"Login", // URL with parameters
new { controller = "Profile", action = "Login" }, // Parameter defaults
new[] { typeof(Controllers.ProfileController).Namespace }
);
context.MapSubdomainRoute(
"Profile_default_unique", // Route name
"profile",

View File

@ -25,6 +25,8 @@ namespace Teknik.Areas.Profile.ViewModels
[Display(Name = "Remember Me")]
public bool RememberMe { get; set; }
public string ReturnUrl { get; set; }
public bool IsValid()
{
return IsValid(Username, Password);

View File

@ -3,6 +3,7 @@
@using (Html.BeginForm("Login", "Profile", new { area = "Profile" }, FormMethod.Post, new { id = "loginForm" }))
{
@Html.ValidationMessage("Unable to login.")
<input name="ReturnUrl" id="ReturnUrl" type="hidden" value="@Model.ReturnUrl" />
<div class="form-group">
<input type="text" class="form-control" id="Username" value="" placeholder="Username" name="Username" data-val-required="The Username field is required." data-val="true" />
@Html.ValidationMessageFor(u => u.Username)

View File

@ -0,0 +1,21 @@
@model Teknik.Areas.Profile.ViewModels.LoginViewModel
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="error-template text-center">
<h1>Stay Away!</h1>
<h2>403 Access Denied</h2>
<div class="error-details">
You aren't allowed to see this! If you think you are, then login below.
</div>
<br />
<div class="error-actions">
<div class="col-md-4 col-md-offset-4">
@Html.Partial("../../Areas/Profile/Views/Profile/Login", Model)
</div>
</div>
</div>
</div>
</div>
</div>

View File

@ -240,6 +240,7 @@
<Content Include="Areas\Blog\Views\Blog\Posts.cshtml" />
<Content Include="Areas\Blog\Views\Blog\Post.cshtml" />
<Content Include="Areas\Blog\Views\Blog\ViewPost.cshtml" />
<Content Include="Areas\Profile\Views\Profile\ViewLogin.cshtml" />
<None Include="Properties\PublishProfiles\Teknik Dev.pubxml" />
<None Include="Scripts\jquery-2.1.4.intellisense.js" />
<Content Include="Scripts\bootbox\bootbox.min.js" />

View File

@ -19,7 +19,7 @@
<a href="#" id="services_menu" class="dropdown-toggle" data-toggle="dropdown">Services <strong class="caret"></strong></a>
<ul class="dropdown-menu" role="menu" aria-labelledby="services_menu">
<li>
<a href="@Url.Action("Blog", "Blog", new { area = "Blog" })">Blog</a>
<a href="@Url.Action("Blog", "Blog", new { area = "Blog", username = string.Empty })">Blog</a>
</li>
<li>
<a href="@Url.Action("Index", "Podcast", new { area = "Podcast" })">Podcast</a>

View File

@ -16,7 +16,7 @@
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="RouteDebugger:Enabled" value="false" />
<add key="RouteDebugger:Enabled" value="true" />
</appSettings>
<!--
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.