This repository has been archived by the owner on Jul 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AUTH.cs
67 lines (62 loc) · 2.34 KB
/
AUTH.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.IO;
using System.Net;
namespace TrickeryAUTH
{
public class AUTH
{
private static string Parse(string source, string left, string right) => source.Split(new string[1] { left }, StringSplitOptions.None)[1].Split(new string[1] { right }, StringSplitOptions.None)[0];
private static DateTime UnixTimeStampToDateTime(double unixTimeStamp)
{
DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime();
return dtDateTime;
}
private static string AuthResponse = "";
public static bool Login(string AuthKey)
{
var request = (HttpWebRequest)WebRequest.Create("https://trickery.to/forum/tapi/index.php?users/me&oauth_token=" + AuthKey);
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
AuthResponse = responseString;
if (AuthResponse.Contains("user"))
return true;
return false;
}
public static string GetRawJSON(string AuthKey)
{
if (Login(AuthKey))
return AuthResponse;
else
return "Invalid Key";
}
public static string GetUsername(string AuthKey)
{
if (Login(AuthKey))
return Parse(AuthResponse, "\"username\": \"", "\",");
else
return "Invalid Key";
}
public static string GetUserID(string AuthKey)
{
if (Login(AuthKey))
return Parse(AuthResponse, "\"user_id\": ", ",");
else
return "Invalid Key";
}
public static string GetUserEmail(string AuthKey)
{
if (Login(AuthKey))
return Parse(AuthResponse, "\"user_email\": \"", "\",");
else
return "Invalid Key";
}
public static string GetRegistrationDate(string AuthKey)
{
if (Login(AuthKey))
return (UnixTimeStampToDateTime(double.Parse(Parse(AuthResponse, "\"user_register_date\": ", ",")))).ToString("dd/MM/yyyy");
else
return "Invalid Key";
}
}
}