Copied to clipboard

Flag this post as spam?

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


  • Anders Brohus 194 posts 475 karma points
    May 12, 2020 @ 08:03
    Anders Brohus
    0

    Custom Login Controller - Members

    Hi Our,

    I have a little problem that i hope you can help with :)

    I'm having an Custom Login Controller, which redirects to different pages if the user role list contains specific roles :)

    BUT sometimes the Members.GetCurrentUserRoles is empty, and the Members.CurrentUserName is empty, like it's not getting the logged in user..

    This is my code :)

    if (ModelState.IsValid == false)
                {
                    return CurrentUmbracoPage();
                }
    
    
                if (Members.Login(model.Username, model.Password) == false)
                {
                    //don't add a field level error, just model level
                    ModelState.AddModelError("loginModel", "Invalid username or password");
                    return CurrentUmbracoPage();
                }
    
    
                TempData["LoginSuccess"] = true;
                IEnumerable<string> userRolesIEnumerable = Members.GetCurrentUserRoles();
                List<string> userRolesList = new List<string>();
                userRolesList.AddRange(userRolesIEnumerable);
    
                if (userRolesList.Contains("DJ") && userRolesList.Contains("BNV"))
                {
                    return RedirectToCurrentUmbracoPage("?allow-user-selection=1");
                }
                else if (userRolesList.Contains("DJ") && !userRolesList.Contains("BNV"))
                {
                    return RedirectToUmbracoPage(1078);
                }
                else if (!userRolesList.Contains("DJ") && userRolesList.Contains("BNV"))
                {
                    return RedirectToUmbracoPage(1079);
                }
    
  • Subbyy 1 post 21 karma points
    Dec 25, 2020 @ 20:19
    Subbyy
    0

    Hey,

    You can use the static class Roles

    Roles.GetRolesForUser(model.Username)
    

    Or:

    Services.MemberService.GetAllRoles(model.Username)
    

    Or:

    Members.GetUserRoles(model.Username)
    
  • 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