Implement admin endpoints
This commit is contained in:
1 parent
4628cacc0b
commit
24a04e8c02
11 files changed
+307
-127
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -27,10 +27,10 @@ namespace OpenSaveCloudClient.Core
|
||||
private ServerInformation? serverInformation;
|
||||
private User? connectedUser;
|
||||
|
||||
private LogManager logManager;
|
||||
private TaskManager taskManager;
|
||||
private Configuration configuration;
|
||||
private SaveManager saveManager;
|
||||
private readonly LogManager logManager;
|
||||
private readonly TaskManager taskManager;
|
||||
private readonly Configuration configuration;
|
||||
private readonly SaveManager saveManager;
|
||||
|
||||
|
||||
public string? Host { get { return host; } }
|
||||
@@ -65,10 +65,6 @@ namespace OpenSaveCloudClient.Core
|
||||
public void BindNewServer(string host, int port)
|
||||
{
|
||||
Logout();
|
||||
if (!host.StartsWith("http://") && !host.StartsWith("https://"))
|
||||
{
|
||||
host = "http://" + host;
|
||||
}
|
||||
logManager.AddInformation(String.Format("Binding server {0}:{1}", host, port));
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
@@ -86,7 +82,7 @@ namespace OpenSaveCloudClient.Core
|
||||
string uuidTask = taskManager.StartTask("Login to the server", true, 1);
|
||||
try
|
||||
{
|
||||
HttpClient client = new HttpClient();
|
||||
using HttpClient client = new();
|
||||
string json = JsonSerializer.Serialize(new Credential { Username = username, Password = password });
|
||||
HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
HttpResponseMessage response = client.PostAsync(string.Format("{0}:{1}/api/v1/login", host, port), content).Result;
|
||||
@@ -130,7 +126,7 @@ namespace OpenSaveCloudClient.Core
|
||||
if (ReloadFromConfiguration())
|
||||
{
|
||||
uuidTask = taskManager.StartTask("Login to the server", true, 1);
|
||||
HttpClient client = new HttpClient();
|
||||
using HttpClient client = new();
|
||||
string json = JsonSerializer.Serialize(new AccessToken { Token = token });
|
||||
HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
HttpResponseMessage response = client.PostAsync(string.Format("{0}:{1}/api/v1/check/token", host, port), content).Result;
|
||||
@@ -194,7 +190,7 @@ namespace OpenSaveCloudClient.Core
|
||||
string uuidTask = taskManager.StartTask("Creating game to server database", true, 1);
|
||||
try
|
||||
{
|
||||
HttpClient client = new HttpClient();
|
||||
using HttpClient client = new();
|
||||
string json = JsonSerializer.Serialize(new NewGameInfo { Name = name });
|
||||
HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
@@ -358,22 +354,20 @@ namespace OpenSaveCloudClient.Core
|
||||
string uuidTask = taskManager.StartTask("Getting game information", true, 1);
|
||||
try
|
||||
{
|
||||
using (HttpClient client = new HttpClient())
|
||||
using HttpClient client = new();
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
HttpResponseMessage response = client.GetAsync(string.Format("{0}:{1}/api/v1/game/info/{2}", host, port, gameId)).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
HttpResponseMessage response = client.GetAsync(string.Format("{0}:{1}/api/v1/game/info/{2}", host, port, gameId)).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string responseText = response.Content.ReadAsStringAsync().Result;
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return JsonSerializer.Deserialize<Game>(responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
}
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
string responseText = response.Content.ReadAsStringAsync().Result;
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return JsonSerializer.Deserialize<Game>(responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
}
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -394,22 +388,20 @@ namespace OpenSaveCloudClient.Core
|
||||
string uuidTask = taskManager.StartTask("Getting game information", true, 1);
|
||||
try
|
||||
{
|
||||
using (HttpClient client = new HttpClient())
|
||||
using HttpClient client = new();
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
HttpResponseMessage response = client.GetAsync(string.Format("{0}:{1}/api/v1/game/all", host, port)).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
HttpResponseMessage response = client.GetAsync(string.Format("{0}:{1}/api/v1/game/all", host, port)).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string responseText = response.Content.ReadAsStringAsync().Result;
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return JsonSerializer.Deserialize<List<Game>>(responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
}
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
string responseText = response.Content.ReadAsStringAsync().Result;
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return JsonSerializer.Deserialize<List<Game>>(responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
}
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -437,23 +429,21 @@ namespace OpenSaveCloudClient.Core
|
||||
fileStreamContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
|
||||
multipartFormContent.Add(fileStreamContent, name: "file", fileName: "file.bin");
|
||||
|
||||
using (HttpClient client = new HttpClient())
|
||||
using HttpClient client = new();
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
client.DefaultRequestHeaders.Add("X-Upload-Key", uploadToken);
|
||||
client.DefaultRequestHeaders.Add("X-Game-Save-Hash", newHash);
|
||||
HttpResponseMessage response = client.PostAsync(string.Format("{0}:{1}/api/v1/game/upload", host, port), multipartFormContent).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
client.DefaultRequestHeaders.Add("X-Upload-Key", uploadToken);
|
||||
client.DefaultRequestHeaders.Add("X-Game-Save-Hash", newHash);
|
||||
HttpResponseMessage response = client.PostAsync(string.Format("{0}:{1}/api/v1/game/upload", host, port), multipartFormContent).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
}
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
}
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -479,30 +469,28 @@ namespace OpenSaveCloudClient.Core
|
||||
string uuidTask = taskManager.StartTask("Downloading", true, 1);
|
||||
try
|
||||
{
|
||||
using (HttpClient client = new HttpClient())
|
||||
using HttpClient client = new();
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
client.DefaultRequestHeaders.Add("X-Upload-Key", uploadToken);
|
||||
HttpResponseMessage response = client.GetAsync(string.Format("{0}:{1}/api/v1/game/download", host, port)).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
client.DefaultRequestHeaders.Add("X-Upload-Key", uploadToken);
|
||||
HttpResponseMessage response = client.GetAsync(string.Format("{0}:{1}/api/v1/game/download", host, port)).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
using (var fs = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
using (var fs = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
await response.Content.CopyToAsync(fs);
|
||||
}
|
||||
if (Directory.Exists(unzipPath))
|
||||
{
|
||||
Directory.Delete(unzipPath, true);
|
||||
}
|
||||
ZipFile.ExtractToDirectory(filePath, unzipPath);
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return true;
|
||||
await response.Content.CopyToAsync(fs);
|
||||
}
|
||||
else
|
||||
if (Directory.Exists(unzipPath))
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
Directory.Delete(unzipPath, true);
|
||||
}
|
||||
ZipFile.ExtractToDirectory(filePath, unzipPath);
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -519,22 +507,20 @@ namespace OpenSaveCloudClient.Core
|
||||
string uuidTask = taskManager.StartTask("Getting user information", true, 1);
|
||||
try
|
||||
{
|
||||
using (HttpClient client = new HttpClient())
|
||||
using HttpClient client = new();
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
HttpResponseMessage response = client.GetAsync(string.Format("{0}:{1}/api/v1/user/information", host, port)).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
HttpResponseMessage response = client.GetAsync(string.Format("{0}:{1}/api/v1/user/information", host, port)).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string responseText = response.Content.ReadAsStringAsync().Result;
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return JsonSerializer.Deserialize<User>(responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
}
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
string responseText = response.Content.ReadAsStringAsync().Result;
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return JsonSerializer.Deserialize<User>(responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
}
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -550,22 +536,140 @@ namespace OpenSaveCloudClient.Core
|
||||
string uuidTask = taskManager.StartTask("Getting users list", true, 1);
|
||||
try
|
||||
{
|
||||
using (HttpClient client = new HttpClient())
|
||||
using HttpClient client = new();
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
HttpResponseMessage response = client.GetAsync(string.Format("{0}:{1}/api/v1/admin/users", host, port)).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
HttpResponseMessage response = client.GetAsync(string.Format("{0}:{1}/api/v1/system/users", host, port)).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string responseText = response.Content.ReadAsStringAsync().Result;
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return JsonSerializer.Deserialize<List<User>>(responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
}
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
string responseText = response.Content.ReadAsStringAsync().Result;
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return JsonSerializer.Deserialize<List<User>>(responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
}
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logManager.AddError(ex);
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public User? CreateUser(Registration registration)
|
||||
{
|
||||
logManager.AddInformation("Creation of the new user");
|
||||
string uuidTask = taskManager.StartTask("Registration of the user", true, 1);
|
||||
try
|
||||
{
|
||||
HttpClient client = new();
|
||||
string json = JsonSerializer.Serialize(registration);
|
||||
HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
HttpResponseMessage response = client.PostAsync(string.Format("{0}:{1}/api/v1/admin/user", host, port), content).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
logManager.AddInformation("Password changed");
|
||||
string responseText = response.Content.ReadAsStringAsync().Result;
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return JsonSerializer.Deserialize<User>(responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
}
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logManager.AddError(ex);
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public User? GetUser(long userId)
|
||||
{
|
||||
logManager.AddInformation("Getting user information from the server database");
|
||||
string uuidTask = taskManager.StartTask("Getting user information", true, 1);
|
||||
try
|
||||
{
|
||||
using HttpClient client = new();
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
HttpResponseMessage response = client.GetAsync(string.Format("{0}:{1}/api/v1/admin/user/{2}", host, port, userId)).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string responseText = response.Content.ReadAsStringAsync().Result;
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return JsonSerializer.Deserialize<User>(responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
}
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logManager.AddError(ex);
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public User? SetUserAdmin(long userId, bool setAdmin)
|
||||
{
|
||||
logManager.AddInformation("Getting user information from the server database");
|
||||
string uuidTask = taskManager.StartTask("Getting user information", true, 1);
|
||||
string role = setAdmin ? "admin" : "user";
|
||||
try
|
||||
{
|
||||
using HttpClient client = new();
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
HttpResponseMessage response = client.GetAsync(string.Format("{0}:{1}/api/v1/admin/user/role/{2}/{3}", host, port, role, userId)).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string responseText = response.Content.ReadAsStringAsync().Result;
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return JsonSerializer.Deserialize<User>(responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
}
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logManager.AddError(ex);
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public User? DeleteUser(long userId)
|
||||
{
|
||||
logManager.AddInformation("Delete a user and all his datas");
|
||||
string uuidTask = taskManager.StartTask("Deleting user", true, 1);
|
||||
try
|
||||
{
|
||||
using HttpClient client = new();
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
HttpResponseMessage response = client.DeleteAsync(string.Format("{0}:{1}/api/v1/admin/user/{2}", host, port, userId)).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string responseText = response.Content.ReadAsStringAsync().Result;
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return JsonSerializer.Deserialize<User>(responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
}
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -581,7 +685,7 @@ namespace OpenSaveCloudClient.Core
|
||||
string uuidTask = taskManager.StartTask("Changing password", true, 1);
|
||||
try
|
||||
{
|
||||
HttpClient client = new HttpClient();
|
||||
HttpClient client = new();
|
||||
string json = JsonSerializer.Serialize(password);
|
||||
HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
@@ -607,6 +711,38 @@ namespace OpenSaveCloudClient.Core
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool ChangePassword(int userId, NewPassword password)
|
||||
{
|
||||
logManager.AddInformation(string.Format("Changing password of user {0}", userId));
|
||||
string uuidTask = taskManager.StartTask("Changing password", true, 1);
|
||||
try
|
||||
{
|
||||
HttpClient client = new();
|
||||
string json = JsonSerializer.Serialize(password);
|
||||
HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
HttpResponseMessage response = client.PostAsync(string.Format("{0}:{1}/api/v1/admin/user/passwd/{2}", host, port, userId), content).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
logManager.AddInformation("Password changed");
|
||||
string responseText = response.Content.ReadAsStringAsync().Result;
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
}
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logManager.AddError(ex);
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// method <c>UpdateCache</c> update the GameSave object with the server data
|
||||
/// </summary>
|
||||
@@ -640,25 +776,23 @@ namespace OpenSaveCloudClient.Core
|
||||
string uuidTask = taskManager.StartTask("Locking game", true, 1);
|
||||
try
|
||||
{
|
||||
using (HttpClient client = new HttpClient())
|
||||
using HttpClient client = new();
|
||||
string json = JsonSerializer.Serialize(new UploadGameInfo { GameId = gameId });
|
||||
HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
HttpResponseMessage response = client.PostAsync(string.Format("{0}:{1}/api/v1/game/upload/init", host, port), content).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string json = JsonSerializer.Serialize(new UploadGameInfo { GameId = gameId });
|
||||
HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
|
||||
HttpResponseMessage response = client.PostAsync(string.Format("{0}:{1}/api/v1/game/upload/init", host, port), content).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
logManager.AddInformation("Game locked");
|
||||
string responseText = response.Content.ReadAsStringAsync().Result;
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return JsonSerializer.Deserialize<GameUploadToken>(responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
}
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
logManager.AddInformation("Game locked");
|
||||
string responseText = response.Content.ReadAsStringAsync().Result;
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return JsonSerializer.Deserialize<GameUploadToken>(responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
|
||||
}
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace OpenSaveCloudClient
|
||||
private void ShowLoginForm()
|
||||
{
|
||||
Enabled = false;
|
||||
LoginForm loginForm = new LoginForm();
|
||||
LoginForm loginForm = new();
|
||||
loginForm.FormClosed += LoginForm_Close;
|
||||
loginForm.Show();
|
||||
}
|
||||
|
||||
+20
-5
@@ -40,6 +40,7 @@
|
||||
this.PortNumericBox = new System.Windows.Forms.NumericUpDown();
|
||||
this.LoginButton = new System.Windows.Forms.Button();
|
||||
this.AboutButton = new System.Windows.Forms.PictureBox();
|
||||
this.sslCheckBox = new System.Windows.Forms.CheckBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.PortNumericBox)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.AboutButton)).BeginInit();
|
||||
@@ -58,10 +59,10 @@
|
||||
//
|
||||
// ServerTextBox
|
||||
//
|
||||
this.ServerTextBox.Location = new System.Drawing.Point(297, 192);
|
||||
this.ServerTextBox.Location = new System.Drawing.Point(297, 187);
|
||||
this.ServerTextBox.Name = "ServerTextBox";
|
||||
this.ServerTextBox.PlaceholderText = "myserver.com";
|
||||
this.ServerTextBox.Size = new System.Drawing.Size(412, 31);
|
||||
this.ServerTextBox.Size = new System.Drawing.Size(311, 31);
|
||||
this.ServerTextBox.TabIndex = 1;
|
||||
//
|
||||
// UsernameTextBox
|
||||
@@ -75,7 +76,7 @@
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.ForeColor = System.Drawing.SystemColors.ControlText;
|
||||
this.label1.Location = new System.Drawing.Point(297, 166);
|
||||
this.label1.Location = new System.Drawing.Point(297, 161);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(61, 25);
|
||||
this.label1.TabIndex = 0;
|
||||
@@ -113,7 +114,7 @@
|
||||
//
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.ForeColor = System.Drawing.SystemColors.ControlText;
|
||||
this.label4.Location = new System.Drawing.Point(716, 166);
|
||||
this.label4.Location = new System.Drawing.Point(615, 161);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(44, 25);
|
||||
this.label4.TabIndex = 0;
|
||||
@@ -122,7 +123,7 @@
|
||||
// PortNumericBox
|
||||
//
|
||||
this.PortNumericBox.InterceptArrowKeys = false;
|
||||
this.PortNumericBox.Location = new System.Drawing.Point(716, 192);
|
||||
this.PortNumericBox.Location = new System.Drawing.Point(615, 187);
|
||||
this.PortNumericBox.Maximum = new decimal(new int[] {
|
||||
65535,
|
||||
0,
|
||||
@@ -164,12 +165,25 @@
|
||||
this.AboutButton.TabStop = false;
|
||||
this.AboutButton.Click += new System.EventHandler(this.AboutButton_Click);
|
||||
//
|
||||
// sslCheckBox
|
||||
//
|
||||
this.sslCheckBox.AutoSize = true;
|
||||
this.sslCheckBox.Checked = true;
|
||||
this.sslCheckBox.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||
this.sslCheckBox.Location = new System.Drawing.Point(743, 189);
|
||||
this.sslCheckBox.Name = "sslCheckBox";
|
||||
this.sslCheckBox.Size = new System.Drawing.Size(100, 29);
|
||||
this.sslCheckBox.TabIndex = 7;
|
||||
this.sslCheckBox.Text = "Use SSL";
|
||||
this.sslCheckBox.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// LoginForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(144F, 144F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
|
||||
this.BackColor = System.Drawing.SystemColors.Window;
|
||||
this.ClientSize = new System.Drawing.Size(1112, 447);
|
||||
this.Controls.Add(this.sslCheckBox);
|
||||
this.Controls.Add(this.AboutButton);
|
||||
this.Controls.Add(this.LoginButton);
|
||||
this.Controls.Add(this.PortNumericBox);
|
||||
@@ -212,5 +226,6 @@
|
||||
private NumericUpDown PortNumericBox;
|
||||
private Button LoginButton;
|
||||
private PictureBox AboutButton;
|
||||
private CheckBox sslCheckBox;
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,20 @@ namespace OpenSaveCloudClient
|
||||
try
|
||||
{
|
||||
decimal port = PortNumericBox.Value;
|
||||
serverConnector.BindNewServer(ServerTextBox.Text, (int)port);
|
||||
string host = ServerTextBox.Text;
|
||||
if (host.StartsWith("https://"))
|
||||
{
|
||||
sslCheckBox.Checked = true;
|
||||
}
|
||||
else if (host.StartsWith("http://"))
|
||||
{
|
||||
sslCheckBox.Checked = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
host = (sslCheckBox.Checked ? "https://" : "http://") + host;
|
||||
}
|
||||
serverConnector.BindNewServer(host, (int)port);
|
||||
if (serverConnector.Bind)
|
||||
{
|
||||
serverConnector.Login(UsernameTextBox.Text, PasswordTextBox.Text);
|
||||
@@ -86,6 +99,7 @@ namespace OpenSaveCloudClient
|
||||
UsernameTextBox.Enabled = value;
|
||||
PasswordTextBox.Enabled = value;
|
||||
LoginButton.Enabled = value;
|
||||
sslCheckBox.Enabled = value;
|
||||
}
|
||||
|
||||
private void AboutButton_Click(object sender, EventArgs e)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenSaveCloudClient.Models.Remote
|
||||
{
|
||||
public class Registration
|
||||
{
|
||||
[JsonPropertyName("username")]
|
||||
public string Username { get; set; }
|
||||
[JsonPropertyName("password")]
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user