Further refactoring

This commit is contained in:
Phyks 2014-08-30 23:39:41 +02:00
parent d465f2aab9
commit 337c3d81f0
6 changed files with 54 additions and 65 deletions

9
TODO
View File

@ -1,9 +0,0 @@
* Notifications by e-mail for users
Improvements :
==============
* User groups
* Search invoice
* JSON output => do index view
* API
* README file

View File

@ -29,7 +29,7 @@ class User extends Storage {
} }
public function getDisplayName() { public function getDisplayName() {
return $this->display_name; return (!empty($this->display_name) ? $this->display_name : $this->login);
} }
public function getId() { public function getId() {

View File

@ -228,7 +228,7 @@
exit(); exit();
} }
if(!empty($_POST['login']) && !empty($_POST['display_name']) && !empty($_POST['email']) && (!empty($_POST['password']) || !empty($_POST['user_id'])) && !empty($_POST['notifications']) && isset($_POST['admin'])) { if(!empty($_POST['login']) && (!empty($_POST['password']) || !empty($_POST['user_id'])) && !empty($_POST['notifications']) && isset($_POST['admin'])) {
if(check_token(600, 'edit_users')) { if(check_token(600, 'edit_users')) {
$user = new User(); $user = new User();
if(!empty($_POST['user_id'])) { if(!empty($_POST['user_id'])) {
@ -238,7 +238,7 @@
$user->newJsonToken(); $user->newJsonToken();
} }
$user->setLogin($_POST['login']); $user->setLogin($_POST['login']);
$user->setDisplayName($_POST['display_name']); $user->setDisplayName(!empty($_POST['display_name']) ? $_POST['display_name'] : '');
if(!empty($_POST['password'])) { if(!empty($_POST['password'])) {
$user->setPassword($user->encrypt($_POST['password'])); $user->setPassword($user->encrypt($_POST['password']));
} }
@ -413,7 +413,7 @@
break; break;
case 'settings': case 'settings':
if(!empty($_POST['mysql_host']) && !empty($_POST['mysql_login']) && !empty($_POST['mysql_db']) && !empty($_POST['currency']) && !empty($_POST['instance_title']) && !empty($_POST['base_url']) && !empty($_POST['timezone']) && !empty($_POST['email_webmaster']) && !empty($_POST['template'])) { if(!empty($_POST['mysql_host']) && !empty($_POST['mysql_login']) && !empty($_POST['mysql_password']) && !empty($_POST['mysql_db']) && !empty($_POST['instance_title']) && !empty($_POST['base_url']) && !empty($_POST['currency']) && !empty($_POST['timezone']) && !empty($_POST['template'])) {
if(check_token(600, 'settings')) { if(check_token(600, 'settings')) {
if(!is_writable('data/')) { if(!is_writable('data/')) {
$tpl>assign('error', $errors['write_error_data'][LANG]); $tpl>assign('error', $errors['write_error_data'][LANG]);
@ -478,9 +478,9 @@
$tpl->assign('timezone', @date_default_timezone_get()); $tpl->assign('timezone', @date_default_timezone_get());
$tpl->assign('show_settings', true); $tpl->assign('show_settings', true);
$tpl->assign('token', generate_token('settings')); $tpl->assign('token', generate_token('settings'));
$tpl->assign('templates', listTemplates('tpl/')); $tpl->assign('templates', secureDisplay(listTemplates('tpl/')));
$tpl->assign('current_template', trim(substr(TEMPLATE_DIR, 4), '/')); $tpl->assign('current_template', htmlspecialchars(trim(substr(TEMPLATE_DIR, 4), '/')));
$tpl->assign('lang', LANG); $tpl->assign('lang', htmlspecialchars(LANG));
$tpl->draw('settings'); $tpl->draw('settings');
break; break;

View File

@ -103,9 +103,6 @@
if(!empty($_POST['email_webmaster']) && !filter_var($_POST['email_webmaster'], FILTER_VALIDATE_EMAIL)) { if(!empty($_POST['email_webmaster']) && !filter_var($_POST['email_webmaster'], FILTER_VALIDATE_EMAIL)) {
$error = "Webmaster's email address is invalid."; $error = "Webmaster's email address is invalid.";
} }
else {
$email_webmaster = !empty($_POST['email_webmaster']) ? $_POST['email_webmaster'] : '';
}
if(empty($error)) { if(empty($error)) {
if(function_exists('mcrypt_create_iv')) { if(function_exists('mcrypt_create_iv')) {
@ -128,7 +125,7 @@
define('BASE_URL', '".$_POST['base_url']."'); define('BASE_URL', '".$_POST['base_url']."');
define('SALT', '".$salt."'); define('SALT', '".$salt."');
define('CURRENCY', '".$_POST['currency']."'); define('CURRENCY', '".$_POST['currency']."');
define('EMAIL_WEBMASTER', '".$email_webmaster."'); define('EMAIL_WEBMASTER', '".$_POST['email_webmaster']."');
define('TEMPLATE_DIR', 'tpl/".$_POST['template']."'); define('TEMPLATE_DIR', 'tpl/".$_POST['template']."');
define('LANG', '".$_POST['lang']."'); define('LANG', '".$_POST['lang']."');

View File

@ -32,10 +32,10 @@
<label for="login" class="label-block">Login: </label><input type="text" name="login" id="login" {if condition="$login_post != ''"} value="{$login_post}" {else} {$user_id != -1 ? 'value="'.$user_data->getLogin().'"' : ''} {/if}/> <label for="login" class="label-block">Login: </label><input type="text" name="login" id="login" {if condition="$login_post != ''"} value="{$login_post}" {else} {$user_id != -1 ? 'value="'.$user_data->getLogin().'"' : ''} {/if}/>
</p> </p>
<p> <p>
<label for="display_name" class="label-block">Displayed name : </label><input type="text" name="display_name" id="display_name" {if condition="$display_name_post != ''"} value="{$display_name_post}" {else} {$user_id != -1 ? 'value="'.$user_data->getDisplayName().'"' : ''} {/if}/> <label for="display_name" class="label-block">Displayed name (optionnal): </label><input type="text" name="display_name" id="display_name" {if condition="$display_name_post != ''"} value="{$display_name_post}" {else} {$user_id != -1 ? 'value="'.$user_data->getDisplayName().'"' : ''} {/if}/>
</p> </p>
<p> <p>
<label for="email" class="label-block">E-mail address : </label><input type="text" name="email" id="email" {if condition="$email_post != ''"} value="{$email_post}" {else} {$user_id != -1 ? 'value="'.$user_data->getEmail().'"' : ''} {/if}/> <label for="email" class="label-block">E-mail address (optionnal): </label><input type="text" name="email" id="email" {if condition="$email_post != ''"} value="{$email_post}" {else} {$user_id != -1 ? 'value="'.$user_data->getEmail().'"' : ''} {/if}/>
</p> </p>
<p> <p>
<label for="notifications" class="label-block">Notifications for </label> <label for="notifications" class="label-block">Notifications for </label>

View File

@ -55,7 +55,8 @@
{/loop} {/loop}
</select </select
</p> </p>
<p><label for="email_webmaster">Webmaster's email : </label><input type="text" name="email_webmaster" id="email_webmaster" value="{$email_webmaster}"/></p> <p><label for="lang">Lang: </label><select name="lang" id="lang">TODO</select></p>
<p><label for="email_webmaster">Webmaster's email (optionnal): </label><input type="text" name="email_webmaster" id="email_webmaster" value="{$email_webmaster}"/></p>
</fieldset> </fieldset>
<p class="center"><input type="submit" value="Update settings"><input type="hidden" name="token" value="{$token}"/></p> <p class="center"><input type="submit" value="Update settings"><input type="hidden" name="token" value="{$token}"/></p>
</form> </form>