fa927f3db7190ade8ae8036e210c827c0a501922
Guides/MVC-Integration/Phase-II-Draft.md
| ... | ... | @@ -118,6 +118,9 @@ namespace Sample_MVCApp.Models { |
| 118 | 118 | **b.** Copy and paste the below code in AccountController.cs |
| 119 | 119 | |
| 120 | 120 | ```csharp |
| 121 | + |
|
| 122 | +//This is how AccountController.cs should look like |
|
| 123 | + |
|
| 121 | 124 | using System; |
| 122 | 125 | using System.Collections.Generic; |
| 123 | 126 | using System.Linq; |
| ... | ... | @@ -128,12 +131,10 @@ using System.Web.Security; |
| 128 | 131 | using Izenda.AdHoc; |
| 129 | 132 | |
| 130 | 133 | |
| 131 | - |
|
| 132 | 134 | namespace Sample_MVCApp.Controllers { |
| 133 | 135 | public class AccountController : Controller { |
| 134 | 136 | |
| 135 | - |
|
| 136 | - |
|
| 137 | + |
|
| 137 | 138 | // Login Action. This leads to login page |
| 138 | 139 | |
| 139 | 140 | public ActionResult Login() { |
| ... | ... | @@ -145,8 +146,6 @@ namespace Sample_MVCApp.Controllers { |
| 145 | 146 | return View(); |
| 146 | 147 | } |
| 147 | 148 | |
| 148 | - |
|
| 149 | - |
|
| 150 | 149 | // Post Register Action |
| 151 | 150 | |
| 152 | 151 | [HttpPost] |
| ... | ... | @@ -165,10 +164,6 @@ namespace Sample_MVCApp.Controllers { |
| 165 | 164 | return View(); |
| 166 | 165 | } |
| 167 | 166 | |
| 168 | - |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - |
|
| 172 | 167 | // Post Login Action |
| 173 | 168 | |
| 174 | 169 | [HttpPost] |
| ... | ... | @@ -196,8 +191,6 @@ namespace Sample_MVCApp.Controllers { |
| 196 | 191 | return View(); |
| 197 | 192 | } |
| 198 | 193 | |
| 199 | - |
|
| 200 | - |
|
| 201 | 194 | //Log Out. |
| 202 | 195 | [HttpPost] |
| 203 | 196 | [ValidateAntiForgeryToken] |
| ... | ... | @@ -214,6 +207,70 @@ namespace Sample_MVCApp.Controllers { |
| 214 | 207 | |
| 215 | 208 | ### Step 6. Add Views |
| 216 | 209 | |
| 210 | + |
|
| 211 | + |
|
| 212 | +**a.** In AccountController.cs, right click on public ActionResult Login()-> Add View->Name it Login -> Add |
|
| 213 | + |
|
| 214 | +**b.** Copy and paste below code in Login.cshtml |
|
| 215 | + |
|
| 216 | +```html |
|
| 217 | +@model Sample_MVCApp.Models.User |
|
| 218 | +@{ |
|
| 219 | + ViewBag.Title = "Login"; |
|
| 220 | +} |
|
| 221 | + |
|
| 222 | + |
|
| 223 | +@{ |
|
| 224 | + ViewBag.Title = "Log in"; |
|
| 225 | +} |
|
| 226 | + |
|
| 227 | +<h2>@ViewBag.Title.</h2> |
|
| 228 | +<div class="row"> |
|
| 229 | + <div class="col-md-8"> |
|
| 230 | + <section id="loginForm"> |
|
| 231 | + @using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" })) { |
|
| 232 | + @Html.AntiForgeryToken() |
|
| 233 | + <h4>Use a local account to log in.</h4> |
|
| 234 | + <hr /> |
|
| 235 | + @Html.ValidationSummary(true, "", new { @class = "text-danger" }) |
|
| 236 | + <div class="form-group"> |
|
| 237 | + @Html.LabelFor(m => m.Username, new { @class = "col-md-2 control-label" }) |
|
| 238 | + <div class="col-md-10"> |
|
| 239 | + @Html.TextBoxFor(m => m.Username, new { @class = "form-control" }) |
|
| 240 | + @Html.ValidationMessageFor(m => m.Username, "", new { @class = "text-danger" }) |
|
| 241 | + </div> |
|
| 242 | + </div> |
|
| 243 | + <div class="form-group"> |
|
| 244 | + @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" }) |
|
| 245 | + <div class="col-md-10"> |
|
| 246 | + @Html.PasswordFor(m => m.Password, new { @class = "form-control" }) |
|
| 247 | + @Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" }) |
|
| 248 | + </div> |
|
| 249 | + </div> |
|
| 250 | + |
|
| 251 | + <div class="form-group"> |
|
| 252 | + <div class="col-md-offset-2 col-md-10"> |
|
| 253 | + <input type="submit" value="Log in" class="btn btn-default" /> |
|
| 254 | + </div> |
|
| 255 | + </div> |
|
| 256 | + <p> |
|
| 257 | + @Html.ActionLink("Register as a new user, "Register") |
|
| 258 | + </p> |
|
| 259 | + } |
|
| 260 | + </section> |
|
| 261 | + </div> |
|
| 262 | + |
|
| 263 | +</div> |
|
| 264 | + |
|
| 265 | +@section Scripts { |
|
| 266 | + @Scripts.Render("~/bundles/jqueryval") |
|
| 267 | +} |
|
| 268 | + |
|
| 269 | + |
|
| 270 | +``` |
|
| 271 | + |
|
| 272 | +Right click on public ActionResult Register() -> Add View -> Name it Register -> Add |
|
| 273 | +Copy and paste the below code to corresponding file |
|
| 217 | 274 | ### Step 7. Add user role model |
| 218 | 275 | |
| 219 | 276 | |
| ... | ... | \ No newline at end of file |