Esempio n. 1
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);

                    if (ConfigurationManager.AppSettings["ForumAuthenticationEnabled"] == "true")
                    {
                        ForumAuthentication.SetAuthCookie(model.UserName, Request.UserHostAddress, Request.UserAgent, Request.ServerVariables["HTTP_X_FORWARDED_FOR"]);
                    }

                    if (!User.IsInRole("Guest"))
                    {
                        Login             login  = _dataService.GetLoginByUsername(model.UserName);
                        Member            member = login.ClubMember.First();
                        AuthenticatedUser user   = new AuthenticatedUser()
                        {
                            LoginId  = login.Id,
                            Username = model.UserName,
                            FullName = member.FullName,
                            MemberId = member.Id
                        };

                        Session.Add(FlyingClub.Common.ContextVariables.AuthenticatedUser, user);

                        _dataService.UpdateLoggedInDate(login.Id, DateTime.Now);
                    }

                    if ((User.IsInRole("Guest") && Url.IsLocalToHost(returnUrl) && !Url.IsLocalUrl(returnUrl)) || (!User.IsInRole("Guest") && Url.IsLocalToHost(returnUrl)))
                    {
                        return(Redirect(returnUrl));
                    }
                    else if (User.IsInRole("Guest"))
                    {
                        return(Redirect(ConfigurationManager.AppSettings["FrontEndUrl"]));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 2
0
        //
        // GET: /Account/LogOff

        public ActionResult LogOff(string returnUrl)
        {
            if (ConfigurationManager.AppSettings["ForumAuthenticationEnabled"] == "true")
            {
                ForumAuthentication.SignOut();
            }
            FormsAuthentication.SignOut();

            if (String.IsNullOrEmpty(returnUrl) || !Url.IsLocalToHost(returnUrl))
            {
                returnUrl = Url.Action("Index", "Home");
            }
            ;

            return(Redirect(returnUrl));
        }