Webserver: use a methode for checking rights

This commit is contained in:
lukeIam committed 2013-12-13 17:58:23 +01:00
1 parent c782ba3862
commit 959a11a4a2
1 file changed
+16 -94
+16 -94
View File
@@ -29,25 +29,12 @@ namespace ServerLib
public void SendKeyEvent(string key) public void SendKeyEvent(string key)
{ {
Guid sessionKey = _GetSession(); if (!_CheckRight(EUserRights.UseKeyboard))
{
return;
}
if (sessionKey == Guid.Empty) if (CServer.SendKeyEvent == null)
{
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
}
}
else if (!CSessionControl.RequestRight(sessionKey, EUserRights.UseKeyboard))
{
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
}
}
else if (CServer.SendKeyEvent == null)
{ {
if (WebOperationContext.Current != null) if (WebOperationContext.Current != null)
{ {
@@ -94,24 +81,8 @@ namespace ServerLib
if (profile.ProfileId != -1) //-1 is the id for a new profile if (profile.ProfileId != -1) //-1 is the id for a new profile
{ {
if (sessionKey == Guid.Empty) if (!(_CheckRight(EUserRights.EditAllProfiles) || CSessionControl.GetUserIdFromSession(sessionKey) == profile.ProfileId))
{ {
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
}
return;
}
if (!CSessionControl.RequestRight(sessionKey, EUserRights.EditAllProfiles) &&
CSessionControl.GetUserIdFromSession(sessionKey) != profile.ProfileId)
{
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
}
return; return;
} }
} }
@@ -143,28 +114,8 @@ namespace ServerLib
public SProfileData GetProfile(int profileId) public SProfileData GetProfile(int profileId)
{ {
Guid sessionKey = _GetSession(); Guid sessionKey = _GetSession();
if (_CheckRight(EUserRights.ViewOtherProfiles) || CSessionControl.GetUserIdFromSession(sessionKey) == profileId)
if (sessionKey == Guid.Empty)
{ {
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
}
return new SProfileData();
}
if (!CSessionControl.RequestRight(sessionKey, EUserRights.ViewOtherProfiles) &&
CSessionControl.GetUserIdFromSession(sessionKey) != profileId)
{
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
}
return new SProfileData();
}
if (CServer.GetProfileData == null) if (CServer.GetProfileData == null)
{ {
return new SProfileData(); return new SProfileData();
@@ -175,6 +126,11 @@ namespace ServerLib
return CServer.GetProfileData(profileId, isReadonly); return CServer.GetProfileData(profileId, isReadonly);
} }
else
{
return new SProfileData();
}
}
public SProfileData[] GetProfileList() public SProfileData[] GetProfileList()
{ {
@@ -191,29 +147,11 @@ namespace ServerLib
public void SendPhoto(SPhotoData photo) public void SendPhoto(SPhotoData photo)
{ {
Guid sessionKey = _GetSession(); if (_CheckRight(EUserRights.UploadPhotos))
if (sessionKey == Guid.Empty)
{ {
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
}
return;
}
if (!CSessionControl.RequestRight(sessionKey, EUserRights.UploadPhotos))
{
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
}
return;
}
CServer.SendPhoto(photo); CServer.SendPhoto(photo);
} }
}
#endregion #endregion
@@ -411,27 +349,11 @@ namespace ServerLib
public void SetUserRole(int profileId, int userRole) public void SetUserRole(int profileId, int userRole)
{ {
Guid sessionKey = _GetSession(); if (_CheckRight(EUserRights.EditAllProfiles))
if (sessionKey == Guid.Empty)
{ {
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
}
return;
}
if (!CSessionControl.RequestRight(sessionKey, EUserRights.EditAllProfiles))
{
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
}
return;
}
CServer.SetUserRole(profileId, userRole); CServer.SetUserRole(profileId, userRole);
} }
}
private static bool _CheckRight(EUserRights requestedRight) private static bool _CheckRight(EUserRights requestedRight)
{ {