Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Matt 359 posts 842 karma points
    Dec 19, 2019 @ 07:51
    Matt
    0

    Members login redirect

    Hi,

    Im adding members login to my umbraco 8 website, I've got everything working and members can log in/out. However what I want to do is once the member logs in then redirect to the home page.

    Here is my code;

        @inherits Umbraco.Web.Mvc.UmbracoViewPage<Engage.Models.LoginModel>
    @using Umbraco.Web
    
    
    
    
    @if (!Umbraco.MemberIsLoggedOn())
    {
    <div class="form-block w-form">
        @using (Html.BeginUmbracoForm("SubmitLogin", "Member", System.Web.Mvc.FormMethod.Post, new { id = "login" }))
        {
            @Html.AntiForgeryToken()
    
    
            @Html.LabelFor(m => m.Username)
            @Html.TextBoxFor(m => m.Username, new { @class = "text-field w-input" })
    
    
            @Html.LabelFor(m => m.Password)
            @Html.PasswordFor(m => m.Password, new { @class = "text-field w-input" })
    
            @Html.ValidationSummary()
            <div class="div-block-83">
                <button class="contact-button w-button" name="login" type="submit">Login</button>
            </div>
    
        }
        </div>
        }
    
            else
            {
            Html.RenderAction("RenderLogout", "Member");
            }
    

    And my controller

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web.Security;
    using System.Web;
    using System.Web.Mvc;
    using Engage.Models;
    using Umbraco.Web.Mvc;
    
    namespace Engage.Controllers
    {
        public class MemberController : SurfaceController
        {
            public ActionResult RenderLogin()
            {
                return PartialView("_Login", new LoginModel());
            }
    
            [HttpPost]
            [ValidateAntiForgeryToken]
            public ActionResult SubmitLogin(LoginModel model, string returnUrl)
            {
                if (ModelState.IsValid)
                {
                    if (Membership.ValidateUser(model.Username, model.Password))
                    {
                        FormsAuthentication.SetAuthCookie(model.Username, false);
                        UrlHelper myHelper = new UrlHelper(HttpContext.Request.RequestContext);
                        if (myHelper.IsLocalUrl(returnUrl))
                        {
                            return Redirect(returnUrl);
                        }
                        else
                        {
                            return Redirect("/login/");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "The username or password provided is incorrect.");
                    }
                }
                return CurrentUmbracoPage();
            }
    
            public ActionResult RenderLogout()
            {
                return PartialView("_Logout", null);
            }
    
            public ActionResult SubmitLogout()
            {
                TempData.Clear();
                Session.Clear();
                FormsAuthentication.SignOut();
                return RedirectToCurrentUmbracoPage();
            }
        }
    }
    

    Thanks in advance,

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies