Database Reference
In-Depth Information
Login Controller
In the LoginController class, you will use the method named Index to control the flow of the login process, as
shown in Listing 7-20. Inside the Index controller method, the GraphStoryInterface will pass the login method of
the UserInterface the GraphStory object from the HTML form shown in Listing 7-20 and then return a GraphStory
object back to the controller.
Listing 7-20. The login Controller
public ActionResult Index(GraphStory graphStory)
{
graphStory = this.graphStoryService.userInterface.login(graphStory);
if (graphStory.haserror == false)
{
HttpCookie userCookie = new HttpCookie(graphstoryUserAuthKey);
userCookie.Value = graphStory.user.username;
userCookie.Expires = DateTime.Now.AddDays(20);
Response.Cookies.Add(userCookie);
return RedirectToRoute(new { controller = "Social", action = "Index" });
}
else
{
ViewBag.error = graphStory.error;
return View("~/Views/Home/Index.cshtml");
}
}
If no errors were return during the login attempt, a cookie is added to the response and the request is redirected
via RedirectToRoute to the social home page, shown in Figure 7-3 . Otherwise, the View will specify the HTML page to
return as well as use the ViewBag object to add the error messages that need to be displayed back to the View .
 
Search WWH ::




Custom Search