mirror of
https://github.com/SoDOff-Project/sodoff.git
synced 2025-10-11 08:18:49 -07:00
viking and user deletion (#19)
This commit is contained in:
parent
c3bb769934
commit
d5fb8ce5f1
@ -74,6 +74,8 @@ Then run School of Dragons.
|
|||||||
- GetChildList
|
- GetChildList
|
||||||
- GetUnselectedPetByTypes
|
- GetUnselectedPetByTypes
|
||||||
- UseInventory
|
- UseInventory
|
||||||
|
- DeleteProfile
|
||||||
|
- DeleteAccountNotification
|
||||||
|
|
||||||
#### Implemented enough (probably)
|
#### Implemented enough (probably)
|
||||||
- GetRules (doesn't return any rules, probably doesn't need to)
|
- GetRules (doesn't return any rules, probably doesn't need to)
|
||||||
|
@ -69,7 +69,9 @@ methods = [
|
|||||||
'GetUnselectedPetByTypes',
|
'GetUnselectedPetByTypes',
|
||||||
'GetUserGameCurrency',
|
'GetUserGameCurrency',
|
||||||
'SetAchievementByEntityIDs',
|
'SetAchievementByEntityIDs',
|
||||||
'UseInventory'
|
'UseInventory',
|
||||||
|
'DeleteProfile',
|
||||||
|
'DeleteAccountNotification'
|
||||||
]
|
]
|
||||||
|
|
||||||
def routable(path):
|
def routable(path):
|
||||||
|
@ -136,14 +136,19 @@ public class AuthenticationController : Controller {
|
|||||||
public IActionResult LoginChild([FromForm] string parentApiToken) {
|
public IActionResult LoginChild([FromForm] string parentApiToken) {
|
||||||
User? user = ctx.Sessions.FirstOrDefault(e => e.ApiToken == parentApiToken)?.User;
|
User? user = ctx.Sessions.FirstOrDefault(e => e.ApiToken == parentApiToken)?.User;
|
||||||
if (user is null) {
|
if (user is null) {
|
||||||
return Ok();
|
return Unauthorized();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the viking
|
// Find the viking
|
||||||
string? childUserID = Request.Form["childUserID"];
|
string? childUserID = Request.Form["childUserID"];
|
||||||
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Id == childUserID);
|
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Id == childUserID);
|
||||||
if (viking is null) {
|
if (viking is null) {
|
||||||
return Ok();
|
return Unauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if user is viking parent
|
||||||
|
if (user != viking.User) {
|
||||||
|
return Unauthorized();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create session
|
// Create session
|
||||||
@ -158,4 +163,18 @@ public class AuthenticationController : Controller {
|
|||||||
// Return back the api token
|
// Return back the api token
|
||||||
return Ok(session.ApiToken);
|
return Ok(session.ApiToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Produces("application/xml")]
|
||||||
|
[Route("AuthenticationWebService.asmx/DeleteAccountNotification")]
|
||||||
|
public IActionResult DeleteAccountNotification([FromForm] string apiToken) {
|
||||||
|
User? user = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken)?.User;
|
||||||
|
if (user is null)
|
||||||
|
return Ok(MembershipUserStatus.ValidationError);
|
||||||
|
|
||||||
|
ctx.Users.Remove(user);
|
||||||
|
ctx.SaveChanges();
|
||||||
|
|
||||||
|
return Ok(MembershipUserStatus.Success);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -913,12 +913,16 @@ public class ContentController : Controller {
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Produces("application/xml")]
|
[Produces("application/xml")]
|
||||||
[Route("ContentWebService.asmx/SetNextItemState")]
|
[Route("ContentWebService.asmx/SetNextItemState")]
|
||||||
public IActionResult SetNextItemState([FromForm] string setNextItemStateRequest) {
|
public IActionResult SetNextItemState([FromForm] string apiToken, [FromForm] string setNextItemStateRequest) {
|
||||||
SetNextItemStateRequest request = XmlUtil.DeserializeXml<SetNextItemStateRequest>(setNextItemStateRequest);
|
SetNextItemStateRequest request = XmlUtil.DeserializeXml<SetNextItemStateRequest>(setNextItemStateRequest);
|
||||||
RoomItem? item = ctx.RoomItems.FirstOrDefault(x => x.Id == request.UserItemPositionID);
|
RoomItem? item = ctx.RoomItems.FirstOrDefault(x => x.Id == request.UserItemPositionID);
|
||||||
if (item is null)
|
if (item is null)
|
||||||
return Ok();
|
return Ok();
|
||||||
|
|
||||||
|
Viking? viking = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken)?.Viking;
|
||||||
|
if (item.Room.Viking != viking)
|
||||||
|
return Unauthorized();
|
||||||
|
|
||||||
// NOTE: The game sets OverrideStateCriteria only if a speedup is used
|
// NOTE: The game sets OverrideStateCriteria only if a speedup is used
|
||||||
return Ok(roomService.NextItemState(item, request.OverrideStateCriteria));
|
return Ok(roomService.NextItemState(item, request.OverrideStateCriteria));
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,30 @@ public class RegistrationController : Controller {
|
|||||||
this.roomService = roomService;
|
this.roomService = roomService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Produces("application/xml")]
|
||||||
|
[Route("v3/RegistrationWebService.asmx/DeleteProfile")]
|
||||||
|
public IActionResult DeleteProfile([FromForm] string apiToken, [FromForm] string userID) {
|
||||||
|
User? user = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken)?.User;
|
||||||
|
if (user is null) {
|
||||||
|
return Ok(DeleteProfileStatus.OWNER_ID_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Id == userID);
|
||||||
|
if (viking is null) {
|
||||||
|
return Ok(DeleteProfileStatus.PROFILE_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user != viking.User) {
|
||||||
|
return Ok(DeleteProfileStatus.PROFILE_NOT_OWNED_BY_THIS_OWNER);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Vikings.Remove(viking);
|
||||||
|
ctx.SaveChanges();
|
||||||
|
|
||||||
|
return Ok(DeleteProfileStatus.SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Produces("application/xml")]
|
[Produces("application/xml")]
|
||||||
[Route("v3/RegistrationWebService.asmx/RegisterParent")]
|
[Route("v3/RegistrationWebService.asmx/RegisterParent")]
|
||||||
@ -93,6 +117,7 @@ public class RegistrationController : Controller {
|
|||||||
Name = data.ChildName,
|
Name = data.ChildName,
|
||||||
User = user,
|
User = user,
|
||||||
Inventory = inv,
|
Inventory = inv,
|
||||||
|
AchievementPoints = new List<AchievementPoints>(),
|
||||||
Rooms = new List<Room>()
|
Rooms = new List<Room>()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -28,11 +28,13 @@ public class DBContext : DbContext {
|
|||||||
protected override void OnModelCreating(ModelBuilder builder) {
|
protected override void OnModelCreating(ModelBuilder builder) {
|
||||||
builder.Entity<Session>().HasOne(s => s.User)
|
builder.Entity<Session>().HasOne(s => s.User)
|
||||||
.WithMany(e => e.Sessions)
|
.WithMany(e => e.Sessions)
|
||||||
.HasForeignKey(e => e.UserId);
|
.HasForeignKey(e => e.UserId)
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
builder.Entity<Session>().HasOne(s => s.Viking)
|
builder.Entity<Session>().HasOne(s => s.Viking)
|
||||||
.WithMany(e => e.Sessions)
|
.WithMany(e => e.Sessions)
|
||||||
.HasForeignKey(e => e.VikingId);
|
.HasForeignKey(e => e.VikingId)
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
builder.Entity<User>().HasMany(u => u.Sessions)
|
builder.Entity<User>().HasMany(u => u.Sessions)
|
||||||
.WithOne(e => e.User);
|
.WithOne(e => e.User);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user