This repository has been archived by the owner on Feb 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Accounts.go
99 lines (87 loc) · 3.25 KB
/
Accounts.go
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
func GetAccounts(request *APIRequest) *APIResponse {
return ValidateAndSelectAll(
request,
&[]Account{},
"SELECT Accounts.* FROM Accounts JOIN Users ON Users.ID = Accounts.UserID WHERE Users.ApiKey = :ApiKey",
[]string { "ApiKey" },
)
}
func AddAccount(request *APIRequest) *APIResponse {
return ValidateAndInsert(
request,
"INSERT INTO Accounts(UserID, Email, Password) VALUES((SELECT ID FROM Users WHERE ApiKey = :ApiKey), :Email, :Password)",
[]string { "ApiKey", "Email", "Password" },
)
}
func GetAccount(request *APIRequest) *APIResponse {
return ValidateAndSelectOne(
request,
&Account{},
"SELECT Accounts.* FROM Accounts JOIN Users ON Users.ID = Accounts.UserID WHERE Users.ApiKey = :ApiKey AND Accounts.ID = :ID",
[]string { "ApiKey", "ID" },
)
}
func UpdateAccount(request *APIRequest) *APIResponse {
return ValidateAndUpdateFromStruct(
request,
&Account{},
"Accounts",
"UPDATE Accounts JOIN Users ON Users.ID = Accounts.UserID SET",
" WHERE Users.ApiKey = :ApiKey AND Accounts.ID = :ID",
[]string { "ApiKey", "ID" },
"UserID",
)
}
func DeleteAccount(request *APIRequest) *APIResponse {
return ValidateAndDelete(
request,
`DELETE Accounts FROM Accounts JOIN Users ON Users.ID = Accounts.UserID WHERE Users.ApiKey = :ApiKey AND Accounts.ID = :ID`,
[]string { "ApiKey", "ID" },
)
}
func LockAccount(request *APIRequest) *APIResponse {
return ValidateAndUpdate(
request,
`UPDATE Accounts JOIN Users ON Users.ID = Accounts.UserID SET Locks = Locks + 1 WHERE Users.ApiKey = :ApiKey AND Accounts.ID = :ID`,
[]string { "ApiKey", "ID" },
)
}
func BanAccount(request *APIRequest) *APIResponse {
return ValidateAndUpdate(
request,
`UPDATE Accounts JOIN Users ON Users.ID = Accounts.UserID SET Banned = TRUE WHERE Users.ApiKey = :ApiKey AND Accounts.ID = :ID`,
[]string { "ApiKey", "ID" },
)
}
func GetResetPasswordStatus(request *APIRequest) *APIResponse {
return ValidateAndSelectOne(
request,
&PasswordResetRequest{},
`SELECT PasswordResetRequests.* FROM PasswordResetRequests JOIN Users ON Users.ID = PasswordResetRequests.UserID WHERE User.ApiKey = :ApiKey AND PasswordResetRequest.ID = :ID`,
[]string { "ApiKey", "ID" },
)
}
func ResetAccountPassword(request *APIRequest) *APIResponse {
request.ApiArguments["StartTime"] = Timestamp()
return ValidateAndInsert(
request,
`INSERT INTO PasswordResetRequests(UserID, AccountID, NewPassword, StartTime) VALUES((SELECT ID FROM Users WHERE ApiKey = :ApiKey), :ID, :NewPassword, :StartTime)`,
[]string { "ApiKey", "NewPassword", "ID" },
)
}
func GetCreateAccountStatus(request *APIRequest) *APIResponse {
return ValidateAndSelectOne(
request,
&AccountCreationRequest{},
`SELECT AccountCreationRequests.* FROM AccountCreationRequests JOIN Users ON Users.ID = AccountCreationRequests.UserID WHERE User.ApiKey = :ApiKey AND AccountCreationRequests.ID = :ID`,
[]string { "ApiKey", "ID" },
)
}
func CreateAccount(request *APIRequest) *APIResponse {
return ValidateAndInsert(
request,
`INSERT INTO AccountCreationRequests(UserID, Email, DisplayName, Password, Age, StartTime) VALUES((SELECT ID FROM Users WHERE ApiKey = :ApiKey), :Email, :DisplayName, :Password, :Age, :StartTime)`,
[]string { "ApiKey", "Email", "DisplayName", "Password", "Age" },
)
}