Class UserService
Represents the UserService, which is an easy access to operations involving IProfile, IMembershipUser and eventually Backoffice Users.
Namespace: Umbraco.Core.Services.Implement
Assembly: Umbraco.Core.dll
Syntax
public class UserService : ScopeRepositoryService, IUserService, IMembershipUserService, IMembershipMemberService<IUser>, IService
Constructors
View SourceUserService(IScopeProvider, ILogger, IEventMessagesFactory, IRuntimeState, IUserRepository, IUserGroupRepository, IGlobalSettings)
Declaration
public UserService(IScopeProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory, IRuntimeState runtimeState, IUserRepository userRepository, IUserGroupRepository userGroupRepository, IGlobalSettings globalSettings)
Parameters
Type | Name | Description |
---|---|---|
IScopeProvider | provider | |
ILogger | logger | |
IEventMessagesFactory | eventMessagesFactory | |
IRuntimeState | runtimeState | |
IUserRepository | userRepository | |
IUserGroupRepository | userGroupRepository | |
IGlobalSettings | globalSettings |
Methods
View SourceAssignUserGroupPermission(Int32, Char, Int32[])
Assigns the same permission set for a single user group to any number of entities
Declaration
public void AssignUserGroupPermission(int groupId, char permission, params int[] entityIds)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | groupId | Id of the user group |
System.Char | permission | |
System.Int32[] | entityIds | Specify the nodes to replace permissions for |
ClearLoginSession(Guid)
Declaration
public void ClearLoginSession(Guid sessionId)
Parameters
Type | Name | Description |
---|---|---|
System.Guid | sessionId |
ClearLoginSessions(Int32)
Declaration
public int ClearLoginSessions(int userId)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | userId |
Returns
Type | Description |
---|---|
System.Int32 |
CreateLoginSession(Int32, String)
Declaration
public Guid CreateLoginSession(int userId, string requestingIpAddress)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | userId | |
System.String | requestingIpAddress |
Returns
Type | Description |
---|---|
System.Guid |
CreateUserWithIdentity(String, String)
Creates a new User
Declaration
public IUser CreateUserWithIdentity(string username, string email)
Parameters
Type | Name | Description |
---|---|---|
System.String | username | Username of the user to create |
System.String | Email of the user to create |
Returns
Type | Description |
---|---|
IUser | IUser |
Remarks
The user will be saved in the database and returned with an Id
Delete(IUser)
Disables an IUser
Declaration
public void Delete(IUser membershipUser)
Parameters
Type | Name | Description |
---|---|---|
IUser | membershipUser | IUser to disable |
Delete(IUser, Boolean)
Deletes or disables a User
Declaration
public void Delete(IUser user, bool deletePermanently)
Parameters
Type | Name | Description |
---|---|---|
IUser | user | IUser to delete |
System.Boolean | deletePermanently |
|
DeleteSectionFromAllUserGroups(String)
Removes a specific section from all users
Declaration
public void DeleteSectionFromAllUserGroups(string sectionAlias)
Parameters
Type | Name | Description |
---|---|---|
System.String | sectionAlias | Alias of the section to remove |
Remarks
This is useful when an entire section is removed from config
DeleteUserGroup(IUserGroup)
Deletes a UserGroup
Declaration
public void DeleteUserGroup(IUserGroup userGroup)
Parameters
Type | Name | Description |
---|---|---|
IUserGroup | userGroup | UserGroup to delete |
Exists(String)
Checks if a User with the username exists
Declaration
public bool Exists(string username)
Parameters
Type | Name | Description |
---|---|---|
System.String | username | Username to check |
Returns
Type | Description |
---|---|
System.Boolean |
|
FindByEmail(String, Int64, Int32, out Int64, StringPropertyMatchType)
Finds a list of IUser objects by a partial email string
Declaration
public IEnumerable<IUser> FindByEmail(string emailStringToMatch, long pageIndex, int pageSize, out long totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith)
Parameters
Type | Name | Description |
---|---|---|
System.String | emailStringToMatch | Partial email string to match |
System.Int64 | pageIndex | Current page index |
System.Int32 | pageSize | Size of the page |
System.Int64 | totalRecords | Total number of records found (out) |
StringPropertyMatchType | matchType | The type of match to make as StringPropertyMatchType. Default is StartsWith |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IUser> | System.Collections.Generic.IEnumerable<T> |
FindByUsername(String, Int64, Int32, out Int64, StringPropertyMatchType)
Finds a list of IUser objects by a partial username
Declaration
public IEnumerable<IUser> FindByUsername(string login, long pageIndex, int pageSize, out long totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith)
Parameters
Type | Name | Description |
---|---|---|
System.String | login | Partial username to match |
System.Int64 | pageIndex | Current page index |
System.Int32 | pageSize | Size of the page |
System.Int64 | totalRecords | Total number of records found (out) |
StringPropertyMatchType | matchType | The type of match to make as StringPropertyMatchType. Default is StartsWith |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IUser> | System.Collections.Generic.IEnumerable<T> |
GetAll(Int64, Int32, out Int64)
Gets a list of paged IUser objects
Declaration
public IEnumerable<IUser> GetAll(long pageIndex, int pageSize, out long totalRecords)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | pageIndex | Current page index |
System.Int32 | pageSize | Size of the page |
System.Int64 | totalRecords | Total number of records found (out) |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IUser> | System.Collections.Generic.IEnumerable<T> |
GetAll(Int64, Int32, out Int64, String, Direction, UserState[], String[], String)
Declaration
public IEnumerable<IUser> GetAll(long pageIndex, int pageSize, out long totalRecords, string orderBy, Direction orderDirection, UserState[] userState = null, string[] userGroups = null, string filter = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | pageIndex | |
System.Int32 | pageSize | |
System.Int64 | totalRecords | |
System.String | orderBy | |
Direction | orderDirection | |
UserState[] | userState | |
System.String[] | userGroups | |
System.String | filter |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IUser> |
GetAll(Int64, Int32, out Int64, String, Direction, UserState[], String[], String[], IQuery<IUser>)
Declaration
public IEnumerable<IUser> GetAll(long pageIndex, int pageSize, out long totalRecords, string orderBy, Direction orderDirection, UserState[] userState = null, string[] includeUserGroups = null, string[] excludeUserGroups = null, IQuery<IUser> filter = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | pageIndex | |
System.Int32 | pageSize | |
System.Int64 | totalRecords | |
System.String | orderBy | |
Direction | orderDirection | |
UserState[] | userState | |
System.String[] | includeUserGroups | |
System.String[] | excludeUserGroups | |
IQuery<IUser> | filter |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IUser> |
GetAllInGroup(Int32)
Gets a list of IUser objects associated with a given group
Declaration
public IEnumerable<IUser> GetAllInGroup(int groupId)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | groupId | Id of group |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IUser> | System.Collections.Generic.IEnumerable<T> |
GetAllNotInGroup(Int32)
Gets a list of IUser objects not associated with a given group
Declaration
public IEnumerable<IUser> GetAllNotInGroup(int groupId)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | groupId | Id of group |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IUser> | System.Collections.Generic.IEnumerable<T> |
GetAllUserGroups(Int32[])
Gets all UserGroups or those specified as parameters
Declaration
public IEnumerable<IUserGroup> GetAllUserGroups(params int[] ids)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | ids | Optional Ids of UserGroups to retrieve |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IUserGroup> | An enumerable list of IUserGroup |
GetByEmail(String)
Get an IUser by email
Declaration
public IUser GetByEmail(string email)
Parameters
Type | Name | Description |
---|---|---|
System.String | Email to use for retrieval |
Returns
Type | Description |
---|---|
IUser | IUser |
GetById(Int32)
Gets a User by its integer id
Declaration
public IUser GetById(int id)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id |
Returns
Type | Description |
---|---|
IUser | IUser |
GetByProviderKey(Object)
Gets an IUser by its provider key
Declaration
public IUser GetByProviderKey(object id)
Parameters
Type | Name | Description |
---|---|---|
System.Object | id | Id to use for retrieval |
Returns
Type | Description |
---|---|
IUser | IUser |
GetByUsername(String)
Get an IUser by username
Declaration
public IUser GetByUsername(string username)
Parameters
Type | Name | Description |
---|---|---|
System.String | username | Username to use for retrieval |
Returns
Type | Description |
---|---|
IUser | IUser |
GetCount(MemberCountType)
Gets the total number of Users based on the count type
Declaration
public int GetCount(MemberCountType countType)
Parameters
Type | Name | Description |
---|---|---|
MemberCountType | countType | MemberCountType to count by |
Returns
Type | Description |
---|---|
System.Int32 |
Remarks
The way the Online count is done is the same way that it is done in the MS SqlMembershipProvider - We query for any members that have their last active date within the Membership.UserIsOnlineTimeWindow (which is in minutes). It isn't exact science but that is how MS have made theirs so we'll follow that principal.
GetDefaultMemberType()
This is just the default user group that the membership provider will use
Declaration
public string GetDefaultMemberType()
Returns
Type | Description |
---|---|
System.String |
GetPermissions(IUser, Int32[])
Get explicitly assigned permissions for a user and optional node ids
Declaration
public EntityPermissionCollection GetPermissions(IUser user, params int[] nodeIds)
Parameters
Type | Name | Description |
---|---|---|
IUser | user | User to retrieve permissions for |
System.Int32[] | nodeIds | Specifying nothing will return all permissions for all nodes |
Returns
Type | Description |
---|---|
EntityPermissionCollection | An enumerable list of EntityPermission |
GetPermissions(IUserGroup[], Boolean, Int32[])
Get explicitly assigned permissions for a group and optional node Ids
Declaration
public EntityPermissionCollection GetPermissions(IUserGroup[] groups, bool fallbackToDefaultPermissions, params int[] nodeIds)
Parameters
Type | Name | Description |
---|---|---|
IUserGroup[] | groups | |
System.Boolean | fallbackToDefaultPermissions | Flag indicating if we want to include the default group permissions for each result if there are not explicit permissions set |
System.Int32[] | nodeIds | Specifying nothing will return all permissions for all nodes |
Returns
Type | Description |
---|---|
EntityPermissionCollection | An enumerable list of EntityPermission |
GetPermissionsForPath(IUser, String)
Gets the implicit/inherited permissions for the user for the given path
Declaration
public EntityPermissionSet GetPermissionsForPath(IUser user, string path)
Parameters
Type | Name | Description |
---|---|---|
IUser | user | User to check permissions for |
System.String | path | Path to check permissions for |
Returns
Type | Description |
---|---|
EntityPermissionSet |
GetPermissionsForPath(IUserGroup[], String, Boolean)
Gets the permissions for the provided group and path
Declaration
public EntityPermissionSet GetPermissionsForPath(IUserGroup[] groups, string path, bool fallbackToDefaultPermissions = false)
Parameters
Type | Name | Description |
---|---|---|
IUserGroup[] | groups | |
System.String | path | Path to check permissions for |
System.Boolean | fallbackToDefaultPermissions | Flag indicating if we want to include the default group permissions for each result if there are not explicit permissions set |
Returns
Type | Description |
---|---|
EntityPermissionSet | String indicating permissions for provided user and path |
GetProfileById(Int32)
Gets an IProfile by User Id.
Declaration
public IProfile GetProfileById(int id)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | Id of the User to retrieve |
Returns
Type | Description |
---|---|
IProfile | IProfile |
GetProfileByUserName(String)
Gets a profile by username
Declaration
public IProfile GetProfileByUserName(string username)
Parameters
Type | Name | Description |
---|---|---|
System.String | username | Username |
Returns
Type | Description |
---|---|
IProfile | IProfile |
GetUserById(Int32)
Gets a user by Id
Declaration
public IUser GetUserById(int id)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | Id of the user to retrieve |
Returns
Type | Description |
---|---|
IUser | IUser |
GetUserGroupByAlias(String)
Gets a UserGroup by its Alias
Declaration
public IUserGroup GetUserGroupByAlias(string alias)
Parameters
Type | Name | Description |
---|---|---|
System.String | alias | Alias of the UserGroup to retrieve |
Returns
Type | Description |
---|---|
IUserGroup | IUserGroup |
GetUserGroupById(Int32)
Gets a UserGroup by its Id
Declaration
public IUserGroup GetUserGroupById(int id)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | Id of the UserGroup to retrieve |
Returns
Type | Description |
---|---|
IUserGroup | IUserGroup |
GetUserGroupsByAlias(String[])
Declaration
public IEnumerable<IUserGroup> GetUserGroupsByAlias(params string[] aliases)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | aliases |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IUserGroup> |
GetUsersById(Int32[])
Declaration
public IEnumerable<IUser> GetUsersById(params int[] ids)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | ids |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IUser> |
GetUserStates()
Declaration
public IDictionary<UserState, int> GetUserStates()
Returns
Type | Description |
---|---|
System.Collections.Generic.IDictionary<UserState, System.Int32> |
ReplaceUserGroupPermissions(Int32, IEnumerable<Char>, Int32[])
Replaces the same permission set for a single group to any number of entities
Declaration
public void ReplaceUserGroupPermissions(int groupId, IEnumerable<char> permissions, params int[] entityIds)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | groupId | Id of the group |
System.Collections.Generic.IEnumerable<System.Char> | permissions | Permissions as enumerable list of System.Char If nothing is specified all permissions are removed. |
System.Int32[] | entityIds | Specify the nodes to replace permissions for. |
Remarks
If no 'entityIds' are specified all permissions will be removed for the specified group.
Save(IEnumerable<IUser>, Boolean)
Saves a list of IUser objects
Declaration
public void Save(IEnumerable<IUser> entities, bool raiseEvents = true)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<IUser> | entities | System.Collections.Generic.IEnumerable<T> to save |
System.Boolean | raiseEvents | Optional parameter to raise events.
Default is |
Save(IUser, Boolean)
Saves an IUser
Declaration
public void Save(IUser entity, bool raiseEvents = true)
Parameters
Type | Name | Description |
---|---|---|
IUser | entity | IUser to Save |
System.Boolean | raiseEvents | Optional parameter to raise events.
Default is |
Save(IUserGroup, Int32[], Boolean)
Saves a UserGroup
Declaration
public void Save(IUserGroup userGroup, int[] userIds = null, bool raiseEvents = true)
Parameters
Type | Name | Description |
---|---|---|
IUserGroup | userGroup | UserGroup to save |
System.Int32[] | userIds | If null than no changes are made to the users who are assigned to this group, however if a value is passed in than all users will be removed from this group and only these users will be added |
System.Boolean | raiseEvents | Optional parameter to raise events.
Default is |
TryGetAssignedPermissionsForNode(IList<EntityPermission>, Int32, out String)
Checks in a set of permissions associated with a user for those related to a given nodeId
Declaration
public static bool TryGetAssignedPermissionsForNode(IList<EntityPermission> permissions, int nodeId, out string assignedPermissions)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IList<EntityPermission> | permissions | The set of permissions |
System.Int32 | nodeId | The node Id |
System.String | assignedPermissions | The permissions to return |
Returns
Type | Description |
---|---|
System.Boolean | True if permissions for the given path are found |
ValidateLoginSession(Int32, Guid)
Declaration
public bool ValidateLoginSession(int userId, Guid sessionId)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | userId | |
System.Guid | sessionId |
Returns
Type | Description |
---|---|
System.Boolean |
Events
View SourceDeletedUser
Occurs after Delete
Declaration
public static event TypedEventHandler<IUserService, DeleteEventArgs<IUser>> DeletedUser
Event Type
Type | Description |
---|---|
TypedEventHandler<IUserService, DeleteEventArgs<IUser>> |
DeletedUserGroup
Occurs after Delete
Declaration
public static event TypedEventHandler<IUserService, DeleteEventArgs<IUserGroup>> DeletedUserGroup
Event Type
Type | Description |
---|---|
TypedEventHandler<IUserService, DeleteEventArgs<IUserGroup>> |
DeletingUser
Occurs before Delete
Declaration
public static event TypedEventHandler<IUserService, DeleteEventArgs<IUser>> DeletingUser
Event Type
Type | Description |
---|---|
TypedEventHandler<IUserService, DeleteEventArgs<IUser>> |
DeletingUserGroup
Occurs before Delete
Declaration
public static event TypedEventHandler<IUserService, DeleteEventArgs<IUserGroup>> DeletingUserGroup
Event Type
Type | Description |
---|---|
TypedEventHandler<IUserService, DeleteEventArgs<IUserGroup>> |
SavedUser
Occurs after Save
Declaration
public static event TypedEventHandler<IUserService, SaveEventArgs<IUser>> SavedUser
Event Type
Type | Description |
---|---|
TypedEventHandler<IUserService, SaveEventArgs<IUser>> |
SavedUserGroup
Occurs after Save
Declaration
public static event TypedEventHandler<IUserService, SaveEventArgs<UserGroupWithUsers>> SavedUserGroup
Event Type
Type | Description |
---|---|
TypedEventHandler<IUserService, SaveEventArgs<UserGroupWithUsers>> |
SavingUser
Occurs before Save
Declaration
public static event TypedEventHandler<IUserService, SaveEventArgs<IUser>> SavingUser
Event Type
Type | Description |
---|---|
TypedEventHandler<IUserService, SaveEventArgs<IUser>> |
SavingUserGroup
Occurs before Save
Declaration
public static event TypedEventHandler<IUserService, SaveEventArgs<UserGroupWithUsers>> SavingUserGroup
Event Type
Type | Description |
---|---|
TypedEventHandler<IUserService, SaveEventArgs<UserGroupWithUsers>> |
Explicit Interface Implementations
View SourceIMembershipMemberService<IUser>.CreateWithIdentity(String, String, String, String)
Creates and persists a new IUser
Declaration
IUser IMembershipMemberService<IUser>.CreateWithIdentity(string username, string email, string passwordValue, string memberTypeAlias)
Parameters
Type | Name | Description |
---|---|---|
System.String | username | Username of the IUser to create |
System.String | Email of the IUser to create |
|
System.String | passwordValue | This value should be the encoded/encrypted/hashed value for the password that will be stored in the database |
System.String | memberTypeAlias | Not used for users |
Returns
Type | Description |
---|---|
IUser | IUser |
IMembershipMemberService<IUser>.CreateWithIdentity(String, String, String, String, Boolean)
Creates and persists a new IUser
Declaration
IUser IMembershipMemberService<IUser>.CreateWithIdentity(string username, string email, string passwordValue, string memberTypeAlias, bool isApproved)
Parameters
Type | Name | Description |
---|---|---|
System.String | username | Username of the IUser to create |
System.String | Email of the IUser to create |
|
System.String | passwordValue | This value should be the encoded/encrypted/hashed value for the password that will be stored in the database |
System.String | memberTypeAlias | Alias of the Type |
System.Boolean | isApproved | Is the member approved |
Returns
Type | Description |
---|---|
IUser | IUser |
IMembershipMemberService<IUser>.SetLastLogin(String, DateTime)
Declaration
void IMembershipMemberService<IUser>.SetLastLogin(string username, DateTime date)
Parameters
Type | Name | Description |
---|---|---|
System.String | username | |
System.DateTime | date |