Skip to content

Commit 1c19a2c

Browse files
committed
now mostly working
1 parent fd3c367 commit 1c19a2c

File tree

11 files changed

+81
-49
lines changed

11 files changed

+81
-49
lines changed

admin/add.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
$module = Modules::initModulePage("admin");
1010
$L = $module->getLangStrings();
1111
$LANG = Core::$L;
12+
$root_url = Core::getRootUrl();
1213

1314
// get a list of forms that already have a submission account configured. These are omitted from the
1415
// list of available forms
@@ -22,7 +23,12 @@
2223

2324
$page_vars = array(
2425
"omit_forms" => $omit_forms,
25-
"js_messages" => array("phrase_please_select", "phrase_please_select_form", "word_delete")
26+
"js_messages" => array(
27+
"phrase_please_select", "phrase_please_select_form", "word_delete"
28+
),
29+
"js_files" => array(
30+
"$root_url/modules/submission_accounts/scripts/manage_submission_account.js"
31+
)
2632
);
2733

2834
$page_vars["head_js"] = <<< END

code/Users.class.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ public static function login($info, $L)
111111
$db->query("
112112
SELECT *
113113
FROM {PREFIX}form_{$form_id}
114-
WHERE $username_col = :value
114+
WHERE $username_col = :username
115115
");
116-
$db->bind("value", $info["username"]);
116+
$db->bind("username", $info["username"]);
117117
$db->execute();
118118
$submissions = $db->fetchAll();
119119

120120
// since there may be multiple users with the same username (we're relying on the administrator to enforce it, we'll
121121
// assume they've been a little lapse in their duties...), loop through all results found and log them in under the
122-
// FIRST user that matches the exact username-password combo
122+
// FIRST user that matches the exact username-password combo.
123123
$account_found = false;
124124
$submission_info = array();
125125
foreach ($submissions as $submission) {
@@ -186,15 +186,24 @@ public static function login($info, $L)
186186
// now figure out what View the user's supposed to see
187187
$view_id = self::getSubmissionView($form_id, $submission_id);
188188

189+
$settings = Settings::get();
190+
189191
Sessions::clearAll();
190192
Sessions::set("account", array(
191193
"is_logged_in" => true,
194+
195+
// the secret sauce to allow the User->checkAuth method to accept this user. The whole auth is in need of refactoring.
196+
"account_id" => "user",
197+
"account_type" => "user",
198+
192199
"theme" => $submission_account["theme"],
193200
"swatch" => $submission_account["swatch"],
201+
"ui_language" => "en_us", // always in English right now
202+
"timezone_offset" => $settings["default_timezone_offset"],
194203
"form_id" => $form_id,
195204
"view_id" => $view_id,
196205
"submission_id" => $submission_info["submission_id"],
197-
"settings" => Settings::get()
206+
"settings" => $settings
198207
));
199208

200209
$menu_template_info = self::cacheAccountMenu($form_id);
@@ -221,7 +230,7 @@ public static function cacheAccountMenu($form_id)
221230
{
222231
$root_url = Core::getRootUrl();
223232

224-
$menu_info = self::getFormMenu($form_id);
233+
$menu_info = Admin::getFormMenu($form_id);
225234

226235
$menu_template_info = array();
227236
for ($i = 0; $i < count($menu_info); $i++) {

forget_password.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
require_once("../../global/library.php");
44

55
use FormTools\Administrator;
6+
use FormTools\General;
67
use FormTools\Modules;
78
use FormTools\Settings;
89
use FormTools\Modules\SubmissionAccounts\Admin;
10+
use FormTools\Modules\SubmissionAccounts\Users;
911

1012
$module = Modules::initModulePage();
1113

@@ -24,6 +26,7 @@
2426
// now, if there's a form ID available (e.g. passed to the page via GET or POST), see if the form has been
2527
// configured with submission accounts and if so, use the theme associated with the form
2628
$form_id = Modules::loadModuleField("submission_accounts", "form_id", "form_id", "");
29+
2730
$submission_account = array();
2831
if (!empty($form_id)) {
2932
$submission_account = Admin::getSubmissionAccount($form_id);
@@ -46,24 +49,30 @@
4649
}
4750

4851
// if trying to send password
52+
$success = true;
53+
$message = "";
4954
if (isset($_POST["send_password"])) {
50-
list($g_success, $g_message) = sa_send_password($form_id, $_POST);
55+
list($success, $message) = Users::sendPassword($form_id, $_POST, $L);
5156
}
5257

5358
$admin_info = Administrator::getAdminInfo();
5459
$admin_email = $admin_info["email"];
5560

5661
$replacements = array("site_admin_email" => "<a href=\"mailto:$admin_email\">$admin_email</a>");
5762

58-
$page_vars = array();
59-
$page_vars["text_forgot_password"] = ft_eval_smarty_string($L["text_forgot_password"], $replacements);
60-
$page_vars["error"] = $error;
61-
$page_vars["submission_account"] = $submission_account;
62-
$page_vars["main_error"] = $main_error; // an error SO BAD it prevents the login form from appearing
63-
$page_vars["module_settings"] = $module_settings;
63+
$page_vars = array(
64+
"g_success" => $success,
65+
"g_message" => $message,
66+
"text_forgot_password" => General::evalSmartyString($L["text_forgot_password"], $replacements),
67+
"error" => $error,
68+
"submission_account" => $submission_account,
69+
"main_error" => $main_error, // an error SO BAD it prevents the login form from appearing
70+
"module_settings" => $module_settings
71+
);
72+
6473
$page_vars["head_js"] = <<< END
6574
var rules = [];
6675
rules.push("required,email,{$L["validation_no_email"]}");
6776
END;
6877

69-
ft_display_module_page("templates/forget_password.tpl", $page_vars, $g_theme, $g_swatch);
78+
$module->displayPage("templates/forget_password.tpl", $page_vars, $g_theme, $g_swatch);

lang/en_us.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
$L["notify_submission_account_updated"] = "The submission account has been updated for this form.";
5353
$L["notify_menu_updated"] = "The menu has been updated.";
5454
$L["notify_settings_updated"] = "The settings have been updated.";
55-
$L["notify_login_no_form_id"] = "Sorry, there has been no form ID passed to this page. In order to display the login form, a <b>form_id</b> value must to be passed to this page via POST or GET. Please see the <a href=\"http://modules.formtools.org/submission_accounts/?page=logging_in\">user documentation</a>.";
55+
$L["notify_login_no_form_id"] = "Sorry, there has been no form ID passed to this page. In order to display the login form, a <b>form_id</b> value must to be passed to this page via POST or GET. Please see the <a href=\"https://docs.formtools.org/modules/submission_accounts/logging_in/\">user documentation</a>.";
5656
$L["notify_submission_account_inactive"] = "Sorry, user accounts are currently inactive for this form.";
5757
$L["notify_submission_account_data_deleted"] = "The user login data has been cleared.";
5858
$L["notify_problem_installing"] = "There following error occurred when trying to create the database tables for this module: <b>{\$error}</b>";

login.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
require_once("../../global/library.php");
44

5+
use FormTools\Core;
56
use FormTools\Modules;
67
use FormTools\Settings;
78
use FormTools\Modules\SubmissionAccounts\Admin;
9+
use FormTools\Modules\SubmissionAccounts\Users;
810

911
$module = Modules::initModulePage();
12+
$module_settings = $module->getSettings();
13+
$L = $module->getLangStrings();
1014

1115
$main_error = false;
1216
$error = "";
1317

14-
$module_settings = $module->getSettings();
15-
$L = $module->getLangStrings();
16-
1718
// get the default settings
1819
$settings = Settings::get();
1920
$g_theme = $settings["default_theme"];
@@ -25,6 +26,7 @@
2526
$submission_account = array();
2627
if (!empty($form_id)) {
2728
$submission_account = Admin::getSubmissionAccount($form_id);
29+
2830
if (isset($submission_account["form_id"]) && $submission_account["submission_account_is_active"] == "yes") {
2931
$g_theme = $submission_account["theme"];
3032
$g_swatch = $submission_account["swatch"];
@@ -45,17 +47,20 @@
4547
$username = "";
4648
if (isset($_POST["login"])) {
4749
$_POST["form_id"] = $form_id;
48-
$username = ft_strip_tags($_POST["username"]);
49-
$error = sa_login($_POST);
50+
$username = strip_tags($_POST["username"]);
51+
$error = Users::login($_POST, $L);
5052
}
5153

5254
$page_vars = array(
5355
"error" => $error,
5456
"username" => $username,
5557
"submission_account" => $submission_account,
5658
"main_error" => $main_error, // an error SO BAD it prevents the login form from appearing
57-
"module_settings" => $module_settings,
58-
"head_js" => "$(function() { document.login.username.focus(); });"
59+
"module_settings" => $module_settings
5960
);
6061

62+
// Urgh. Should be refactored along with User Roles
63+
Core::$user->setTheme($g_theme);
64+
Core::$user->setSwatch($g_swatch);
65+
6166
$module->displayPage("templates/login.tpl", $page_vars, $g_theme, $g_swatch);

logout.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
<?php
22

3-
session_start();
4-
header("Cache-control: private");
53
require("../../global/library.php");
64

7-
$form_id = "";
8-
if (isset($_SESSION["ft"]["account"]["form_id"]))
9-
$form_id = $_SESSION["ft"]["account"]["form_id"];
5+
use FormTools\Core;
6+
use FormTools\Modules;
7+
use FormTools\Sessions;
108

11-
$module_settings = ft_get_module_settings("", "submission_accounts");
9+
$module = Modules::initModulePage();
10+
$root_url = Core::getRootUrl();
11+
12+
$form_id = Sessions::getWithFallback("account.form_id", "");
13+
14+
$module_settings = $module->getSettings();
1215
$logout_location = $module_settings["logout_location"];
13-
if ($logout_location == "custom_url" || empty($logout_location))
14-
{
15-
$logout_url = $module_settings["logout_url"];
16-
}
17-
else
18-
{
19-
$logout_url = "$g_root_url/modules/submission_accounts/login.php";
20-
if (!empty($form_id))
21-
$logout_url .= "?form_id=" . $form_id;
16+
if ($logout_location == "custom_url" || empty($logout_location)) {
17+
$logout_url = $module_settings["logout_url"];
18+
} else {
19+
$logout_url = "$root_url/modules/submission_accounts/login.php";
20+
if (!empty($form_id)) {
21+
$logout_url .= "?form_id=" . $form_id;
22+
}
2223
}
2324

2425
// empty sessions
25-
$_SESSION["ft"] = array();
26+
Sessions::clearAll();
2627

2728
// redirect to login page
28-
header("location: $logout_url");
29+
header("location: $logout_url");

templates/admin/help.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</table>
1515

1616
<p>
17-
For help on how to use this module, please see the <a href="http://modules.formtools.org/submission_accounts/">module help documentation</a>.
17+
For help on how to use this module, please see the <a href="https://docs.formtools.org/modules/submission_accounts/">module help documentation</a>.
1818
</p>
1919

2020
{ft_include file='modules_footer.tpl'}

templates/forget_password.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
{$text_forgot_password}
1414
</div>
1515

16-
<form name="forget_password" action="{$same_page}{$g_query_params}" method="post"
16+
<form name="forget_password" action="{$same_page}" method="post"
1717
onsubmit="return rsv.validate(this, rules)">
1818

1919
<div class="login_panel margin_bottom_large">
2020
<div class="login_panel_inner">
2121
<table cellpadding="0" cellspacing="1">
2222
<tr>
2323
<td class="login_table_text">{$LANG.word_email}</td>
24-
<td><input type="textbox" size="25" name="email" value="{$email}"></td>
24+
<td><input type="textbox" size="25" name="email" value=""></td>
2525
<td align="center"><input type="submit" name="send_password" value="{$LANG.word_email|upper}" /></td>
2626
</tr>
2727
</table>

templates/login.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
</div>
2929
{/if}
3030

31-
<form name="login" action="{$same_page}{$query_params}" method="post">
31+
<form name="login" action="{$same_page}" method="post">
3232
<div class="login_panel margin_bottom_large">
3333
<div class="login_panel_inner">
3434
<table cellpadding="0" cellspacing="1">
3535
<tr>
3636
<td>{$module_settings.username_field_label}</td>
37-
<td><input type="text" name="username" value="{$username}" /></td>
37+
<td><input type="text" name="username" value="{$username}" autofocus /></td>
3838
</tr>
3939
<tr>
4040
<td>{$module_settings.password_field_label}</td>

templates/users/index.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
{/if}
3636

3737
{foreach from=$fields item=curr_field}
38-
{assign var=field_id value=$field.field_id}
38+
{assign var=field_id value=$curr_field.field_id}
3939
<tr>
4040
<td width="150" class="pad_left_small" valign="top">{$curr_field.field_title} <span class="req">{if $curr_field.is_required}*{/if}</span></td>
4141
<td valign="top">
@@ -72,4 +72,4 @@
7272
{template_hook location="submission_accounts_modules_edit_submission_bottom"}
7373
</div>
7474

75-
{ft_include file='footer.tpl'}
75+
{ft_include file='footer.tpl'}

0 commit comments

Comments
 (0)