/// <summary> /// Gets the username this could be the alias! We should always use this method when getting the username /// </summary> /// <param name="username">The username.</param> /// <param name="session"></param> /// <returns> /// <c>null</c> if we cannot find a user /// </returns> public string GetUsername(string username, ISession session) { var plexUser = PlexUsers.GetUserByUsername(username); if (plexUser != null) { return(!string.IsNullOrEmpty(plexUser.UserAlias) ? plexUser.UserAlias : plexUser.Username); } var dbUser = UserRepository.GetUserByUsername(username); if (dbUser != null) { var userProps = ByteConverterHelper.ReturnObject <UserProperties>(dbUser.UserProperties); return(!string.IsNullOrEmpty(userProps.UserAlias) ? userProps.UserAlias : dbUser.UserName); } // could be a local user var hasSessionKey = session[SessionKeys.UsernameKey] != null; if (hasSessionKey) { return((string)session[SessionKeys.UsernameKey]); } return(string.Empty); }
private Permissions GetPermissions(string userName) { if (string.IsNullOrEmpty(userName)) { // Username without auth var s = UserManagementSettings.GetSettings(); return((Permissions)UserManagementHelper.GetPermissions(s)); } var dbUser = UserRepository.GetUserByUsername(userName); if (dbUser != null) { var permissions = (Permissions)dbUser.Permissions; return(permissions); } var plexUser = PlexUsers.GetUserByUsername(userName); if (plexUser != null) { var permissions = (Permissions)plexUser.Permissions; return(permissions); } return(0); }
public bool IsPlexUser(IUserIdentity user) { if (user == null) { return(false); } var plexUser = PlexUsers.GetUserByUsername(user.UserName); return(plexUser != null); }
/// <summary> /// Gets the username this could be the alias! We should always use this method when getting the username /// </summary> /// <param name="username">The username.</param> /// <returns><c>null</c> if we cannot find a user</returns> public string GetUsername(string username, ISession session) { var plexUser = PlexUsers.GetUserByUsername(username); if (plexUser != null) { if (!string.IsNullOrEmpty(plexUser.UserAlias)) { return(plexUser.UserAlias); } else { return(plexUser.Username); } } var dbUser = UserRepository.GetUserByUsername(username); if (dbUser != null) { var userProps = ByteConverterHelper.ReturnObject <UserProperties>(dbUser.UserProperties); if (!string.IsNullOrEmpty(userProps.UserAlias)) { return(userProps.UserAlias); } else { return(dbUser.UserName); } } // could be a local user var localName = session[SessionKeys.UsernameKey]; return(localName as string); }