API now checks user credentials before granting tokens.
Added new permission - 'api' that allows the group access to using the API.
This commit is contained in:
parent
839ce793c7
commit
17683eaeaa
2 changed files with 23 additions and 0 deletions
|
|
@ -23,6 +23,22 @@ namespace TShockAPI
|
|||
var user = verbs["username"];
|
||||
var pass = verbs["password"];
|
||||
|
||||
var userAccount = TShock.Users.GetUserByName(user);
|
||||
if (userAccount == null)
|
||||
{
|
||||
return new Dictionary<string, string> { { "status", "401" }, { "error", "Invalid username/password combination provided. Please re-submit your query with a correct pair." } };
|
||||
}
|
||||
|
||||
if (Tools.HashPassword(pass).ToUpper() != userAccount.Password.ToUpper())
|
||||
{
|
||||
return new Dictionary<string, string> { { "status", "401" }, { "error", "Invalid username/password combination provided. Please re-submit your query with a correct pair." } };
|
||||
}
|
||||
|
||||
if (!Tools.GetGroup(userAccount.Group).HasPermission("api") && userAccount.Group != "superadmin")
|
||||
{
|
||||
return new Dictionary<string, string> { { "status", "403" }, { "error", "Although your account was successfully found and identified, your account lacks the permission required to use the API. (api)"} };
|
||||
}
|
||||
|
||||
if (Verify != null && !Verify(user, pass))
|
||||
return new Dictionary<string, string> { { "status", "401" } , { "error", "Invalid username/password combination provided. Please re-submit your query with a correct pair." } };
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue