mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
feature: mail confirmed reward
Suggested by @EPuncker
This commit is contained in:
parent
c318d3a9de
commit
43c197316a
2
.gitignore
vendored
2
.gitignore
vendored
@ -53,6 +53,8 @@ plugins/*
|
||||
!plugins/example.json
|
||||
!plugins/account-create-hint.json
|
||||
!plugins/account-create-hint
|
||||
!plugins/email-confirmed-reward.json
|
||||
!plugins/email-confirmed-reward
|
||||
landing
|
||||
|
||||
# others/rest
|
||||
|
@ -93,7 +93,14 @@ $config = array(
|
||||
'account_management' => true, // disable if you're using other method to manage users (fe. tfs account manager)
|
||||
'account_create_auto_login' => false, // auto login after creating account?
|
||||
'account_create_character_create' => true, // allow directly to create character on create account page?
|
||||
'account_mail_verify' => false, // force users to confirm their email addresses when registering account
|
||||
'account_mail_verify' => false, // force users to confirm their email addresses when registering
|
||||
'account_mail_confirmed_reward' => [ // reward users for confirming their E-Mails
|
||||
// account_mail_verify needs to be enabled too
|
||||
'premium_days' => 0,
|
||||
'premium_points' => 0,
|
||||
'coins' => 0,
|
||||
'message' => 'You received %d %s for confirming your E-Mail address.' // example: You received 20 premium points for confirming your E-Mail address.
|
||||
],
|
||||
'account_mail_unique' => true, // email addresses cannot be duplicated? (one account = one email)
|
||||
'account_premium_days' => 0, // default premium days on new account
|
||||
'account_premium_points' => 0, // default premium points on new account
|
||||
|
17
plugins/email-confirmed-reward.json
Normal file
17
plugins/email-confirmed-reward.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "EMail Confirmed Reward",
|
||||
"description": "Reward users for confirming their E-Mail.",
|
||||
"version": "1.0",
|
||||
"author": "MyAAC Authors",
|
||||
"contact": "www.my-aac.org",
|
||||
"hooks": {
|
||||
"mail-confirmed-reward": {
|
||||
"type": "EMAIL_CONFIRMED",
|
||||
"file": "plugins/email-confirmed-reward/reward.php"
|
||||
}
|
||||
},
|
||||
"uninstall": [
|
||||
"plugins/email-confirmed-reward.json",
|
||||
"plugins/email-confirmed-reward"
|
||||
]
|
||||
}
|
33
plugins/email-confirmed-reward/reward.php
Normal file
33
plugins/email-confirmed-reward/reward.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
|
||||
$reward = config('account_mail_confirmed_reward');
|
||||
|
||||
$hasCoinsColumn = $db->hasColumn('accounts', 'coins');
|
||||
if ($reward['coins'] > 0 && $hasCoinsColumn) {
|
||||
log_append('email_confirm_error.log', 'accounts.coins column does not exist.');
|
||||
}
|
||||
|
||||
if (!isset($account) || !$account->isLoaded()) {
|
||||
log_append('email_confirm_error.log', 'Account not loaded.');
|
||||
return;
|
||||
}
|
||||
|
||||
if ($reward['premium_points'] > 0) {
|
||||
$account->setCustomField('premium_points', (int)$account->getCustomField('premium_points') + $reward['premium_points']);
|
||||
|
||||
success(sprintf($reward['message'], $reward['premium_points'], 'premium points'));
|
||||
}
|
||||
|
||||
if ($reward['coins'] > 0 && $hasCoinsColumn) {
|
||||
$account->setCustomField('coins', (int)$account->getCustomField('coins') + $reward['coins']);
|
||||
|
||||
success(sprintf($reward['message'], $reward['coins'], 'coins'));
|
||||
}
|
||||
|
||||
if ($reward['premium_days'] > 0) {
|
||||
$account->setPremDays($account->getPremDays() + $reward['premium_days']);
|
||||
$account->save();
|
||||
|
||||
success(sprintf($reward['message'], $reward['premium_days'], 'premium days'));
|
||||
}
|
@ -43,8 +43,9 @@ define('HOOK_ACCOUNT_CREATE_AFTER_TOWNS', 31);
|
||||
define('HOOK_ACCOUNT_CREATE_BEFORE_SUBMIT_BUTTON', 32);
|
||||
define('HOOK_ACCOUNT_CREATE_AFTER_FORM', 33);
|
||||
define('HOOK_ACCOUNT_CREATE_AFTER_SUBMIT', 34);
|
||||
define('HOOK_EMAIL_CONFIRMED', 35);
|
||||
define('HOOK_FIRST', HOOK_STARTUP);
|
||||
define('HOOK_LAST', HOOK_ACCOUNT_CREATE_AFTER_SUBMIT);
|
||||
define('HOOK_LAST', HOOK_EMAIL_CONFIRMED);
|
||||
|
||||
require_once LIBS . 'plugins.php';
|
||||
class Hook
|
||||
|
@ -23,6 +23,16 @@ if(!$res->rowCount()) {
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = $db->query('SELECT id FROM accounts WHERE email_hash = ' . $db->quote($hash) . ' AND email_verified = 0');
|
||||
if ($query->rowCount() == 1) {
|
||||
$query = $query->fetch(PDO::FETCH_ASSOC);
|
||||
$account = new OTS_Account();
|
||||
$account->load($query['id']);
|
||||
if ($account->isLoaded()) {
|
||||
$hooks->trigger(HOOK_EMAIL_CONFIRMED, ['account' => $account]);
|
||||
}
|
||||
}
|
||||
|
||||
$db->update('accounts', array('email_verified' => '1'), array('email_hash' => $hash));
|
||||
success('You have now verified your e-mail, this will increase the security of your account. Thank you for doing this.');
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user