[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[2583] trunk
- Subject: SF.net SVN: ledger-smb:[2583] trunk
- From: ..hidden..
- Date: Fri, 01 May 2009 05:02:44 +0000
Revision: 2583
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2583&view=rev
Author: einhverfr
Date: 2009-05-01 05:02:44 +0000 (Fri, 01 May 2009)
Log Message:
-----------
User password setting and saving preferences now works (on new codebase)
Modified Paths:
--------------
trunk/LedgerSMB/DBObject/Menu.pm
trunk/LedgerSMB/DBObject/User.pm
trunk/LedgerSMB/Form.pm
trunk/LedgerSMB.pm
trunk/UI/am-userconfig.html
trunk/UI/lib/ui-header.html
trunk/UI/login.js
trunk/scripts/menu.pl
trunk/sql/Pg-database.sql
trunk/sql/modules/admin.sql
Added Paths:
-----------
trunk/UI/users/
trunk/UI/users/preferences.html
trunk/scripts/user.pl
trunk/user.pl
Modified: trunk/LedgerSMB/DBObject/Menu.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Menu.pm 2009-04-30 19:28:10 UTC (rev 2582)
+++ trunk/LedgerSMB/DBObject/Menu.pm 2009-05-01 05:02:44 UTC (rev 2583)
@@ -66,7 +66,25 @@
return @{$self->{menu_items}};
}
+=over
+=item Menu::will_expire_soon($object)
+
+This method returns true if the user's password will expire soon
+(within the next week).
+
+=back
+
+=cut
+
+sub will_expire_soon {
+ my ($self) = @_;
+ my ($pw_expires) = $self->exec_method(
+ funcname => 'user__expires_soon');
+ $self->{expires_soon} = $pw_expires->{'user__expires_soon'};
+ return $self->{expires_soon};
+}
+
# Private method which contains logic common to the full menu and section logic
sub __generate {
@@ -88,3 +106,4 @@
}
}
}
+
Modified: trunk/LedgerSMB/DBObject/User.pm
===================================================================
--- trunk/LedgerSMB/DBObject/User.pm 2009-04-30 19:28:10 UTC (rev 2582)
+++ trunk/LedgerSMB/DBObject/User.pm 2009-05-01 05:02:44 UTC (rev 2583)
@@ -2,7 +2,101 @@
use base qw/LedgerSMB::DBObject/;
use Data::Dumper;
+use strict;
+=item LedgerSMB::User->country_codes();
+
+Returns a hash where the keys are registered locales and the values are the
+textual representation of the locale name.
+
+=cut
+
+sub country_codes {
+ use Locale::Country;
+ use Locale::Language;
+
+ my %cc = ();
+
+ # scan the locale directory and read in the LANGUAGE files
+ opendir DIR, "${LedgerSMB::Sysconfig::localepath}";
+
+ my @dir = grep !/^\..*$/, readdir DIR;
+
+ foreach my $dir (@dir) {
+ $dir = substr( $dir, 0, -3 );
+ $cc{$dir} = code2language( substr( $dir, 0, 2 ) );
+ $cc{$dir} .= ( "/" . code2country( substr( $dir, 3, 2 ) ) )
+ if length($dir) > 2;
+ $cc{$dir} .= ( " " . substr( $dir, 6 ) ) if length($dir) > 5;
+ }
+
+ closedir(DIR);
+
+ %cc;
+
+}
+
+sub save_preferences {
+ my ($self) = @_;
+ $self->exec_method(funcname => 'user__save_preferences');
+ $self->{dbh}->commit;
+ $self->get_user_info;
+}
+
+sub change_my_password {
+ my ($self) = @_;
+ if ($self->{new_password} ne $self->{confirm_password}){
+ $self->error($self->{_locale}->text('Passwords must match.'));
+ die;
+ }
+ $self->{password} = $self->{new_password};
+ $self->exec_method(funcname => 'user__change_password');
+ $self->{dbh}->commit;
+}
+
+
+sub get_option_data {
+ my $self = shift @_;
+ $self->{dateformats} = [];
+ $self->{numberformats} = [];
+ for my $opt (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)){
+ push @{$self->{dateformats}}, {format => $opt};
+ }
+ for my $opt (qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00)){
+ push @{$self->{numberformats}}, {format => $opt};
+ }
+
+ my %country_codes = country_codes();
+ $self->{country_codes};
+
+ foreach my $key ( sort { $country_codes{$a} cmp $country_codes{$b} }
+ keys %country_codes )
+ {
+ push @{$self->{country_codes}}, {
+ label => $country_codes{$key},
+ id => $key,
+ };
+ }
+
+ $self->{cssfiles} = [];
+ opendir CSS, "css/.";
+ for my $opt (grep /.*\.css$/, readdir CSS){
+ push @{$self->{cssfiles}}, {file => $opt};
+ }
+ closedir CSS;
+
+ $self->{printers} = [];
+
+ if ( %{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} ) {
+ foreach my $item ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
+ push @{$self->{printers}}, {printer => $item};
+ }
+ }
+ my ($pw_expiration) = $self->exec_method(
+ funcname => 'user__check_my_expiration');
+ $self->{password_expires} = $pw_expiration->{user__check_my_expiration};
+}
+
sub save {
my $self = shift @_;
Modified: trunk/LedgerSMB/Form.pm
===================================================================
--- trunk/LedgerSMB/Form.pm 2009-04-30 19:28:10 UTC (rev 2582)
+++ trunk/LedgerSMB/Form.pm 2009-05-01 05:02:44 UTC (rev 2583)
@@ -503,8 +503,8 @@
if ($self->{warn_expire}){
$headeradd .= qq|
<script type="text/javascript" language="JavaScript">
- document.alert('Warning: Your password will expire in $self->{pw_expires_in});
- </script>
+ window.alert('Warning: Your password will expire in $self->{pw_expires}');
+ </script>|;
}
print qq|Content-Type: text/html; charset=utf-8\n\n
@@ -1205,11 +1205,11 @@
push @{$self->{_roles}}, $roles[0];
}
- $sth->prepare('SELECT check_expiration()');
+ $sth = $dbh->prepare('SELECT check_expiration()');
$sth->execute;
($self->{warn_expire}) = $sth->fetchrow_array;
if ($self->{warn_expire}){
- $sth->prepare('SELECT user__check_my_expiration()');
+ $sth = $dbh->prepare('SELECT user__check_my_expiration()');
$sth->execute;
($self->{pw_expires}) = $sth->fetchrow_array;
}
Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm 2009-04-30 19:28:10 UTC (rev 2582)
+++ trunk/LedgerSMB.pm 2009-05-01 05:02:44 UTC (rev 2583)
@@ -218,6 +218,7 @@
$self->_db_init;
+
if ($self->is_run_mode('cgi', 'mod_perl')) {
#check for valid session unless this is an inital authentication
#request -- CT
@@ -226,8 +227,8 @@
$self->_get_password("Session Expired");
exit;
}
- $self->{_user} = LedgerSMB::User->fetch_config($self);
}
+ $self->get_user_info;
my %date_setting = (
'mm/dd/yy' => "SQL, US",
'mm-dd-yy' => "POSTGRES, US",
@@ -248,6 +249,10 @@
}
+sub get_user_info {
+ my ($self) = @_;
+ $self->{_user} = LedgerSMB::User->fetch_config($self);
+}
#This function needs to be moved into the session handler.
sub _get_password {
my ($self) = shift @_;
@@ -757,12 +762,12 @@
$self->error("Database is not the expected version. Was $dbversion, expected $self->{dbversion}");
}
- $sth->prepare('SELECT check_expiration()');
+ $sth = $dbh->prepare('SELECT check_expiration()');
$sth->execute;
($self->{warn_expire}) = $sth->fetchrow_array;
if ($self->{warn_expire}){
- $sth->prepare('SELECT user__check_my_expiration()');
+ $sth = $dbh->prepare('SELECT user__check_my_expiration()');
$sth->execute;
($self->{pw_expires}) = $sth->fetchrow_array;
}
Modified: trunk/UI/am-userconfig.html
===================================================================
--- trunk/UI/am-userconfig.html 2009-04-30 19:28:10 UTC (rev 2582)
+++ trunk/UI/am-userconfig.html 2009-05-01 05:02:44 UTC (rev 2583)
@@ -5,6 +5,8 @@
<table width="100%">
<tr><th class="listtop"><?lsmb form.title ?></th></tr>
+ <tr><th class="info">
+ <?lsmb text('Your password will expire in [_1]', password_expires) ?>
<tr>
<td>
<table width="100%">
@@ -12,38 +14,6 @@
<td>
<table>
<tr>
- <th align="right"><?lsmb text('Name') ?></th>
- <td><input name="name" size="20" value="<?lsmb user.name ?>" /></td>
- </tr>
- <tr>
- <th align="right"><?lsmb text('E-mail') ?></th>
- <td><input name="email" size="35" value="<?lsmb user.email ?>" /></td>
- </tr>
- <tr valign="top">
- <th align="right"><?lsmb text('Signature') ?></th>
- <td><textarea name="signature" rows="3" cols="35"><?lsmb user.signature ?></textarea></td>
- </tr>
- <tr>
- <th align="right"><?lsmb text('Phone') ?></th>
- <td><input name="tel" size="14" value="<?lsmb user.tel ?>" /></td>
- </tr>
- <tr>
- <th align="right"><?lsmb text('Fax') ?></th>
- <td><input name="fax" size="14" value="<?lsmb user.fax ?>" /></td>
- </tr>
- <tr>
- <th align="right"><?lsmb text('Company') ?></th>
- <td><input name="company" size="35" value="<?lsmb user.company ?>" /></td>
- </tr>
- <tr valign="top">
- <th align="right"><?lsmb text('Address') ?></th>
- <td><textarea name="address" rows="4" cols="35"><?lsmb user.address ?></textarea></td>
- </tr>
- </table>
- </td>
- <td>
- <table>
- <tr>
<th align="right"><?lsmb text('Password') ?></th>
<td><input type="password" name="new_password" size="10" value="<?lsmb user.password ?>" /></td>
</tr>
@@ -60,22 +30,10 @@
<td><?lsmb PROCESS select element_data=selects.numberformat ?></td>
</tr>
<tr>
- <th align="right"><?lsmb text('Dropdown Limit') ?></th>
- <td><input name="vclimit" size="10" value="<?lsmb user.vclimit ?>" /></td>
- </tr>
- <tr>
- <th align="right"><?lsmb text('Menu Width') ?></th>
- <td><input name="menuwidth" size="10" value="<?lsmb user.menuwidth ?>" /></td>
- </tr>
- <tr>
<th align="right"><?lsmb text('Language') ?></th>
<td><?lsmb PROCESS select element_data=selects.countrycode?></td>
</tr>
<tr>
- <th align="right"><?lsmb text('Session Timeout') ?></th>
- <td><input name="timeout" size="10" value="<?lsmb user.timeout ?>" /></td>
- </tr>
- <tr>
<th align="right"><?lsmb text('Stylesheet') ?></th>
<td><?lsmb PROCESS select element_data=selects.stylesheet?></td>
</tr>
Modified: trunk/UI/lib/ui-header.html
===================================================================
--- trunk/UI/lib/ui-header.html 2009-04-30 19:28:10 UTC (rev 2582)
+++ trunk/UI/lib/ui-header.html 2009-05-01 05:02:44 UTC (rev 2583)
@@ -24,7 +24,7 @@
<?lsmb IF warn_expire ?>
<script type="text/javascript" language="JavaScript">
- document.alert(<?lsmb text('Warning: Your password will expire in [_1]', pw_expires_in)?>);
+ window.alert('<?lsmb text('Warning: Your password will expire in [_1]', pw_expires)?>');
</script>
<?lsmb END ?>
Modified: trunk/UI/login.js
===================================================================
--- trunk/UI/login.js 2009-04-30 19:28:10 UTC (rev 2582)
+++ trunk/UI/login.js 2009-05-01 05:02:44 UTC (rev 2583)
@@ -22,7 +22,7 @@
return false;
}
document.location = document.login.action + "?action=login&company="+
- documnet.login.company.value;
+ document.login.company.value;
}
function check_auth() {
Copied: trunk/UI/users/preferences.html (from rev 2565, trunk/UI/am-userconfig.html)
===================================================================
--- trunk/UI/users/preferences.html (rev 0)
+++ trunk/UI/users/preferences.html 2009-05-01 05:02:44 UTC (rev 2583)
@@ -0,0 +1,98 @@
+<?lsmb INCLUDE 'ui-header.html' ?>
+<?lsmb PROCESS elements.html ?>
+<body>
+<form method="post" action="<?lsmb script ?>">
+
+<table width="100%">
+ <tr><th class="listtop"><?lsmb text('Preferences for [_1]', login) ?></th></tr>
+ <?lsmb IF action == 'save_preferences' ?> <tr><th class="info">
+ <?lsmb text('Preferences Saved') ?>
+ <tr><?lsmb END # if action ?>
+ <tr><th class="info">
+ <?lsmb text('Your password will expire in [_1]', password_expires) ?>
+ <tr>
+ <td>
+ <table width="100%">
+ <tr valign="top">
+ <td>
+ <table>
+ <tr>
+ <th align="right"><?lsmb text('Password') ?></th>
+ <td><input type="password" name="new_password" size="10" value="" /></td>
+ </tr>
+ <tr>
+ <th align="right"><?lsmb text('Confirm') ?></th>
+ <td><input type="password" name="confirm_password" size="10" /></td>
+ </tr>
+ <tr>
+ <th align="right"><?lsmb text('Date Format') ?></th>
+ <td><?lsmb PROCESS select element_data={
+ name = 'dateformat'
+ options = dateformats
+ default_values = [dateformat]
+ text_attr = 'format'
+ value_attr = 'id'
+ } ?></td>
+ </tr>
+ <tr>
+ <th align="right"><?lsmb text('Number Format') ?></th>
+ <td><?lsmb numberformat = user.numberformat -?>
+ <?lsmb PROCESS select element_data={
+ name = 'numberformat',
+ options = numberformats,
+ default_values = [numberformat],
+ text_attr = 'format',
+ value_attr = 'format',
+ } ?></td>
+ </tr>
+ <tr>
+ <th align="right"><?lsmb text('Language') ?></th>
+ <td><?lsmb language = user.language -?>
+ <?lsmb PROCESS select element_data={
+ name = 'language',
+ options = country_codes,
+ default_values = [language],
+ text_attr = 'label',
+ value_attr = 'id',
+ }?> </td>
+ </tr>
+ <tr>
+ <th align="right"><?lsmb text('Stylesheet') ?></th>
+ <td><?lsmb PROCESS select element_data={
+ name = 'css'
+ options = cssfiles
+ default_values = [stylesheet]
+ text_attr = 'file'
+ value_attr = 'file'
+ } ?></td>
+ </tr>
+<?lsmb IF printers.defined ?>
+ <tr>
+ <th align="right"><?lsmb text('Printer') ?></th>
+ <td><?lsmb printer = user.printer -?>
+ <?lsmb PROCESS select element_data={
+ name = 'printer'
+ options = printers
+ default_values = [printer]
+ text_attr = 'printer'
+ value_attr = 'printer'
+ }?></td>
+ </tr>
+<?lsmb END ?>
+
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><hr size="3" noshade="noshade" /></td>
+ </tr>
+</table>
+
+<button type="submit" class="submit" name="action" value="save_preferences"><?lsmb text('Save') ?></button>
+ </form>
+
+</body>
+</html>
Modified: trunk/scripts/menu.pl
===================================================================
--- trunk/scripts/menu.pl 2009-04-30 19:28:10 UTC (rev 2582)
+++ trunk/scripts/menu.pl 2009-05-01 05:02:44 UTC (rev 2583)
@@ -75,9 +75,15 @@
drilldown_menu($request);
return;
} else {
- $request->{main} = "splash.html" if $request->{main} eq 'company_logo';
- $request->{main} = "am.pl?action=recurring_transactions"
- if $request->{main} eq 'recurring_transactions';
+ my $userpw = LedgerSMB::DBObject::Menu->new({base => $request});
+ if ($userpw->will_expire_soon){
+ $request->{main} = 'user.pl?action=preference_screen';
+ } else {
+ $request->{main} = "splash.html"
+ if !$request->{main};
+ $request->{main} = "am.pl?action=recurring_transactions"
+ if $request->{main} eq 'recurring_transactions';
+ }
$template = LedgerSMB::Template->new(
user =>$request->{_user},
locale => $request->{_locale},
Added: trunk/scripts/user.pl
===================================================================
--- trunk/scripts/user.pl (rev 0)
+++ trunk/scripts/user.pl 2009-05-01 05:02:44 UTC (rev 2583)
@@ -0,0 +1,52 @@
+#=====================================================================
+# LedgerSMB
+# Small Medium Business Accounting software
+# http://www.ledgersmb.org/
+#
+#
+# Copyright (C) 2006
+
+use LedgerSMB;
+use LedgerSMB::Template;
+use LedgerSMB::DBObject::User;
+our $VERSION = 1.0;
+use strict;
+
+my $slash = "::";
+
+package LedgerSMB::Scripts::user;
+
+sub preference_screen {
+ my ($request) = @_;
+ my $user = LedgerSMB::DBObject::User->new({base => $request});
+ $user->get_option_data;
+
+ for my $format(@{$user->{dateformats}}){
+ $format->{id} = $format->{format};
+ $format->{id} =~ s/\//$slash/g;
+ }
+
+ $user->{dateformat} = $user->{_user}->{dateformat};
+ $user->{dateformat} =~ s/\//$slash/g;
+
+ my $template = LedgerSMB::Template->new(
+ user =>$request->{_user},
+ locale => $request->{_locale},
+ path => 'UI/users',
+ template => 'preferences',
+ format => 'HTML'
+ );
+ $user->{user} = $request->{_user};
+ $template->render($user);
+}
+
+sub save_preferences {
+ my ($request) = @_;
+ my $user = LedgerSMB::DBObject::User->new({base => $request});
+ $user->{dateformat} =~ s/$slash/\//g;
+ if ($user->{confirm_password}){
+ $user->change_my_password;
+ }
+ $user->save_preferences;
+ preference_screen($user);
+}
Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql 2009-04-30 19:28:10 UTC (rev 2582)
+++ trunk/sql/Pg-database.sql 2009-05-01 05:02:44 UTC (rev 2583)
@@ -2527,8 +2527,8 @@
189 format TEXT 525
190 action display_stylesheet 526
190 module am.pl 527
-191 module am.pl 528
-191 action config 529
+191 module user.pl 528
+191 action preference_screen 529
193 module login.pl 532
193 action logout 533
193 target _top 534
Modified: trunk/sql/modules/admin.sql
===================================================================
--- trunk/sql/modules/admin.sql 2009-04-30 19:28:10 UTC (rev 2582)
+++ trunk/sql/modules/admin.sql 2009-05-01 05:02:44 UTC (rev 2583)
@@ -280,6 +280,12 @@
end;
$$ language plpgsql security definer;
+CREATE OR REPLACE FUNCTION user__expires_soon()
+RETURNS BOOL AS
+$$
+ SELECT user__check_my_expiration() < '1 week';
+$$ language sql;
+
CREATE OR REPLACE FUNCTION user__change_password(in_new_password text)
returns int as
$$
@@ -287,7 +293,7 @@
t_expires timestamp;
BEGIN
SELECT now() + (value::numeric::text || ' days')::interval INTO t_expires
- FROM defaults WHERE setting_key = password_duration;
+ FROM defaults WHERE setting_key = 'password_duration';
UPDATE users SET notify_password = DEFAULT where username = SESSION_USER;
@@ -562,6 +568,26 @@
END;
$$ language plpgsql;
+create or replace function user__save_preferences(
+ in_dateformat text,
+ in_numberformat text,
+ in_language text,
+ in_stylesheet text,
+ in_printer text
+) returns bool as
+$$
+BEGIN
+ UPDATE user_preference
+ SET dateformat = in_dateformat,
+ numberformat = in_numberformat,
+ language = in_language,
+ stylesheet = in_stylesheet,
+ printer = in_printer
+ WHERE id = (select id from users where username = SESSION_USER);
+ RETURN FOUND;
+END;
+$$ language plpgsql;
+
create or replace function user__get_preferences (in_user int) returns setof user_preference as $$
declare
Copied: trunk/user.pl (from rev 2565, trunk/menu.pl)
===================================================================
--- trunk/user.pl (rev 0)
+++ trunk/user.pl 2009-05-01 05:02:44 UTC (rev 2583)
@@ -0,0 +1,3 @@
+#!/usr/bin/perl
+
+require "lsmb-request.pl";
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.