コード例 #1
0
        public ActionResult MvcMemberLoginRenderForm(MvcMemberModel model)
        {
            string checkUrl = HttpContext.Request.Url.AbsolutePath.ToString();

            // add a trailing / if there isn't one (you can access the same page via http://mydomain.com/login or http://mydomain.com/login/)
            if (checkUrl[checkUrl.Length - 1] != '/')
            {
                checkUrl = checkUrl + "/";
            }

            // if we don't have a session variable and have a request URL then store it
            // we have to store it because if user tries an incorrect login then Current.Request.Url will show /umbraco/RenderMvc
            // in MVC we won't have "/umbraco/RenderMvc" but I leave this in here just in case
            if (HttpContext.Request.Url != null && HttpContext.Request.Url.AbsolutePath.ToString() != "/umbraco/RenderMvc" && HttpContext.Session["redirectURL"] == null)
            {
                if (checkUrl.ToLower() != membersLoginUrl)
                {
                    HttpContext.Session["redirectURL"] = HttpContext.Request.Url.ToString();
                }
            }

            // set this to be checked by default - wish you could just pass checked=checked
            model.RememberMe = true;
            return PartialView("MvcMemberLogin", model);
        }
コード例 #2
0
        public ActionResult MvcMemberLoginPost(MvcMemberModel model)
        {
            var memberService = Services.MemberService;
            var member = memberService.GetByEmail(model.Email);

            if (member != null && model.Password != null)
            {
                if (!member.IsApproved)
                {
                    TempData["Status"] = "Before you can login you need to validate your email address - check your email for instructions on how to do this.";
                    return RedirectToCurrentUmbracoPage();
                }

                // helper method on Members to login
                if (Members.Login(model.Email, model.Password))
                {
                    // does this work?
                    FormsAuthentication.SetAuthCookie(model.Email, model.RememberMe);
                    return RedirectToCurrentUmbracoPage();
                }
                else
                {
                    TempData["Status"] = "Invalid username or password";
                    return CurrentUmbracoPage();
                }
            }
            else
            {
                TempData["Status"] = "Invalid username or password";
                return CurrentUmbracoPage();
            }
        }