Copied to clipboard

Flag this post as spam?

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


  • Jonathan Bäckström 6 posts 96 karma points
    Feb 15, 2018 @ 16:56
    Jonathan Bäckström
    0

    Redirect members based on member group

    Hi,

    I am trying to figure out how to redirect members to different urls based on which member group a member has when logging in.

    I have my LoginController where I want to do something like this:

    public class LoginController : SurfaceController
    {
        public ActionResult Login(LoginModel model)
        {
            if (!ModelState.IsValid)
                return CurrentUmbracoPage();
    
            if (Members.Login(model.Email, model.Password))
            {
                var member = Members.GetCurrentMember();
    
                if (member is part of group "Teacher")
                    return Redirect("/app");
                if (member is part of group "Student")
                    return Redirect("/playground");
                else
                    return Redirect("/");
            }
    
            ModelState.AddModelError("", "Invalid Login");
    
            return CurrentUmbracoPage();
        }
    }
    

    When I try to GetCurrentMember() it returns null and I can't find any recent posts about how to check if a member is part of a group.

    Thanks,

    Jonathan

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Feb 15, 2018 @ 19:29
    Alex Skrypnyk
    103

    Hi Jonathan

    It should work for you:

                    var roles = Services.MemberService.GetAllRoles(member.Id);
                    if (roles.Contains("Teacher"))
                        return Redirect("/app");
                    if (roles.Contains("Student"))
                        return Redirect("/playground");
                    else
                        return Redirect("/");
    
  • Jonathan Bäckström 6 posts 96 karma points
    Feb 15, 2018 @ 20:16
    Jonathan Bäckström
    0

    Thank you for quick answer! It works like a charm!

Please Sign in or register to post replies

Write your reply to:

Draft