I am a developer coding a solution where i want to check if a Member is also a User/backoffice user and add support for our logging. the code looks like this.
public bool AddAndOrLoginMember()
{
bool succeeded = false;
var user = GetUser();
if (!CheckValidAbonnemang(user))
{
return false;
}
var memberService = Current.Services.MemberService;
_logger.Info<LoginService>("Check if user already exists");
IMember member = memberService.GetByUsername(user.Personnummer);
var backOfficeUserService = Current.UmbracoContext.Security.CurrentUser;
if (member != null)
{
_logger.Info<LoginService>($"User, {user.Fornamn} {user.Efternamn}: Username {user.Personnummer.Substring(0, 10)}, exists. Login user.");
// Member already added. Login member
succeeded = Login(member);
}
else
{
// Create the user
member = AddUmbracoMember(user);
// Login user
_logger.Info<LoginService>("Login user");
succeeded = Login(member);
}
if (succeeded)
{
_logger.Info<LoginService>($"Set forms authentication cookie");
FormsAuthentication.SetAuthCookie(member.Username, true);
}
_logger.Info<LoginService>($"User login succeeded: {succeeded}");
return succeeded;
}
I found Current.UmbracoContext.Security.CurrentUser; and it has a method i think called IsAdmin() but it only takes a IUser and when i get the current member its a IMember so it aint compatible.
My first thought was to do something like If()member != null || backOfficeUserService.IsAdmin(member){...} but then i get a "Severity Code Description Project File Line Suppression State
Error CS1501 No overload for method 'IsAdmin' takes 1 argument"
so any idea how to easily solve this and do a check if a member is also a backofficeUser? if more clarification is needed i will try to answer it :)
There is a clear difference between Members and Users. Users are specifically accounts that have access to the Umbraco Back-Office. Members are used for external users of the platform, like the front-end of your application!
You can for example check if your Users and Members have the same username or e-mail address if you are still interested in such a thing, but there is no intended relationship between Members and Users as it stands!
Check if a Member is a User
Hello everyone!
I am a developer coding a solution where i want to check if a Member is also a User/backoffice user and add support for our logging. the code looks like this.
I found Current.UmbracoContext.Security.CurrentUser; and it has a method i think called IsAdmin() but it only takes a IUser and when i get the current member its a IMember so it aint compatible.
My first thought was to do something like
If()member != null || backOfficeUserService.IsAdmin(member){...}
but then i get a "Severity Code Description Project File Line Suppression State Error CS1501 No overload for method 'IsAdmin' takes 1 argument"so any idea how to easily solve this and do a check if a member is also a backofficeUser? if more clarification is needed i will try to answer it :)
Hi Stefan,
There is a clear difference between Members and Users. Users are specifically accounts that have access to the Umbraco Back-Office. Members are used for external users of the platform, like the front-end of your application!
You can for example check if your Users and Members have the same username or e-mail address if you are still interested in such a thing, but there is no intended relationship between Members and Users as it stands!
Hope this helped!
Kind regards,
Corné Hoskam
is working on a reply...