Webserver: Edit profiles (server part)

This commit is contained in:
lukeIam committed 2013-12-13 17:58:22 +01:00
1 parent 5432676c08
commit c782ba3862
6 files changed
+371 -16

No files matched your search

+56 -2
View File
@@ -96,6 +96,60 @@ namespace ServerLib
}
#endregion
#region playlist
private static GetPlaylistsDelegate _GetPlaylists;
public static GetPlaylistsDelegate GetPlaylists
{
get { return _GetPlaylists; }
set { _GetPlaylists = value; }
}
private static GetPlaylistDelegate _GetPlaylist;
public static GetPlaylistDelegate GetPlaylist
{
get { return _GetPlaylist; }
set { _GetPlaylist = value; }
}
private static AddSongToPlaylistDelegate _AddSongToPlaylist;
public static AddSongToPlaylistDelegate AddSongToPlaylist
{
get { return _AddSongToPlaylist; }
set { _AddSongToPlaylist = value; }
}
private static RemoveSongFromPlaylistDelegate _RemoveSongFromPlaylist;
public static RemoveSongFromPlaylistDelegate RemoveSongFromPlaylist
{
get { return _RemoveSongFromPlaylist; }
set { _RemoveSongFromPlaylist = value; }
}
private static MoveSongInPlaylistDelegate _MoveSongInPlaylist;
public static MoveSongInPlaylistDelegate MoveSongInPlaylist
{
get { return _MoveSongInPlaylist; }
set { _MoveSongInPlaylist = value; }
}
private static PlaylistContainsSongDelegate _PlaylistContainsSong;
public static PlaylistContainsSongDelegate PlaylistContainsSong
{
get { return _PlaylistContainsSong; }
set { _PlaylistContainsSong = value; }
}
private static GetPlaylistSongsDelegate _GetPlaylistSongs;
public static GetPlaylistSongsDelegate GetPlaylistSongs
{
get { return _GetPlaylistSongs; }
set { _GetPlaylistSongs = value; }
}
#endregion
#region user management
@@ -135,8 +189,8 @@ namespace ServerLib
set { CServer._GetUserIdFromUsername = value; }
}
#endregion
#endregion
public CServer(int port, bool encrypted)
{
_Init(port, encrypted);
@@ -163,7 +217,7 @@ namespace ServerLib
MaxReceivedMessageSize = 10485760,
MaxBufferSize = 10485760,
MaxBufferPoolSize = 10485760,
ReaderQuotas = {MaxStringContentLength = 10485760, MaxArrayLength = 10485760, MaxBytesPerRead = 10485760}
ReaderQuotas = { MaxStringContentLength = 10485760, MaxArrayLength = 10485760, MaxBytesPerRead = 10485760 }
};
if (encrypted)
{
+84 -4
View File
@@ -333,7 +333,7 @@ namespace ServerLib
#region songs
public SOngInfo GetSong(int songId)
public SSongInfo GetSong(int songId)
{
return CServer.GetSong(songId);
}
@@ -343,11 +343,63 @@ namespace ServerLib
return CServer.GetCurrentSongId();
}
public SOngInfo[] GetAllSongs()
public SSongInfo[] GetAllSongs()
{
return CServer.GetAllSongs();
}
#endregion
#region playlist
public SPlaylistInfo[] GetPlaylists()
{
return CServer.GetPlaylists();
}
public SPlaylistInfo GetPlaylist(int playlistId)
{
return CServer.GetPlaylist(playlistId);
}
public void AddSongToPlaylist(int songId, int playlistId, bool allowDuplicates)
{
if (_CheckRight(EUserRights.AddSongToPlaylist)||_CheckRight(EUserRights.EditPlaylists))
{
CServer.AddSongToPlaylist(songId, playlistId, allowDuplicates);
}
}
public void RemoveSongFromPlaylist(int position, int playlistId, int songId)
{
if (_CheckRight(EUserRights.EditPlaylists))
{
CServer.RemoveSongFromPlaylist(position, playlistId, songId);
}
}
public void MoveSongInPlaylist(int oldPosition, int newPosition, int playlistId, int songId)
{
if (_CheckRight(EUserRights.EditPlaylists))
{
CServer.MoveSongInPlaylist(oldPosition, newPosition, playlistId, songId);
}
}
public bool PlaylistContainsSong(int songId, int playlistId)
{
return CServer.PlaylistContainsSong(songId, playlistId);
}
public SPlaylistSongInfo[] GetPlaylistSongs(int playlistId)
{
return CServer.GetPlaylistSongs(playlistId);
}
public bool IsPlaylistEditable(int playlistId)
{
return _CheckRight(EUserRights.EditPlaylists);
}
#endregion
#region user management
@@ -362,7 +414,8 @@ namespace ServerLib
Guid sessionKey = _GetSession();
if (sessionKey == Guid.Empty)
{
if (WebOperationContext.Current != null) {
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
}
@@ -370,7 +423,8 @@ namespace ServerLib
}
if (!CSessionControl.RequestRight(sessionKey, EUserRights.EditAllProfiles))
{
if (WebOperationContext.Current != null) {
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
}
@@ -379,6 +433,32 @@ namespace ServerLib
CServer.SetUserRole(profileId, userRole);
}
private static bool _CheckRight(EUserRights requestedRight)
{
Guid sessionKey = _GetSession();
if (sessionKey == Guid.Empty)
{
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
}
return false;
}
if (!CSessionControl.RequestRight(sessionKey, requestedRight))
{
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
}
return false;
}
return true;
}
#endregion
}
}
@@ -109,6 +109,20 @@ namespace ServerLib
public delegate int GetCurrentSongIdDelegate();
public delegate SPlaylistInfo[] GetPlaylistsDelegate();
public delegate SPlaylistInfo GetPlaylistDelegate(int playlistId);
public delegate void AddSongToPlaylistDelegate(int songId, int playlistId, bool allowDuplicates);
public delegate void RemoveSongFromPlaylistDelegate(int position, int playlistId, int songId);
public delegate void MoveSongInPlaylistDelegate(int oldPosition, int newPosition, int playlistId, int songId);
public delegate bool PlaylistContainsSongDelegate(int songId, int playlistId);
public delegate SPlaylistSongInfo[] GetPlaylistSongsDelegate(int playlistId);
[DataContract]
public struct SSongInfo
{
@@ -130,6 +144,30 @@ namespace ServerLib
public int SongId { get; set; }
}
public struct SPlaylistSongInfo
{
[DataMember]
public SSongInfo Song;
[DataMember]
public int PlaylistId;
[DataMember]
public int PlaylistPosition;
[DataMember]
public int GameMode;
}
public struct SPlaylistInfo
{
[DataMember]
public int PlaylistId;
[DataMember]
public string PlaylistName;
[DataMember]
public int SongCount;
[DataMember]
public string LastChanged;
}
#endregion
#region user management
@@ -105,7 +105,7 @@ namespace ServerLib
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getSong?songId={songId}")]
SOngInfo GetSong(int songId);
SSongInfo GetSong(int songId);
[OperationContract]
[WebInvoke(Method = "GET",
@@ -117,7 +117,58 @@ namespace ServerLib
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getAllSongs")]
SOngInfo[] GetAllSongs();
SSongInfo[] GetAllSongs();
#endregion
#region playlist
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getPlaylists")]
SPlaylistInfo[] GetPlaylists();
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getPlaylist?id={playlistId}")]
SPlaylistInfo GetPlaylist(int playlistId);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/addSongToPlaylist?songId={songId}&playlistId={playlistId}&duplicates={allowDuplicates}")]
void AddSongToPlaylist(int songId, int playlistId, bool allowDuplicates);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/removeSongFromPlaylist?position={position}&playlistId={playlistId}&songId={songId}")]
void RemoveSongFromPlaylist(int position, int playlistId, int songId);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/moveSongInPlaylist?oldPosition={oldPosition}&newPosition={newPosition}&playlistId={playlistId}&songId={songId}")]
void MoveSongInPlaylist(int oldPosition, int newPosition, int playlistId, int songId);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/playlistContainsSong?songId={songId}&playlistId={playlistId}")]
bool PlaylistContainsSong(int songId, int playlistId);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getPlaylistSongs?playlistId={playlistId}")]
SPlaylistSongInfo[] GetPlaylistSongs(int playlistId);
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/isPlaylistEditable?playlistId={playlistId}")]
bool IsPlaylistEditable(int playlistId);
#endregion
@@ -9,6 +9,8 @@ namespace ServerLib
EditAllProfiles = 0x01,
UploadPhotos = 0x02,
ViewOtherProfiles = 0x04,
UseKeyboard = 0x08
UseKeyboard = 0x08,
EditPlaylists = 0x16,
AddSongToPlaylist = 0x32
}
}