Last active
August 29, 2015 14:23
-
-
Save shrayasr/9821d749cd9ac132deb3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>@ViewBag.Title</title> | |
@RenderSection("Scripts", false) | |
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" /> | |
@(Html.Telerik().StyleSheetRegistrar().DefaultGroup(group => group.Add("telerik.common.css").Add("telerik.black.css").Combined(true).Compress(true)))</head> | |
<body> | |
<div class="page"> | |
<header> | |
<div id="title"> | |
<h1>My MVC Application</h1> | |
</div> | |
@(Html.Telerik().Menu() | |
.Name("menu") | |
.Items(menu => { | |
menu.Add().Text("Home").Action("Index", "Home"); | |
menu.Add().Text("Login").Action("Login", "Account").Visible(!User.Identity.IsAuthenticated); | |
menu.Add().Text("Cards").Action("Index", "Items").Visible(User.Identity.IsAuthenticated); | |
menu.Add().Text("Logout").Action("Logout", "Account").Visible(User.Identity.IsAuthenticated); | |
})) | |
<div style="clear:both;"></div> | |
</header> | |
<section id="main"> | |
@RenderBody() | |
</section> | |
<footer> | |
</footer> | |
</div> | |
@(Html.Telerik().ScriptRegistrar().DefaultGroup(group => group.Combined(true).Compress(true)))</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AccountController : Controller | |
{ | |
// | |
// GET: /Account/ | |
public ActionResult Index() | |
{ | |
return RedirectToAction("Login"); | |
} | |
public ActionResult Login() | |
{ | |
return View("Login"); | |
} | |
[HttpPost] | |
public ActionResult Login(LoginViewModel login) | |
{ | |
if (!ModelState.IsValid) | |
{ | |
ViewBag.Error = "Form is not valid; please review and try again."; | |
return View("Login"); | |
} | |
if (login.Username == "user" && login.Password == "password") | |
FormsAuthentication.RedirectFromLoginPage(login.Username, true); | |
ViewBag.Error = "Credentials invalid. Please try again."; | |
return View("Login"); | |
} | |
public ActionResult Logout() | |
{ | |
Session.Clear(); | |
FormsAuthentication.SignOut(); | |
return RedirectToAction("Index", "Home"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model NamesUp.Web.Models.LoginViewModel | |
@{ | |
ViewBag.Title = "Login"; | |
} | |
<h2>Login</h2> | |
@if (ViewBag.Error != null) { | |
<p class="error">@Html.Raw(ViewBag.Error)</p> | |
} | |
@using (Html.BeginForm()) { | |
@Html.AntiForgeryToken() | |
@Html.ValidationSummary(true) | |
<fieldset> | |
<legend>Login</legend> | |
<div class="editor-label"> | |
@Html.LabelFor(model => model.Username) | |
</div> | |
<div class="editor-field"> | |
@Html.EditorFor(model => model.Username) | |
@Html.ValidationMessageFor(model => model.Username) | |
</div> | |
<div class="editor-label"> | |
@Html.LabelFor(model => model.Password) | |
</div> | |
<div class="editor-field"> | |
@Html.PasswordFor(model => model.Password) | |
@Html.ValidationMessageFor(model => model.Password) | |
</div> | |
<p> | |
<input type="submit" value="Login" /> | |
</p> | |
</fieldset> | |
} | |
<div> | |
@Html.ActionLink("Back to List", "Index") | |
</div> | |
@section Scripts { | |
@Scripts.Render("~/bundles/jqueryval") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LoginViewModel | |
{ | |
[Required] | |
public string Username { get; set; } | |
[Required] | |
public string Password { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<authentication mode="Forms"> | |
<forms loginUrl="~/Account/Login" timeout="2880" defaultUrl="~/Home" /> | |
</authentication> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment