Patch WebserverFlokuepDevelopTest

This commit is contained in:
Florian Küpper committed 2013-12-19 09:02:40 +01:00
1 parent 42b82f5b29
commit 0c807862a8
8 files changed
+277 -67

No files matched your search

@@ -6,7 +6,7 @@ namespace ServerLib
internal static class CUserRoleControl
{
private static readonly Dictionary<EUserRoles, EUserRights> _RoleRightsMapping = new Dictionary<EUserRoles, EUserRights> {
{EUserRoles.Administrator,
{EUserRoles.TR_USERROLE_ADMIN,
(EUserRights.EditAllProfiles|
EUserRights.UploadPhotos|
EUserRights.ViewOtherProfiles|
@@ -16,10 +16,23 @@ namespace ServerLib
EUserRights.CreatePlaylists|
EUserRights.DeletePlaylists|
EUserRights.RemoveSongsFromPlaylists)},
{EUserRoles.AuthenticatedUser,
{EUserRoles.TR_USERROLE_GUEST,
EUserRights.None},
{EUserRoles.TR_USERROLE_NORMAL,
(EUserRights.UploadPhotos|
EUserRights.ViewOtherProfiles|
EUserRights.UseKeyboard)}
EUserRights.ViewOtherProfiles)},
{EUserRoles.TR_USERROLE_KEYBOARDUSER,
EUserRights.UseKeyboard},
{EUserRoles.TR_USERROLE_ADDSONGSUSER,
EUserRights.AddSongToPlaylist},
{EUserRoles.TR_USERROLE_PLAYLISTEDITOR,
(EUserRights.AddSongToPlaylist|
EUserRights.ReorderPlaylists|
EUserRights.CreatePlaylists|
EUserRights.DeletePlaylists|
EUserRights.RemoveSongsFromPlaylists)},
{EUserRoles.TR_USERROLE_PROFILEEDITOR,
EUserRights.EditAllProfiles}
};
+7 -3
View File
@@ -5,8 +5,12 @@ namespace ServerLib
[Flags]
internal enum EUserRoles
{
GuestUser = 0,
AuthenticatedUser = 1,
Administrator = 2
TR_USERROLE_GUEST = 0,
TR_USERROLE_NORMAL = 1,
TR_USERROLE_ADMIN = 2,
TR_USERROLE_KEYBOARDUSER = 4,
TR_USERROLE_ADDSONGSUSER = 8,
TR_USERROLE_PLAYLISTEDITOR = 16,
TR_USERROLE_PROFILEEDITOR = 32
}
}
+14 -12
View File
@@ -212,7 +212,7 @@ namespace Vocaluxe.Base
public static void LoadProfiles()
{
var change = new SChange {Action = EAction.LoadProfiles};
var change = new SChange { Action = EAction.LoadProfiles };
lock (_QueueMutex)
{
@@ -222,7 +222,7 @@ namespace Vocaluxe.Base
public static void LoadAvatars()
{
var change = new SChange {Action = EAction.LoadAvatars};
var change = new SChange { Action = EAction.LoadAvatars };
lock (_QueueMutex)
{
@@ -235,7 +235,7 @@ namespace Vocaluxe.Base
if (newProfile == null)
return;
var change = new SChange {Action = EAction.AddProfile, Profile = newProfile};
var change = new SChange { Action = EAction.AddProfile, Profile = newProfile };
lock (_QueueMutex)
{
@@ -248,7 +248,7 @@ namespace Vocaluxe.Base
if (editProfile == null)
return;
var change = new SChange {Action = EAction.EditProfile, Profile = editProfile};
var change = new SChange { Action = EAction.EditProfile, Profile = editProfile };
lock (_QueueMutex)
{
@@ -261,7 +261,7 @@ namespace Vocaluxe.Base
if (!IsProfileIDValid(profileID))
return;
var change = new SChange {Action = EAction.DeleteProfile, ProfileID = profileID};
var change = new SChange { Action = EAction.DeleteProfile, ProfileID = profileID };
lock (_QueueMutex)
{
@@ -274,7 +274,7 @@ namespace Vocaluxe.Base
if (newAvatar == null)
return;
var change = new SChange {Action = EAction.AddAvatar, Avatar = newAvatar};
var change = new SChange { Action = EAction.AddAvatar, Avatar = newAvatar };
lock (_QueueMutex)
{
@@ -287,7 +287,7 @@ namespace Vocaluxe.Base
if (editAvatar == null)
return;
var change = new SChange {Action = EAction.EditAvatar, Avatar = editAvatar};
var change = new SChange { Action = EAction.EditAvatar, Avatar = editAvatar };
lock (_QueueMutex)
{
@@ -310,9 +310,9 @@ namespace Vocaluxe.Base
if (!IsProfileIDValid(profileID))
{
return null;
}
}
return _Profiles[profileID];
return _Profiles[profileID];
}
public static IEnumerable<CAvatar> GetAvatars()
@@ -442,8 +442,10 @@ namespace Vocaluxe.Base
{
if (!IsProfileIDValid(profileID))
return;
_Profiles[profileID].UserRole = option;
//Only allow the change of TR_USERROLE_GUEST, TR_USERROLE_NORMAL and TR_USERROLE_ADMIN
const EUserRole mask = (EUserRole.TR_USERROLE_GUEST | EUserRole.TR_USERROLE_NORMAL | EUserRole.TR_USERROLE_ADMIN);
option &= mask;
_Profiles[profileID].UserRole = (_Profiles[profileID].UserRole & ~mask) | option;
}
public static EOffOn GetActive(int profileID)
@@ -464,7 +466,7 @@ namespace Vocaluxe.Base
if (!IsProfileIDValid(profileID))
return true; // this will prevent from saving dummy profiles to highscore db
return _Profiles[profileID].UserRole == EUserRole.TR_USERROLE_GUEST;
return _Profiles[profileID].UserRole.HasFlag(EUserRole.TR_USERROLE_GUEST);
}
public static bool IsActive(int profileID)
+21 -8
View File
@@ -228,7 +228,10 @@ namespace Vocaluxe.Base.Server
if (profile.Type >= 0 && profile.Type <= 1)
{
newProfile.UserRole = (EUserRole)profile.Type;
var option = profile.Type == 0 ? EUserRole.TR_USERROLE_GUEST : EUserRole.TR_USERROLE_NORMAL;
//Only allow the change of TR_USERROLE_GUEST and TR_USERROLE_NORMAL
const EUserRole mask = EUserRole.TR_USERROLE_NORMAL;
newProfile.UserRole = (newProfile.UserRole & mask) | option;
}
if (!string.IsNullOrEmpty(profile.Password))
@@ -281,10 +284,11 @@ namespace Vocaluxe.Base.Server
IsEditable = !isReadonly,
ProfileId = profile.ID,
PlayerName = profile.PlayerName,
Type = (int)profile.UserRole,
//Is TR_USERROLE_GUEST or TR_USERROLE_NORMAL?
Type = (profile.UserRole.HasFlag(EUserRole.TR_USERROLE_NORMAL)?1:0),
Difficulty = (int)profile.Difficulty
};
CAvatar avatar = profile.Avatar;
if (avatar != null)
{
@@ -502,7 +506,7 @@ namespace Vocaluxe.Base.Server
{
throw new ArgumentException("invalid songId");
}
if (position < 0 || CPlaylists.Playlists[playlistId].Songs.Count <= position
if (position < 0 || CPlaylists.Playlists[playlistId].Songs.Count <= position
|| CPlaylists.Playlists[playlistId].Songs[position].SongID != songId)
{
throw new ArgumentException("invalid position");
@@ -521,7 +525,7 @@ namespace Vocaluxe.Base.Server
{
throw new ArgumentException("invalid songId");
}
if (CPlaylists.Playlists[playlistId].Songs.Count < newPosition)
{
throw new ArgumentException("invalid newPosition");
@@ -673,7 +677,10 @@ namespace Vocaluxe.Base.Server
throw new ArgumentException("Invalid profileId");
}
return (int)profile.UserRole;
//Hide TR_USERROLE_GUEST and TR_USERROLE_NORMAL
const EUserRole mask = (EUserRole.TR_USERROLE_GUEST | EUserRole.TR_USERROLE_NORMAL);
return (int)(profile.UserRole & ~mask);
}
private static void _SetUserRole(int profileId, int userRole)
@@ -683,8 +690,14 @@ namespace Vocaluxe.Base.Server
{
throw new ArgumentException("Invalid profileId");
}
profile.UserRole = (EUserRole)userRole;
var option = (EUserRole)userRole;
//Only allow the change of all options exept TR_USERROLE_GUEST and TR_USERROLE_NORMAL
const EUserRole mask = (EUserRole.TR_USERROLE_GUEST | EUserRole.TR_USERROLE_NORMAL);
option &= ~mask;
profile.UserRole = (profile.UserRole & mask) | option;
CProfiles.EditProfile(profile);
CProfiles.Update();
+10 -4
View File
@@ -329,10 +329,16 @@
<div id="displayUserAdminContent" data-role="content">
<fieldset data-role="controlgroup">
<legend></legend>
<input type="checkbox" id="roleAuthenticatedUser" checked="checked" disabled="disabled">
<label for="roleAuthenticatedUser">AuthenticatedUser</label>
<input type="checkbox" id="roleAdministrator">
<label for="roleAdministrator">Administrator</label>
<input type="checkbox" id="TR_USERROLE_ADMIN">
<label for="TR_USERROLE_ADMIN">Administrator</label>
<input type="checkbox" id="TR_USERROLE_KEYBOARDUSER">
<label for="TR_USERROLE_KEYBOARDUSER">Keyboard</label>
<input type="checkbox" id="TR_USERROLE_ADDSONGSUSER">
<label for="TR_USERROLE_ADDSONGSUSER">AddSongs</label>
<input type="checkbox" id="TR_USERROLE_PLAYLISTEDITOR">
<label for="TR_USERROLE_PLAYLISTEDITOR">PlaylistEditor</label>
<input type="checkbox" id="TR_USERROLE_PROFILEEDITOR">
<label for="TR_USERROLE_PROFILEEDITOR">ProfileEditor</label>
</fieldset>
<a data-role="button" id="btnRoleSave" data-transition="slidefade" data-i18n="displayUserAdminContentSaveButton"></a>
</div>
+196 -30
View File
@@ -7,34 +7,24 @@ var playlistRequestName = "";
var customSelectPlaylistSongCallback = null;
var sessionId = "";
var serverBaseAddress = "";
var tranlationLoaded;
if (document.location.protocol == "file:") {
if (typeof (window.deviceAndJqmLoaded) == "undefined") {
window.deviceAndJqmLoaded = $.Deferred();
}
window.deviceAndJqmLoaded.done(function () {
preStart();
start();
});
} else {
$(document).ready(function () {
preStart();
});
}
function preStart() {
tranlationLoaded = $.Deferred();
initTranslation();
tranlationLoaded.done(function () {
translate();
start();
});
}
function start() {
replaceTransitionHandler();
initTranslation();
initPageLoadHandler();
initKeyboardPageHandler();
initMainPageHandler();
@@ -410,13 +400,28 @@ function initPageLoadHandler() {
var promise = request({
url: "getUserRole?profileId=" + profileIdRequest
}).done(function (result) {
$('#roleAdministrator').prop("checked", ((result & 0x01) != 0)).checkboxradio("refresh");
var userRoles = {
TR_USERROLE_ADMIN: 2,
TR_USERROLE_KEYBOARDUSER: 4,
TR_USERROLE_ADDSONGSUSER: 8,
TR_USERROLE_PLAYLISTEDITOR: 16,
TR_USERROLE_PROFILEEDITOR: 32
};
for (var roleName in userRoles) {
$('#' + roleName).prop("checked", ((result & userRoles[roleName]) != 0)).checkboxradio("refresh");
}
$('#btnRoleSave').unbind('click').click(function () {
var role = 0;
if ($('#roleAdministrator').prop("checked")) {
role = (role | 0x01);
for (var roleName2 in userRoles) {
if ($('#' + roleName2).prop("checked")) {
role = (role | userRoles[roleName2]);
}
}
request({
url: "setUserRole?profileId=" + profileIdRequest + "&userRole=" + role,
headers: { "session": sessionId }
@@ -1239,24 +1244,185 @@ function showWikipedia(artist) {
}
function initTranslation() {
$.i18n.init({
resGetPath: 'locales/__lng__.json',
supportedLngs: ['en', 'de'],
fallbackLng: 'en',
keyseparator: '::',
nsseparator: ':::'
}).done(function () {
tranlationLoaded.resolve();
});
}
var translations = {
"en": {
translation: {
'loginName': 'User:',
'loginPassword': 'Password:',
'loginButton': 'Login',
'registerButton': 'Create Profile',
'discoverReadQrButton': 'Scan QRCode',
'mainPageYourProfileLink': 'Your Profile',
'mainPageYourProfileLinkDesc': 'Edit your profile',
'mainPageCurrentSongLink': 'Current Song',
'mainPageCurrentSongLinkDesc': 'Display informations about the current song',
'mainPageSelectSong': 'All songs',
'mainPageSelectSongDesc': 'Lists all available songs',
'mainPageSelectPlaylist': 'All playlists',
'mainPageSelectPlaylistDesc': 'Lists all playlists',
'mainPageSelectProfile': 'Profiles',
'mainPageSelectProfileDesc': 'Shows all profiles',
'mainPageTakePhotoLink': 'Take Photo',
'mainPageTakePhotoLinkDesc': 'Takes a photo and displays it at the end of the current round',
'mainPageKeyboard': 'Keyboard',
'mainPageKeyboardDesc': 'Send keys',
'mainPageSelectUserAdmin': 'Administration',
'mainPageSelectUserAdminDesc': 'Configure user rights',
'mainPageLogoutLink': 'Logout',
'mainPageLogoutLinkDesc': 'Closes the session',
'selectProfileHeader': 'All profiles',
'displayProfileHeader': 'Profile',
'displayProfileName': 'Name:',
'displayProfilePlayerType': 'Player Type:',
'displayProfilePlayerTypeNormal': 'Normal',
'displayProfilePlayerTypeGuest': 'Guest',
'displayProfilePlayerDifficulty': 'Difficulty:',
'displayProfilePlayerDifficultyEasy': 'Easy',
'displayProfilePlayerDifficultyNormal': 'Normal',
'displayProfilePlayerDifficultyHard': 'Hard',
'displayProfilePlayerPassword': 'New Password:',
'displayProfilePlayerSaveButton': 'Save and upload',
'displaySongHeader': 'No current song',
'displaySongArtist': 'Artist:',
'displaySongGenre': 'Genre:',
'displaySongYear': 'Year:',
'displaySongLanguage': 'Language:',
'displaySongIsDuet': 'Duet:',
'popupVideoClose': 'Close',
'selectSongHeader': 'All songs',
'keyboardHeader': 'Keyboard',
'keyboardButtonUp': 'up',
'keyboardButtonLeft': 'left',
'keyboardButtonRight': 'right',
'keyboardButtonDown': 'down',
'keyboardButtonEscape': 'escape',
'keyboardButtonTab': 'tab',
'keyboardButtonReturn': 'return',
'keyboardButtonKeys': 'To send other keys type here:',
'selectUserAdminHeader': 'All profiles',
'displayUserAdminHeader': 'Profile',
'displayUserAdminContentSaveButton': 'Save',
'selectPlaylistHeader': 'Select a playlist',
'displayPlaylistHeader': 'Playlist',
'displayPlaylistSaveButton': 'Save',
'selectPlaylistAddPlaylistButton': 'Add',
'Loading (external)...': 'Loading (external)...',
'Loading...': 'Loading...',
'Error...': 'Error...',
'No connection': 'No connection',
'No session': 'No session',
'Uploading photo...': 'Uploading photo...',
'Getting current song...': 'Getting current song...',
'Login...': 'Login...',
'Creating profile...': 'Creating profile...',
'This is not a valid name.': 'This is not a valid name.',
'Uploading profile...': 'Uploading profile...',
'songs': 'songs',
'YourName': 'YourName',
'discoverConnectHeader': 'Connect to server',
'discoverConnectServerAddress': 'Serveraddress:',
'discoverConnectButton': 'Connect',
'Checking...': 'Checking...',
'timeout': 'Timeout'
}
},
"de": {
translation: {
'loginName': 'Benutzer:',
'loginPassword': 'Passwort:',
'loginButton': 'Einloggen',
'registerButton': 'Erstelle Profil',
'discoverReadQrButton': 'Fotografiere QRCode',
'mainPageYourProfileLink': 'Dein Profil',
'mainPageYourProfileLinkDesc': 'Bearbeite dein Profil',
'mainPageCurrentSongLink': 'Aktuelles Lied',
'mainPageCurrentSongLinkDesc': 'Zeigt Informationen über das aktuelle Lied an',
'mainPageSelectSong': 'Alle Lieder',
'mainPageSelectSongDesc': 'Listet alle verfügbaren Lieder auf',
'mainPageSelectPlaylist': 'Alle Playlisten',
'mainPageSelectPlaylistDesc': 'Listet alle verfügbaren Playlisten auf',
'mainPageSelectProfile': 'Profile',
'mainPageSelectProfileDesc': 'Listet alle Profile auf',
'mainPageTakePhotoLink': 'Nehme Foto auf',
'mainPageTakePhotoLinkDesc': 'Nimmt ein Foto auf und zeigt es am ende der Runde an',
'mainPageKeyboard': 'Tastatur',
'mainPageKeyboardDesc': 'Sende Tastatureingaben',
'mainPageSelectUserAdmin': 'Administration',
'mainPageSelectUserAdminDesc': 'Konfiguriere die Benutzerrechte',
'mainPageLogoutLink': 'Abmelden',
'mainPageLogoutLinkDesc': 'Beendet diese Sitzung',
'selectProfileHeader': 'Alle Profile',
'displayProfileHeader': 'Profile',
'displayProfileName': 'Name:',
'displayProfilePlayerType': 'Player Typ:',
'displayProfilePlayerTypeNormal': 'Normal',
'displayProfilePlayerTypeGuest': 'Gast',
'displayProfilePlayerDifficulty': 'Schwierigkeit:',
'displayProfilePlayerDifficultyEasy': 'Einfach',
'displayProfilePlayerDifficultyNormal': 'Normal',
'displayProfilePlayerDifficultyHard': 'Schwer',
'displayProfilePlayerPassword': 'Neues Passwort:',
'displayProfilePlayerSaveButton': 'Speichern und hochladen',
'displaySongHeader': 'Kein aktuelles Lied',
'displaySongArtist': 'Künstler:',
'displaySongGenre': 'Genre:',
'displaySongYear': 'Jahr:',
'displaySongLanguage': 'Sprache:',
'displaySongIsDuet': 'Duet:',
'popupVideoClose': 'Schließen',
'selectSongHeader': 'Alle Lieder',
'keyboardHeader': 'Tastatur',
'keyboardButtonUp': 'hoch',
'keyboardButtonLeft': 'links',
'keyboardButtonRight': 'rechts',
'keyboardButtonDown': 'runter',
'keyboardButtonEscape': 'Escape',
'keyboardButtonTab': 'Tab',
'keyboardButtonReturn': 'Enter',
'keyboardButtonKeys': 'Um andere Zeichen zu senden, hier tippen:',
'selectUserAdminHeader': 'Alle Profile',
'displayUserAdminHeader': 'Profile',
'displayUserAdminContentSaveButton': 'Speichern',
'selectPlaylistHeader': 'Wähle eine Playlist',
'displayPlaylistHeader': 'Playlist',
'displayPlaylistSaveButton': 'Speichern',
'selectPlaylistAddPlaylistButton': 'Hinzufügen',
'Loading (external)...': 'Laden (extern)...',
'Loading...': 'Laden...',
'Error...': 'Fehler...',
'No connection': 'Keine Verbindung',
'No session': 'Keine Sitzung',
'Uploading photo...': 'Foto hochladen...',
'Getting current song...': 'Lade aktuelles Lied...',
'Login...': 'Einloggen...',
'Creating profile...': 'Erstelle Profil...',
'This is not a valid name.': 'Dies ist kein gültiger Name.',
'Uploading profile...': 'Profil hochladen...',
'songs': 'Lieder',
'YourName': 'DeinName',
'discoverConnectHeader': 'Verbinde zum Server',
'discoverConnectServerAddress': 'Serveradresse:',
'discoverConnectButton': 'Verbinden',
'Checking...': 'Prüfen...',
'timeout': 'Zeitüberschreitung'
}
}
};
function translate() {
//repair broken buttons on the first page (get broken while translating)
var repairButtons = function () {
$($('#discoverConnect')[0].childNodes).wrap('<span class="ui-btn-inner"><span class="ui-btn-text"> </span></span>');
$($('#discoverReadQr')[0].childNodes).wrap('<span class="ui-btn-inner"><span class="ui-btn-text"> </span></span>');
};
$('body').i18n();
repairButtons();
$.i18n.init({
resStore: translations,
supportedLngs: ['en', 'de'],
fallbackLng: 'en',
keyseparator: '::',
nsseparator: ':::'
}).done(function () {
$('body').i18n();
repairButtons();
});
}
+6 -1
View File
@@ -350,10 +350,15 @@ namespace VocaluxeLib
NoPopup = -1
}
[Flags]
public enum EUserRole
{
TR_USERROLE_GUEST = 0,
TR_USERROLE_NORMAL = 1,
TR_USERROLE_ADMIN = 2
TR_USERROLE_ADMIN = 2,
TR_USERROLE_KEYBOARDUSER = 4,
TR_USERROLE_ADDSONGSUSER = 8,
TR_USERROLE_PLAYLISTEDITOR = 16,
TR_USERROLE_PROFILEEDITOR = 32
}
}
+6 -5
View File
@@ -370,7 +370,7 @@ namespace VocaluxeLib.Menu
_Player = player;
_PlayerSelector.Color = CBase.Theme.GetPlayerColor(player);
}
//Normal activation
//Normal activation
else if (active)
{
Selection = 0;
@@ -379,7 +379,7 @@ namespace VocaluxeLib.Menu
_PlayerSelector.Color = CBase.Theme.GetPlayerColor(player);
_PlayerSelector.Visible = true;
}
//Deactivate
//Deactivate
else
{
Selection = -1;
@@ -456,7 +456,7 @@ namespace VocaluxeLib.Menu
return new CStatic(_PartyModeID);
}
public void UnloadTextures() {}
public void UnloadTextures() { }
public void LoadTextures()
{
@@ -486,7 +486,7 @@ namespace VocaluxeLib.Menu
for (int j = 0; j < _NumW; j++)
{
var rect = new SRectF(Rect.X + j * (_TileW + _SpaceW), Rect.Y + i * (_TileH + _SpaceH), _TileW, _TileH, Rect.Z);
var tileStatic = new CStatic(_PartyModeID, _TextureEmptyTile, ColorEmptyTile, rect) {Aspect = EAspect.Crop};
var tileStatic = new CStatic(_PartyModeID, _TextureEmptyTile, ColorEmptyTile, rect) { Aspect = EAspect.Crop };
var tileText = new CText(rect.X + rect.W / 2, rect.Y + rect.H + _Theme.NameSpace, rect.Z, _Theme.NameHeight, rect.W, EAlignment.Center, _Theme.NameStyle,
_Theme.NameFont, _Theme.NameColor, "");
_Tiles.Add(new CTile(tileStatic, tileText, -1));
@@ -508,7 +508,8 @@ namespace VocaluxeLib.Menu
for (int p = 0; p < CBase.Game.GetNumPlayer(); p++)
{
//Don't show profile if is selected, but if selected and guest
if (CBase.Game.GetPlayers()[p].ProfileID == profile.ID && profile.UserRole == EUserRole.TR_USERROLE_GUEST)
if (CBase.Game.GetPlayers()[p].ProfileID == profile.ID
&& profile.UserRole.HasFlag(EUserRole.TR_USERROLE_GUEST))
visible = false;
}
}