add: purchased accounts
This commit is contained in:
parent
0aa2ea362f
commit
2ec8d86edf
22 changed files with 1279 additions and 124 deletions
|
@ -20,8 +20,8 @@ impl DataManager {
|
|||
}
|
||||
}
|
||||
|
||||
auto_method!(get_invite_code_by_id()@get_invite_code_from_row -> "SELECT * FROM invite_codes WHERE id = $1" --name="invite_code" --returns=InviteCode --cache-key-tmpl="atto.invite_code:{}");
|
||||
auto_method!(get_invite_code_by_code(&str)@get_invite_code_from_row -> "SELECT * FROM invite_codes WHERE code = $1" --name="invite_code" --returns=InviteCode);
|
||||
auto_method!(get_invite_code_by_id()@get_invite_code_from_row -> "SELECT * FROM invite_codes WHERE id = $1" --name="invite code" --returns=InviteCode --cache-key-tmpl="atto.invite_code:{}");
|
||||
auto_method!(get_invite_code_by_code(&str)@get_invite_code_from_row -> "SELECT * FROM invite_codes WHERE code = $1" --name="invite code" --returns=InviteCode);
|
||||
|
||||
/// Get invite_codes by `owner`.
|
||||
pub async fn get_invite_codes_by_owner(
|
||||
|
@ -96,23 +96,22 @@ impl DataManager {
|
|||
|
||||
const MAXIMUM_FREE_INVITE_CODES: usize = 4;
|
||||
const MAXIMUM_SUPPORTER_INVITE_CODES: usize = 48;
|
||||
const MINIMUM_ACCOUNT_AGE_FOR_FREE_INVITE_CODES: usize = 2_629_800_000; // 1mo
|
||||
const MINIMUM_ACCOUNT_AGE_FOR_INVITE_CODES: usize = 2_629_800_000; // 1mo
|
||||
|
||||
/// Create a new invite_code in the database.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `data` - a mock [`InviteCode`] object to insert
|
||||
pub async fn create_invite_code(&self, data: InviteCode, user: &User) -> Result<InviteCode> {
|
||||
if !user.permissions.check(FinePermission::SUPPORTER) {
|
||||
// check account creation date
|
||||
if unix_epoch_timestamp() - user.created
|
||||
< Self::MINIMUM_ACCOUNT_AGE_FOR_FREE_INVITE_CODES
|
||||
{
|
||||
return Err(Error::MiscError(
|
||||
"Your account is too young to do this".to_string(),
|
||||
));
|
||||
}
|
||||
// check account creation date
|
||||
if unix_epoch_timestamp() - user.created < Self::MINIMUM_ACCOUNT_AGE_FOR_INVITE_CODES {
|
||||
return Err(Error::MiscError(
|
||||
"Your account is too young to do this".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
// ...
|
||||
if !user.permissions.check(FinePermission::SUPPORTER) {
|
||||
// our account is old enough, but we need to make sure we don't already have
|
||||
// 2 invite codes
|
||||
if (self.get_invite_codes_by_owner_count(user.id).await? as usize)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue