-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The purpose of this is twofold: * Allow players to navigate their main/multi accounts without having to log in and out. * Synchronize things between the two accounts when it doesn't make sense to have two values (i.e. e-mail address, user preferences, bans, etc.). Add a new table `account_link_login`, which associates a `login_id` (the new primary key replacing `account_id` in the `account` table) with an `account_id` (the primary key of `account_link_login`). Each "login" (`account`) can be associated with multiple "accounts" (`account_link_login`). This is a little confusing, since ideally the `account` table would be renamed `login` (or similar), but we are probably a bit too heavily invested in the original infrastructure to completely change it now. We provide a way on the "Play Game" page to switch to/create multis, including an option to link an existing account as a multi. Adds two helper methods to SmrAccount: * getLinkedAccountList - finds all accounts associated with login * getLinkedAccount - returns an account if it is associated with login
- Loading branch information
Showing
10 changed files
with
210 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- Rename `account.account_id` to `account.login_id` | ||
ALTER TABLE account CHANGE `account_id` `login_id` smallint(6) unsigned NOT NULL AUTO_INCREMENT; | ||
|
||
-- Add `account_link_login` table | ||
CREATE TABLE account_link_login ( | ||
`account_id` smallint(6) unsigned NOT NULL AUTO_INCREMENT, | ||
`login_id` smallint(6) unsigned NOT NULL, | ||
PRIMARY KEY (`account_id`) | ||
) ENGINE=MyISAM AUTO_INCREMENT=1; | ||
|
||
-- Fill in `account_link_login` from the rows of `account`, | ||
-- setting account_id = login_id. | ||
INSERT INTO account_link_login (account_id, login_id) | ||
SELECT login_id, login_id as account_id FROM account; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
$template->assign('PageTopic', 'Create Multi Account'); | ||
|
||
$container = create_container('switch_account_create_processing.php'); | ||
$container['action'] = 'Create'; | ||
$template->assign('CreateHREF', SmrSession::getNewHREF($container)); | ||
$container['action'] = 'Link'; | ||
$template->assign('LinkHREF', SmrSession::getNewHREF($container)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
if (count($account->getLinkedAccountList()) >= SmrAccount::MAX_LINKED_ACCOUNTS) { | ||
create_error('Cannot create another linked account!'); | ||
} | ||
|
||
if ($var['action'] == 'Create') { | ||
// Create a new multi account | ||
$db->query('INSERT INTO account_link_login (login_id) VALUES ('.$account->getLoginID().')'); | ||
$newAccountID = $db->getInsertID(); | ||
|
||
$container = create_container('skeleton.php', 'game_play.php'); | ||
$container['switch_account_id'] = $newAccountID; | ||
|
||
} elseif ($var['action'] == 'Link') { | ||
$login = $_REQUEST['multi_account_login']; | ||
$password = $_REQUEST['multi_account_password']; | ||
|
||
// Link an existing multi account | ||
$db->query('SELECT login_id FROM account ' . | ||
'WHERE login = '.$db->escapeString($login).' AND ' . | ||
'password = '.$db->escapeString(md5($password)).' LIMIT 1'); | ||
if (!$db->nextRecord()) { | ||
create_error('Could not find a matching account. If you believe this is an error, please contact an admin.'); | ||
} | ||
$multiLoginID = $db->getInt('login_id'); | ||
|
||
// Sanity check: multi ID > current ID | ||
if ($multiLoginID <= $account->getLoginID()) { | ||
create_error('Multi account must be newer than main account!'); | ||
} | ||
|
||
// update the account_link_login to reflect the new login association | ||
// For existing accounts login_id == account_id | ||
$db->query('UPDATE account_link_login SET login_id='.$db->escapeNumber($account->getLoginID()).' WHERE account_id='.$db->escapeNumber($multiLoginID)); | ||
|
||
// delete the old login | ||
$db->query('DELETE FROM account WHERE login_id='.$db->escapeNumber($multiLoginID)); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
templates/Default/engine/Default/switch_account_create.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<h2>Create New Multi Account</h2> | ||
<p>All players are allowed a second ("multi") account in addition to their | ||
primary ("main") account. It is created only through this interface, so | ||
<b>DO NOT</b> create a second login!</p> | ||
|
||
<p>There are very specific rules about how you can use you multi account. | ||
<a href='https://wiki.smrealms.de/rules' target="_blank" style='font-weight:bold;'>Click HERE</a> for more information.</p> | ||
|
||
<p>If you have an existing multi account, please link it below instead of | ||
creating a new one.</p> | ||
|
||
<div class="buttonA"> | ||
<a class="buttonA" href="<?php echo $CreateHREF; ?>">Create Multi</a> | ||
</div> | ||
<br /><br /><br /> | ||
|
||
<h2>Link Existing Multi Account</h2> | ||
|
||
<p>If you are logged in on an existing multi account, <b>DO NOT CONTINUE</b>. | ||
Instead, please log into your main account and link your multi account from | ||
there.</p> | ||
|
||
<p><span class="bold red">WARNING</span>: When you do this, your multi login | ||
will be deleted. This action cannot be undone! However, your multi account | ||
data will then be associated as the multi of the account you are currently | ||
logged in as.</p> | ||
|
||
<p>If you are at all unsure how to procede, please contact an admin for | ||
assistance.</p> | ||
|
||
<form id="LinkOldAccountForm" method="POST" action="<?php echo $LinkHREF; ?>"> | ||
<table> | ||
<tr> | ||
<th colspan="2">Enter Existing Account Credentials</th> | ||
</tr> | ||
<tr> | ||
<td>Login:</td> | ||
<td><input type="text" name="multi_account_login"/></td> | ||
</tr> | ||
<tr> | ||
<td>Password:</td> | ||
<td><input type="password" name="multi_account_password"/></td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td><input type="submit" name="action" value="Link Account" id="InputFields" /></td> | ||
</tr> | ||
</table> | ||
</form> |