Skip to content

Commit

Permalink
Use e_user.php for addon field. Add link to setup on /usersettings.php.
Browse files Browse the repository at this point in the history
  • Loading branch information
Moc committed Jan 19, 2021
1 parent b20ea1e commit e507bff
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 7 deletions.
67 changes: 67 additions & 0 deletions e_user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2014 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http:https://www.gnu.org/licenses/gpl.txt)
*
*/

if (!defined('e107_INIT')) { exit; }


class twofactorauth_user
{

function profile($udata) // display on user profile page.
{

}

/**
* The same field format as admin-ui, with the addition of 'fieldType', 'read', 'write', 'appliable' and 'required' as used in extended fields table.
*
* @return array
*/
function settings()
{
$fields = array();
$fields['secret_key'] = array(
'title' => LAN_PLUGIN_2FA_NAME_FULL,
'read' => e_UC_NOBODY,
'write' => e_UC_MEMBER,
'fieldType' => 'varchar(255)',
'type' => 'method',
'data' => 'str',
'required' => false,
);

return $fields;

}

function delete()
{

}

}

class twofactorauth_user_form extends e_form
{

public function user_plugin_twofactorauth_secret_key($curVal, $mode, $att = array())
{
$lan = LAN_2FA_USERSETTING_ENABLE;

if(e107::getUserExt()->get(USERID, "user_plugin_twofactorauth_secret_key"))
{
$lan = LAN_2FA_USERSETTING_DISABLE;
}

$url = e107::url('twofactorauth', 'setup');

return "<a href=".$url.">".$lan."</a>";
}
}
4 changes: 3 additions & 1 deletion languages/English/English_front.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@
define("LAN_2FA_DISABLE_INSTRUCTIONS", "To [b]disable[/b] Two Factor Authenthication for your account, please enter your 6-digit code to verify.");

define("LAN_2FA_ENABLED", "Two-factor authenthication has been succesfully [b]enabled[/b]");
define("LAN_2FA_DISABLED", "Two-factor authenthication has been succesfully [b]disabled[/b]");
define("LAN_2FA_DISABLED", "Two-factor authenthication has been succesfully [b]disabled[/b]");

define("LAN_2FA_RETURN_USERSETTINGS", "Return to settings");
7 changes: 6 additions & 1 deletion languages/English/English_global.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@

// plugin.xml
define("LAN_PLUGIN_2FA_NAME", "TwoFactorAuth");
define("LAN_PLUGIN_2FA_DIZ", "Plugin that adds Two-Factor Authentication (2FA) to e107");
define("LAN_PLUGIN_2FA_DIZ", "Plugin that adds Two-Factor Authentication (2FA) to e107");

// usersettings.php
define("LAN_PLUGIN_2FA_NAME_FULL", "Two Factor Authentication");
define("LAN_2FA_USERSETTING_ENABLE", "Enable Two Factor Authenthication");
define("LAN_2FA_USERSETTING_DISABLE", "Disable Two Factor Authenthication");
3 changes: 0 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,4 @@
<pref name="tfa_debug">0</pref>
<pref name="tfa_label"></pref>
</pluginPrefs>
<extendedFields>
<field name="secret_key" type='EUF_TEXT' default='' active="true" />
</extendedFields>
</e107Plugin>
5 changes: 3 additions & 2 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
require_once(HEADERF);

$text = "";
$usersettings_url = e107::getUrl()->create('user/myprofile/edit', array('id' => USERID));

// Check if 2FA is already enabled for current user
$tfaActivated = $tfa_class->tfaActivated(USERID) ? true : false;
Expand All @@ -55,7 +56,7 @@
if($tfa_class->processEnable(USERID, $secret_key, $totp))
{
e107::getMessage()->addSuccess(e107::getParser()->toHTML(LAN_2FA_ENABLED, true));
$text = "Go to homepage button?"; // TODO
$text = "<a class='btn btn-primary' href='".$usersettings_url."'>".LAN_2FA_RETURN_USERSETTINGS."</a>.";

e107::getRender()->tablerender($caption, e107::getMessage()->render().$text);
require_once(FOOTERF);
Expand All @@ -70,7 +71,7 @@
if($tfa_class->processDisable(USERID, $totp))
{
e107::getMessage()->addSuccess(e107::getParser()->toHTML(LAN_2FA_DISABLED, true));
$text = "Go to homepage button?"; // TODO
$text = "<a class='btn btn-primary' href='".$usersettings_url."'>".LAN_2FA_RETURN_USERSETTINGS."</a>.";

e107::getRender()->tablerender($caption, e107::getMessage()->render().$text);
require_once(FOOTERF);
Expand Down

0 comments on commit e507bff

Please sign in to comment.