From 3126d5aaf076ec96f4df6ea53e77999a35833c5c Mon Sep 17 00:00:00 2001 From: lukeIam Date: Tue, 15 Oct 2013 16:00:01 +0200 Subject: [PATCH] User/Roles for webserver --- ClientServerLib/ClientServerLib/CServer.cs | 50 +- .../ClientServerLib/CWebservice.cs | 98 ++- .../ClientServerLib/DataStructs.cs | 16 +- .../ClientServerLib/ServerLib.csproj | 5 + ClientServerLib/ClientServerLib/Session.cs | 35 + .../ClientServerLib/SessionControl.cs | 65 ++ ClientServerLib/ClientServerLib/UserRights.cs | 17 + .../ClientServerLib/UserRoleControl.cs | 35 + ClientServerLib/ClientServerLib/UserRoles.cs | 14 + Vocaluxe/Base/Server/CVocaluxeServer.cs | 155 +++- Vocaluxe/Website/index.html | 458 +++++----- Vocaluxe/Website/js/main.js | 783 ++++++++++-------- VocaluxeLib/Profile/CProfile.cs | 7 +- 13 files changed, 1134 insertions(+), 604 deletions(-) create mode 100644 ClientServerLib/ClientServerLib/Session.cs create mode 100644 ClientServerLib/ClientServerLib/SessionControl.cs create mode 100644 ClientServerLib/ClientServerLib/UserRights.cs create mode 100644 ClientServerLib/ClientServerLib/UserRoleControl.cs create mode 100644 ClientServerLib/ClientServerLib/UserRoles.cs diff --git a/ClientServerLib/ClientServerLib/CServer.cs b/ClientServerLib/ClientServerLib/CServer.cs index 4bd9e39e..07dec143 100644 --- a/ClientServerLib/ClientServerLib/CServer.cs +++ b/ClientServerLib/ClientServerLib/CServer.cs @@ -94,6 +94,45 @@ namespace ServerLib } + #endregion + + #region user management + + private static SetPasswordDelegate setPassword; + public static SetPasswordDelegate SetPassword + { + internal get { return CServer.setPassword; } + set { CServer.setPassword = value; } + } + + private static ValidatePasswordDelegate validatePassword; + public static ValidatePasswordDelegate ValidatePassword + { + internal get { return CServer.validatePassword; } + set { CServer.validatePassword = value; } + } + + private static GetUserRoleDelegate getUserRole; + public static GetUserRoleDelegate GetUserRole + { + internal get { return CServer.getUserRole; } + set { CServer.getUserRole = value; } + } + + private static SetUserRoleDelegate setUserRole; + public static SetUserRoleDelegate SetUserRole + { + internal get { return CServer.setUserRole; } + set { CServer.setUserRole = value; } + } + + private static GetUserIdFromUsernameDelegate getUserIdFromUsername; + public static GetUserIdFromUsernameDelegate GetUserIdFromUsername + { + internal get { return CServer.getUserIdFromUsername; } + set { CServer.getUserIdFromUsername = value; } + } + #endregion public CServer(int port, bool encrypted) @@ -101,6 +140,8 @@ namespace ServerLib init(port, encrypted); } + #region server control + private void init(int port, bool encrypted) { string hostname = Dns.GetHostName(); @@ -178,7 +219,7 @@ namespace ServerLib private void registerUrlAndCert(int port) { - #if WIN +#if WIN ProcessStartInfo info = new ProcessStartInfo(); info.FileName = "WebserverInitalConfig.exe"; @@ -194,11 +235,14 @@ namespace ServerLib p.Close(); } - #else +#else //Required? - #endif +#endif } + + #endregion + } } diff --git a/ClientServerLib/ClientServerLib/CWebservice.cs b/ClientServerLib/ClientServerLib/CWebservice.cs index e812491e..9e77c0bc 100644 --- a/ClientServerLib/ClientServerLib/CWebservice.cs +++ b/ClientServerLib/ClientServerLib/CWebservice.cs @@ -6,6 +6,7 @@ using System.Text; using System.ServiceModel.Web; using System.Web.Services; using System.IO; +using System.ServiceModel.Channels; namespace ServerLib { @@ -20,6 +21,12 @@ namespace ServerLib #region profile + [OperationContract] + [WebInvoke(Method = "GET", + ResponseFormat = WebMessageFormat.Json, + UriTemplate = "/getOwnProfileId")] + int getOwnProfileId(); + [OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, @@ -53,6 +60,12 @@ namespace ServerLib #region website + [OperationContract] + [WebInvoke(Method = "GET", + ResponseFormat = WebMessageFormat.Json, + UriTemplate = "/login?username={username}&password={password}")] + Guid login(string username, string password); + [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, @@ -114,8 +127,35 @@ namespace ServerLib { } + private static Guid getSession() + { + Guid sessionKey = Guid.Empty; + string sessionHeader = + ((HttpRequestMessageProperty)OperationContext.Current.IncomingMessageProperties["httpRequest"]).Headers["session"]; + if (sessionHeader == null || sessionHeader == "") + { + return sessionKey; + } + try + { + sessionKey = Guid.Parse(sessionHeader); + } + catch (Exception e) + { + } + return sessionKey; + } + public bool sendKeyEvent(string key) { + Guid sessionKey = getSession(); + + if (sessionKey == Guid.Empty || !SessionControl.requestRight(sessionKey, UserRights.UseKeyboard)) + { + WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden; + return false; + } + if (CServer.SendKeyEvent == null) { return false; @@ -125,22 +165,58 @@ namespace ServerLib #region profile + public int getOwnProfileId() + { + Guid sessionKey = getSession(); + if (sessionKey == Guid.Empty) + { + WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden; + return -1; + } + + return SessionControl.getUserIdFromSession(sessionKey); + } + public bool sendProfile(ProfileData profile) { - if (CServer.SendProfileData == null) + Guid sessionKey = getSession(); + + if (sessionKey == Guid.Empty || (!SessionControl.requestRight(sessionKey, UserRights.EditAllProfiles) && + SessionControl.getUserIdFromSession(sessionKey) != profile.ProfileId)) { + WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden; return false; } + + if (CServer.SendProfileData == null) + { + WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound; + return false; + } + return CServer.SendProfileData(profile); } public ProfileData getProfile(int profileId) { + Guid sessionKey = getSession(); + + if (sessionKey == Guid.Empty || (!SessionControl.requestRight(sessionKey, UserRights.ViewOtherProfiles) && + SessionControl.getUserIdFromSession(sessionKey) != profileId)) + { + WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden; + return new ProfileData(); + } + if (CServer.GetProfileData == null) { return new ProfileData(); } - return CServer.GetProfileData(profileId); + + bool isReadonly = (!SessionControl.requestRight(sessionKey, UserRights.EditAllProfiles) && + SessionControl.getUserIdFromSession(sessionKey) != profileId); + + return CServer.GetProfileData(profileId, isReadonly); } public ProfileData[] getProfileList() @@ -158,6 +234,13 @@ namespace ServerLib public bool sendPhoto(PhotoData photo) { + Guid sessionKey = getSession(); + if (!SessionControl.requestRight(sessionKey, UserRights.UploadPhotos)) + { + WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden; + return false; + } + return CServer.SendPhoto(photo); } @@ -165,6 +248,16 @@ namespace ServerLib #region website + public Guid login(string username, string password) + { + Guid sessionId = SessionControl.openSession(username, password); + if (sessionId == Guid.Empty) + { + WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden; + } + return sessionId; + } + public Stream Index() { if (WebOperationContext.Current != null) @@ -277,6 +370,5 @@ namespace ServerLib } #endregion - } } diff --git a/ClientServerLib/ClientServerLib/DataStructs.cs b/ClientServerLib/ClientServerLib/DataStructs.cs index a32f6498..700f76fa 100644 --- a/ClientServerLib/ClientServerLib/DataStructs.cs +++ b/ClientServerLib/ClientServerLib/DataStructs.cs @@ -15,7 +15,7 @@ namespace ServerLib #region profile - public delegate ProfileData GetProfileDataDelegate(int profileId); + public delegate ProfileData GetProfileDataDelegate(int profileId, bool isReadonly); public delegate bool SendProfileDataDelegate(ProfileData profile); public delegate ProfileData[] GetProfileListDelegate(); @@ -121,4 +121,18 @@ namespace ServerLib } #endregion + + #region user management + + public delegate void SetPasswordDelegate(int profileId, string newPassword); + + public delegate bool ValidatePasswordDelegate(int profileId, string password); + + public delegate int GetUserRoleDelegate(int profileId); + + public delegate void SetUserRoleDelegate(int profileId, int userRole); + + public delegate int GetUserIdFromUsernameDelegate(string username); + + #endregion } diff --git a/ClientServerLib/ClientServerLib/ServerLib.csproj b/ClientServerLib/ClientServerLib/ServerLib.csproj index 023b4bc6..417c9063 100644 --- a/ClientServerLib/ClientServerLib/ServerLib.csproj +++ b/ClientServerLib/ClientServerLib/ServerLib.csproj @@ -52,6 +52,11 @@ + + + + + - -
- - -
- Login -
- - - - - - - -
-
-

All profiles

-
- - -
-
    -
    - -
    - - -
    -
    -

    Profile

    -
    - - -
    - Avatar - - - - - - - -
    - Save and upload -
    - -
    - - -
    -
    -

    No current song

    -
    - - -
    - Cover -
    -
    -
    - - - -
    - - - -
    - - - -
    - - - -
    - - - -
    - -
    - - -
    -
    -

    All songs

    -
    - - -
    -
      -
      - -
      - - -
      -
      -

      Keyboard

      -
      - - -
      -
      -
      -
      - up -
      -
      -
      - left -
      -
      -
      -
      - right -
      -
      -
      - down -
      -
      -
      -
      -
      - escape -
      -
      - tab -
      -
      - return -
      -
      -
      - - -
      -
      - -
      - - -
      - - - - + + + + Vocaluxe + + + + + + + + +
      +
      +

      Login

      +
      + + +
      + + + + +
      + Login +
      + +
      + + + + + +
      +
      +

      All profiles

      +
      + + +
      +
        +
        + +
        + + +
        +
        +

        Profile

        +
        + + +
        + Avatar + + + + + + + +
        + Save and upload +
        + +
        + + +
        +
        +

        No current song

        +
        + + +
        + Cover +
        +
        +
        + + - +
        + + - +
        + + - +
        + + - +
        + + - +
        + +
        + + +
        +
        +

        All songs

        +
        + + +
        +
          +
          + +
          + + +
          +
          +

          Keyboard

          +
          + + +
          +
          +
          +
          + up +
          +
          +
          + left +
          +
          +
          +
          + right +
          +
          +
          + down +
          +
          +
          +
          +
          + escape +
          +
          + tab +
          +
          + return +
          +
          +
          + + +
          +
          + +
          + + +
          + + + + diff --git a/Vocaluxe/Website/js/main.js b/Vocaluxe/Website/js/main.js index 96e70ae7..8b0bca97 100644 --- a/Vocaluxe/Website/js/main.js +++ b/Vocaluxe/Website/js/main.js @@ -1,360 +1,423 @@ -var ownProfileId = -1; -var profileIdRequest = -1; -var songIdRequest = -1 -var allSongsCache = null; - -$(document).ready(function () { - replaceTransitionHandler(); - initPageLoadHandler(); - initKeyboardPageHandler(); - initMainPageHandler(); - initLoginPageHandler(); -}); - -function replaceTransitionHandler() { - //Thx to http://stackoverflow.com/a/14096311 - var oldDefaultTransitionHandler = $.mobile.defaultTransitionHandler; - - $.mobile.defaultTransitionHandler = function (name, reverse, $to, $from) { - var promise = $to.data('promise'); - if (promise) { - $to.removeData('promise'); - $.mobile.loading('show'); - return promise.then(function () { - $.mobile.loading('hide'); - return oldDefaultTransitionHandler(name, reverse, $to, $from); - }); - } - return oldDefaultTransitionHandler(name, reverse, $to, $from); - }; -} - -function initPageLoadHandler() { - //pageLoadHandler for displayProfile - $(document).on('pagebeforeshow', '#displayProfile', function () { - var promise = $.ajax({ - url: "getProfile?profileId=" + profileIdRequest - }).done(function (result) { - $('#playerName').prop("value", result.PlayerName); - if (result.Avatar && result.Avatar.base64Data) { - $('#playerAvatar').prop("src", result.Avatar.base64Data); - } - $('#playerType').prop("value", result.Type); - $('#playerDifficulty').prop("value", result.Difficulty); - if (result.IsEditable) { - $('#playerAvatar').click(function () { - if ($('#captureContainer').length > 0) { - $('#captureContainer').remove(); - } - - $(document.body).append('
          '); - - $('#capture').change(function (eventData) { - if (eventData && eventData.target && eventData.target.files && eventData.target.files.length == 1) { - var file = eventData.target.files[0]; - var reader = new FileReader(); - reader.onloadend = function (e) { - $('#playerAvatar').prop("src", e.target.result); - $('#playerAvatar').data("changed", true); - $('#captureContainer').remove(); - }; - reader.readAsDataURL(file); - } - }); - - $('#capture').click(); - }); - - $('#playerSaveButton').click(function () { - var dataToUpload = {}; - - dataToUpload["ProfileId"] = profileIdRequest; - dataToUpload["PlayerName"] = $('#playerName').prop("value"); - dataToUpload["Type"] = $('#playerType').prop("value"); - dataToUpload["Difficulty"] = $('#playerDifficulty').prop("value"); - dataToUpload["Avatar"] = $('#playerAvatar').data("changed") ? { "base64Data": $('#playerAvatar').prop("src") } : null; - - $('#content').wrap('
          '); - $.mobile.loading('show', { - text: 'Uploading profile...', - textVisible: true - }); - - $.ajax({ - url: "sendProfile", - dataType: "json", - contentType: "application/json;charset=utf-8", - type: "POST", - data: JSON.stringify(dataToUpload), - success: function (msg) { - - } - }).always(function () { - $.mobile.loading('hide'); - $('#content').unwrap(); - }); - - }); - } - else { - $('#playerName').prop('disabled', true); - $('#playerType').prop('disabled', true); - $('#playerDifficulty').prop('disabled', true); - $('#playerSaveButton').hide(); - $('#playerAvatar').unbind("click"); - } - }); - - // Save promise on page so the transition handler can find it. - $(this).data('promise', promise); - }); - - //pageLoadHandler for selectProfile - $(document).on('pagebeforeshow', '#selectProfile', function () { - var promise = $.ajax({ - url: "getProfileList" - }).done(function (data) { - $('#selectProfileList').children().remove(); - - function handleProfileSelectLineClick(e) { - profileIdRequest = parseInt(e.currentTarget.id.replace("ProfileSelectLine_", "")); - $.mobile.changePage("#displayProfile", { transition: "slidefade" }); - } - - for (var profile in data) { - $('
        • ' + data[profile].PlayerName + '

          Click here to show the profile of ' + data[profile].PlayerName + '

        • ') - .appendTo('#selectProfileList') - .click(handleProfileSelectLineClick); - } - - $('#selectProfileList').listview('refresh'); - }); - - // Save promise on page so the transition handler can find it. - $(this).data('promise', promise); - }); - - //pageLoadHandler for displaySong - $(document).on('pagebeforeshow', '#displaySong', function () { - var promise = $.ajax({ - url: "getSong?songId=" + songIdRequest - }).done(function (result) { - if (result.Title != null) { - $('#displaySongTitle').text(result.Title); - } - else { - $('#displaySongTitle').text("No current song"); - } - - if (result.Cover && result.Cover.base64Data) { - $('#displaySongCover').prop("src", result.Cover.base64Data); - } - else { - $('#displaySongCover').prop("src", "img/noCover.png"); - } - - if (result.Artist != null) { - $('#displaySongArtist').text(result.Artist); - } - else { - $('#displaySongArtist').text("-"); - } - - if (result.Genre != null) { - $('#displaySongGenre').text(result.Genre); - } - else { - $('#displaySongGenre').text("-"); - } - - if (result.Year != null && result.Year != "") { - $('#displaySongYear').text(result.Year); - } - else { - $('#displaySongYear').text("-"); - } - - if (result.Language != null) { - $('#displaySongLanguage').text(result.Language); - } - else { - $('#displaySongLanguage').text("-"); - } - - $('#displaySongIsDuet').text(result.IsDuet ? "Yes" : "No"); - }); - - // Save promise on page so the transition handler can find it. - $(this).data('promise', promise); - }); - - //pageLoadHandler for selectSong - $(document).on('pagebeforeshow', '#selectSong', function () { - function handleGetAllSongs() { - $('#selectSongList').children().remove(); - - function handleSelectSongLineClick(e) { - songIdRequest = parseInt(e.currentTarget.id.replace("selectSongLine_", "")); - $.mobile.changePage("#displaySong", { transition: "slidefade" }); - } - - for (var id in allSongsCache) { - $('
        • '/*+' '*/ + '

          ' + allSongsCache[id].Artist + '

          ' + allSongsCache[id].Title + '

        • ') - .appendTo('#selectSongList') - .click(handleSelectSongLineClick); - } - - $('#selectSongList').listview('refresh'); - } - - if (allSongsCache == null) { - var promise = $.ajax({ - url: "getAllSongs" - }).done(function (data) { - allSongsCache = data; - handleGetAllSongs() - }); - - // Save promise on page so the transition handler can find it. - $(this).data('promise', promise); - } - else { - handleGetAllSongs() - } - }); -} - -function initLoginPageHandler() { - $('#loginButton').click(function () { - ownProfileId = parseInt($('#playerId').prop("value")); - if (ownProfileId != "NaN") { - $.mobile.changePage("#main", { transition: "slidefade" }); - } - }); -} - -function initMainPageHandler() { - $('#yourProfileLink').click(function () { - profileIdRequest = ownProfileId; - $.mobile.changePage("#displayProfile", { transition: "slidefade" }); - }); - - $('#currentSongLink').click(function () { - $('#content').wrap('
          '); - $.mobile.loading('show', { - text: 'Getting current song...', - textVisible: true - }); - - $.ajax({ - url: "getCurrentSongId" - }).done(function (result) { - songIdRequest = parseInt(result); - $.mobile.loading('hide'); - $('#content').unwrap(); - $.mobile.changePage("#displaySong", { transition: "slidefade" }); - }).fail(function (result) { - $.mobile.loading('hide'); - $('#content').unwrap(); - }); - }); - - $('#mainPageTakePhotoLink').click(function () { - if ($('#captureContainer').length > 0) { - $('#captureContainer').remove(); - } - - $(document.body).append('
          '); - - $('#capture').change(function (eventData) { - if (eventData && eventData.target && eventData.target.files && eventData.target.files.length == 1) { - $('#content').wrap('
          '); - $.mobile.loading('show', { - text: 'Uploading photo...', - textVisible: true - }); - - var file = eventData.target.files[0]; - var reader = new FileReader(); - - reader.onloadend = function (e) { - $.ajax({ - url: "sendPhoto", - dataType: "json", - contentType: "application/json;charset=utf-8", - type: "POST", - data: JSON.stringify({ Photo: { base64Data: e.target.result } }), - success: function (msg) { - - } - }).always(function () { - $.mobile.loading('hide'); - $('#content').unwrap(); - }); - }; - - reader.readAsDataURL(file); - } - }); - - $('#capture').click(); - }); -} - -function initKeyboardPageHandler() { - $('#keyboardButtonUp').click(function () { - $.ajax({ - url: "sendKeyEvent?key=up" - }) - }); - - $('#keyboardButtonDown').click(function () { - $.ajax({ - url: "sendKeyEvent?key=down" - }) - }); - - $('#keyboardButtonLeft').click(function () { - $.ajax({ - url: "sendKeyEvent?key=left" - }) - }); - - $('#keyboardButtonRight').click(function () { - $.ajax({ - url: "sendKeyEvent?key=right" - }) - }); - - $('#keyboardButtonEscape').click(function () { - $.ajax({ - url: "sendKeyEvent?key=escape" - }) - }); - - $('#keyboardButtonkeyboardButtonTab').click(function () { - $.ajax({ - url: "sendKeyEvent?key=tab" - }) - }); - - $('#keyboardButtonReturn').click(function () { - $.ajax({ - url: "sendKeyEvent?key=return" - }) - }); - - $('#keyboardButtonKeys').keyup(function (e) { - var c = String.fromCharCode(e.keyCode); - if (c.match(/\w/)) { - c = e.keyCode >= 65 ? c.toLowerCase() : c; - $.ajax({ - url: "sendKeyEvent?key=" + c - }) - } - var oldText = $('#keyboardButtonKeys')[0].value; - if (oldText.length > 0) { - $('#keyboardButtonKeys')[0].value = oldText.slice(1); - } - }); -} +var ownProfileId = -1; +var profileIdRequest = -1; +var songIdRequest = -1 +var allSongsCache = null; +var sessionId = ""; + +$(document).ready(function () { + replaceTransitionHandler(); + initPageLoadHandler(); + initKeyboardPageHandler(); + initMainPageHandler(); + initLoginPageHandler(); +}); + +function replaceTransitionHandler() { + //Thx to http://stackoverflow.com/a/14096311 + var oldDefaultTransitionHandler = $.mobile.defaultTransitionHandler; + + $.mobile.defaultTransitionHandler = function (name, reverse, $to, $from) { + var promise = $to.data('promise'); + if (promise) { + $to.removeData('promise'); + $('#content').wrap('
          '); + $.mobile.loading('show', { + text: 'Loading data...', + textVisible: true + }); + return promise.then(function () { + $.mobile.loading('hide'); + $('#content').unwrap(); + return oldDefaultTransitionHandler(name, reverse, $to, $from); + }); + } + return oldDefaultTransitionHandler(name, reverse, $to, $from); + }; +} + +function initPageLoadHandler() { + //pageLoadHandler for displayProfile + $(document).on('pagebeforeshow', '#displayProfile', function () { + var promise = $.ajax({ + url: "getProfile?profileId=" + profileIdRequest, + headers: { "session": sessionId } + }).done(function (result) { + $('#playerName').prop("value", result.PlayerName); + if (result.Avatar && result.Avatar.base64Data) { + $('#playerAvatar').prop("src", result.Avatar.base64Data); + } + $('#playerType').prop("value", result.Type); + $('#playerDifficulty').prop("value", result.Difficulty); + if (result.IsEditable) { + $('#playerName').prop('disabled', false); + $('#playerType').prop('disabled', false); + $('#playerDifficulty').prop('disabled', false); + $('#playerSaveButton').show(); + + $('#playerAvatar').unbind("click"); + $('#playerAvatar').click(function () { + if ($('#captureContainer').length > 0) { + $('#captureContainer').remove(); + } + + $(document.body).append('
          '); + + $('#capture').change(function (eventData) { + if (eventData && eventData.target && eventData.target.files && eventData.target.files.length == 1) { + var file = eventData.target.files[0]; + var reader = new FileReader(); + reader.onloadend = function (e) { + $('#playerAvatar').prop("src", e.target.result); + $('#playerAvatar').data("changed", true); + $('#captureContainer').remove(); + }; + reader.readAsDataURL(file); + } + }); + + $('#capture').click(); + }); + + $('#playerSaveButton').click(function () { + var dataToUpload = {}; + + dataToUpload["ProfileId"] = profileIdRequest; + dataToUpload["PlayerName"] = $('#playerName').prop("value"); + dataToUpload["Type"] = $('#playerType').prop("value"); + dataToUpload["Difficulty"] = $('#playerDifficulty').prop("value"); + dataToUpload["Avatar"] = $('#playerAvatar').data("changed") ? { "base64Data": $('#playerAvatar').prop("src") } : null; + + $('#content').wrap('
          '); + $.mobile.loading('show', { + text: 'Uploading profile...', + textVisible: true + }); + + $.ajax({ + url: "sendProfile", + dataType: "json", + contentType: "application/json;charset=utf-8", + type: "POST", + headers: { "session": sessionId }, + data: JSON.stringify(dataToUpload), + success: function (msg) { + + } + }).always(function () { + $.mobile.loading('hide'); + $('#content').unwrap(); + }); + + }); + } + else { + $('#playerName').prop('disabled', true); + $('#playerType').prop('disabled', true); + $('#playerDifficulty').prop('disabled', true); + $('#playerSaveButton').hide(); + $('#playerAvatar').unbind("click"); + } + }); + + // Save promise on page so the transition handler can find it. + $(this).data('promise', promise); + }); + + //pageLoadHandler for selectProfile + $(document).on('pagebeforeshow', '#selectProfile', function () { + var promise = $.ajax({ + url: "getProfileList", + headers: { "session": sessionId } + }).done(function (data) { + $('#selectProfileList').children().remove(); + + function handleProfileSelectLineClick(e) { + profileIdRequest = parseInt(e.currentTarget.id.replace("ProfileSelectLine_", "")); + $.mobile.changePage("#displayProfile", { transition: "slidefade" }); + } + + for (var profile in data) { + $('
        • ' + data[profile].PlayerName + '

          Click here to show the profile of ' + data[profile].PlayerName + '

        • ') + .appendTo('#selectProfileList') + .click(handleProfileSelectLineClick); + } + + $('#selectProfileList').listview('refresh'); + }); + + // Save promise on page so the transition handler can find it. + $(this).data('promise', promise); + }); + + //pageLoadHandler for displaySong + $(document).on('pagebeforeshow', '#displaySong', function () { + var promise = $.ajax({ + url: "getSong?songId=" + songIdRequest, + headers: { "session": sessionId } + }).done(function (result) { + if (result.Title != null) { + $('#displaySongTitle').text(result.Title); + } + else { + $('#displaySongTitle').text("No current song"); + } + + if (result.Cover && result.Cover.base64Data) { + $('#displaySongCover').prop("src", result.Cover.base64Data); + } + else { + $('#displaySongCover').prop("src", "img/noCover.png"); + } + + if (result.Artist != null) { + $('#displaySongArtist').text(result.Artist); + } + else { + $('#displaySongArtist').text("-"); + } + + if (result.Genre != null) { + $('#displaySongGenre').text(result.Genre); + } + else { + $('#displaySongGenre').text("-"); + } + + if (result.Year != null && result.Year != "") { + $('#displaySongYear').text(result.Year); + } + else { + $('#displaySongYear').text("-"); + } + + if (result.Language != null) { + $('#displaySongLanguage').text(result.Language); + } + else { + $('#displaySongLanguage').text("-"); + } + + $('#displaySongIsDuet').text(result.IsDuet ? "Yes" : "No"); + }); + + // Save promise on page so the transition handler can find it. + $(this).data('promise', promise); + }); + + //pageLoadHandler for selectSong + $(document).on('pagebeforeshow', '#selectSong', function () { + function handleGetAllSongs() { + $('#selectSongList').children().remove(); + + function handleSelectSongLineClick(e) { + songIdRequest = parseInt(e.currentTarget.id.replace("selectSongLine_", "")); + $.mobile.changePage("#displaySong", { transition: "slidefade" }); + } + + for (var id in allSongsCache) { + $('
        • '/*+' '*/ + '

          ' + allSongsCache[id].Artist + '

          ' + allSongsCache[id].Title + '

        • ') + .appendTo('#selectSongList') + .click(handleSelectSongLineClick); + } + + $('#selectSongList').listview('refresh'); + } + + if (allSongsCache == null) { + var promise = $.ajax({ + url: "getAllSongs", + headers: { "session": sessionId } + }).done(function (data) { + allSongsCache = data; + handleGetAllSongs() + }); + + // Save promise on page so the transition handler can find it. + $(this).data('promise', promise); + } + else { + handleGetAllSongs() + } + }); +} + +function initLoginPageHandler() { + var keyPressed = function (e) { + if (e.which == 13) { + $('#loginButton').click(); + } + }; + + $('#loginName').keypress(keyPressed) + $('#loginPassword').keypress(keyPressed); + + $('#loginButton').click(function () { + $('#content').wrap('
          '); + $.mobile.loading('show', { + text: 'Login...', + textVisible: true + }); + + username = $('#loginName').prop("value"); + password = $('#loginPassword').prop("value"); + + $.ajax({ + url: "login?username=" + username + "&password=" + password + }).done(function (result) { + sessionId = result; + $.ajax({ + url: "getOwnProfileId", + headers: { "session": sessionId } + }).done(function (result) { + ownProfileId = result; + + $.mobile.loading('hide'); + $('#content').unwrap(); + + $.mobile.changePage("#main", { transition: "slidefade" }); + }).fail(function (result) { + $.mobile.loading('hide'); + $('#content').unwrap(); + }); + }).fail(function (result) { + $.mobile.loading('hide'); + $('#content').unwrap(); + }); + }); +} + +function initMainPageHandler() { + $('#yourProfileLink').click(function () { + profileIdRequest = ownProfileId; + $.mobile.changePage("#displayProfile", { transition: "slidefade" }); + }); + + $('#currentSongLink').click(function () { + $('#content').wrap('
          '); + $.mobile.loading('show', { + text: 'Getting current song...', + textVisible: true + }); + + $.ajax({ + url: "getCurrentSongId", + headers: { "session": sessionId } + }).done(function (result) { + songIdRequest = parseInt(result); + $.mobile.loading('hide'); + $('#content').unwrap(); + $.mobile.changePage("#displaySong", { transition: "slidefade" }); + }).fail(function (result) { + $.mobile.loading('hide'); + $('#content').unwrap(); + }); + }); + + $('#mainPageTakePhotoLink').click(function () { + if ($('#captureContainer').length > 0) { + $('#captureContainer').remove(); + } + + $(document.body).append('
          '); + + $('#capture').change(function (eventData) { + if (eventData && eventData.target && eventData.target.files && eventData.target.files.length == 1) { + $('#content').wrap('
          '); + $.mobile.loading('show', { + text: 'Uploading photo...', + textVisible: true + }); + + var file = eventData.target.files[0]; + var reader = new FileReader(); + + reader.onloadend = function (e) { + $.ajax({ + url: "sendPhoto", + dataType: "json", + contentType: "application/json;charset=utf-8", + type: "POST", + headers: { "session": sessionId }, + data: JSON.stringify({ Photo: { base64Data: e.target.result } }), + success: function (msg) { + + } + }).always(function () { + $.mobile.loading('hide'); + $('#content').unwrap(); + }); + }; + + reader.readAsDataURL(file); + } + }); + + $('#capture').click(); + }); +} + +function initKeyboardPageHandler() { + $('#keyboardButtonUp').click(function () { + $.ajax({ + url: "sendKeyEvent?key=up", + headers: { "session": sessionId } + }) + }); + + $('#keyboardButtonDown').click(function () { + $.ajax({ + url: "sendKeyEvent?key=down", + headers: { "session": sessionId } + }) + }); + + $('#keyboardButtonLeft').click(function () { + $.ajax({ + url: "sendKeyEvent?key=left", + headers: { "session": sessionId } + }) + }); + + $('#keyboardButtonRight').click(function () { + $.ajax({ + url: "sendKeyEvent?key=right", + headers: { "session": sessionId } + }) + }); + + $('#keyboardButtonEscape').click(function () { + $.ajax({ + url: "sendKeyEvent?key=escape", + headers: { "session": sessionId } + }) + }); + + $('#keyboardButtonkeyboardButtonTab').click(function () { + $.ajax({ + url: "sendKeyEvent?key=tab", + headers: { "session": sessionId } + }) + }); + + $('#keyboardButtonReturn').click(function () { + $.ajax({ + url: "sendKeyEvent?key=return", + headers: { "session": sessionId } + }) + }); + + $('#keyboardButtonKeys').keyup(function (e) { + var c = String.fromCharCode(e.keyCode); + if (c.match(/\w/)) { + c = e.keyCode >= 65 ? c.toLowerCase() : c; + $.ajax({ + url: "sendKeyEvent?key=" + c, + headers: { "session": sessionId } + }) + } + var oldText = $('#keyboardButtonKeys')[0].value; + if (oldText.length > 0) { + $('#keyboardButtonKeys')[0].value = oldText.slice(1); + } + }); +} diff --git a/VocaluxeLib/Profile/CProfile.cs b/VocaluxeLib/Profile/CProfile.cs index ff4f6fd8..85d32dc7 100644 --- a/VocaluxeLib/Profile/CProfile.cs +++ b/VocaluxeLib/Profile/CProfile.cs @@ -30,6 +30,9 @@ namespace VocaluxeLib.Profile public string FilePath; public string FileName; public string AvatarFileName; + public byte[] PasswordHash; + public byte[] PasswordSalt; + public int UserRoles; public EGameDifficulty Difficulty; @@ -56,7 +59,7 @@ namespace VocaluxeLib.Profile Active = EOffOn.TR_CONFIG_ON; AvatarFileName = String.Empty; - FileName = String.Empty; + FileName = String.Empty; } public bool LoadProfile() @@ -104,7 +107,7 @@ namespace VocaluxeLib.Profile string filename = string.Empty; // ReSharper disable LoopCanBeConvertedToQuery foreach (char chr in PlayerName) - // ReSharper restore LoopCanBeConvertedToQuery + // ReSharper restore LoopCanBeConvertedToQuery { if (char.IsLetter(chr)) filename += chr.ToString();