Skip to content
Snippets Groups Projects
Commit 90bfeea0 authored by Guillaume ROUSSE's avatar Guillaume ROUSSE
Browse files

let Rose::DB::Object handle dates

parent ce46c02d
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,7 @@ CREATE TABLE `authenticationtokens` ( ...@@ -11,7 +11,7 @@ CREATE TABLE `authenticationtokens` (
`token` varchar(50) NOT NULL, `token` varchar(50) NOT NULL,
`email_address` varchar(200) NOT NULL, `email_address` varchar(200) NOT NULL,
`sp_entityid` varchar(200) NOT NULL, `sp_entityid` varchar(200) NOT NULL,
`creation_date` int(11) DEFAULT NULL, `creation_date` date DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `token_2` (`token`), UNIQUE KEY `token_2` (`token`),
KEY `token` (`token`), KEY `token` (`token`),
...@@ -30,8 +30,8 @@ CREATE TABLE `serviceproviders` ( ...@@ -30,8 +30,8 @@ CREATE TABLE `serviceproviders` (
CREATE TABLE `testaccounts` ( CREATE TABLE `testaccounts` (
`id` bigint(20) NOT NULL AUTO_INCREMENT, `id` bigint(20) NOT NULL AUTO_INCREMENT,
`password_hash` varchar(50) NOT NULL, `password_hash` varchar(50) NOT NULL,
`creation_date` int(11) DEFAULT NULL, `creation_date` date DEFAULT NULL,
`expiration_date` int(11) DEFAULT NULL, `expiration_date` date DEFAULT NULL,
`profile` varchar(100) NOT NULL, `profile` varchar(100) NOT NULL,
`scope` varchar(100) NOT NULL, `scope` varchar(100) NOT NULL,
`sp_entityid` varchar(250) NOT NULL, `sp_entityid` varchar(250) NOT NULL,
......
...@@ -6,7 +6,7 @@ use warnings; ...@@ -6,7 +6,7 @@ use warnings;
use base 'IdPAccountManager::DB::Object'; use base 'IdPAccountManager::DB::Object';
use Digest::MD5; use Digest::MD5;
use POSIX qw(strftime); use DateTime;
__PACKAGE__->meta->setup( __PACKAGE__->meta->setup(
table => 'authenticationtokens', table => 'authenticationtokens',
...@@ -16,7 +16,7 @@ __PACKAGE__->meta->setup( ...@@ -16,7 +16,7 @@ __PACKAGE__->meta->setup(
token => { type => 'varchar', length => 50, not_null => 1 }, token => { type => 'varchar', length => 50, not_null => 1 },
email_address => { type => 'varchar', length => 200, not_null => 1 }, email_address => { type => 'varchar', length => 200, not_null => 1 },
sp_entityid => { type => 'varchar', length => 200, not_null => 1 }, sp_entityid => { type => 'varchar', length => 200, not_null => 1 },
creation_date => { type => 'integer' }, creation_date => { type => 'date' },
], ],
primary_key_columns => [ 'id' ], primary_key_columns => [ 'id' ],
...@@ -35,7 +35,7 @@ sub print { ...@@ -35,7 +35,7 @@ sub print {
"AuthenticationToken ID=%s; token=%s; email_address=%s; sp_entityid=%s; creation_date=%s\n", "AuthenticationToken ID=%s; token=%s; email_address=%s; sp_entityid=%s; creation_date=%s\n",
$self->id(), $self->token(), $self->email_address(), $self->id(), $self->token(), $self->email_address(),
$self->sp_entityid(), $self->sp_entityid(),
POSIX::strftime('%Y:%m:%d', localtime($self->creation_date())); $self->creation_date()->strftime('%Y:%m:%d');
} }
sub save { sub save {
...@@ -43,7 +43,7 @@ sub save { ...@@ -43,7 +43,7 @@ sub save {
# If no ID is defined, it is a new account # If no ID is defined, it is a new account
if (! defined $self->id()) { if (! defined $self->id()) {
$self->creation_date(time); $self->creation_date(DateTime->today());
$self->token(_generate_token($self->email_address())); $self->token(_generate_token($self->email_address()));
} }
......
...@@ -5,7 +5,7 @@ use warnings; ...@@ -5,7 +5,7 @@ use warnings;
use base 'IdPAccountManager::DB::Object'; use base 'IdPAccountManager::DB::Object';
use POSIX qw(strftime); use DateTime;
__PACKAGE__->meta->setup( __PACKAGE__->meta->setup(
table => 'testaccounts', table => 'testaccounts',
...@@ -13,8 +13,8 @@ __PACKAGE__->meta->setup( ...@@ -13,8 +13,8 @@ __PACKAGE__->meta->setup(
columns => [ columns => [
id => { type => 'bigserial', not_null => 1 }, id => { type => 'bigserial', not_null => 1 },
password_hash => { type => 'varchar', length => 50, not_null => 1 }, password_hash => { type => 'varchar', length => 50, not_null => 1 },
creation_date => { type => 'integer' }, creation_date => { type => 'date' },
expiration_date => { type => 'integer' }, expiration_date => { type => 'date' },
profile => { type => 'varchar', length => 100, not_null => 1 }, profile => { type => 'varchar', length => 100, not_null => 1 },
scope => { type => 'varchar', length => 100, not_null => 1 }, scope => { type => 'varchar', length => 100, not_null => 1 },
sp_entityid => { type => 'varchar', length => 250, not_null => 1 }, sp_entityid => { type => 'varchar', length => 250, not_null => 1 },
...@@ -121,8 +121,8 @@ sub print { ...@@ -121,8 +121,8 @@ sub print {
$self->sp_entityid(), $self->sp_entityid(),
$self->profile(), $self->profile(),
$self->scope(), $self->scope(),
POSIX::strftime('%Y:%m:%d', localtime($self->creation_date())), $self->creation_date()->strftime('%Y:%m:%d'),
POSIX::strftime('%Y:%m:%d', localtime($self->expiration_date())); $self->expiration_date()->strftime('%Y:%m:%d');
} }
sub password { sub password {
...@@ -140,9 +140,10 @@ sub save { ...@@ -140,9 +140,10 @@ sub save {
IdPAccountManager::Tools::generate_password(); IdPAccountManager::Tools::generate_password();
$self->password_hash( $self->password_hash(
IdPAccountManager::Tools::sha256_hash($self->{password})); IdPAccountManager::Tools::sha256_hash($self->{password}));
$self->creation_date(time); $self->creation_date(DateTime->today());
$self->expiration_date( $self->expiration_date(
time + ($args{accounts_validity_period} * 3600 * 24)); DateTime->today()->add(days => $args{accounts_validity_period})
);
} }
$self->SUPER::save(); $self->SUPER::save();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment