Skip to content
Snippets Groups Projects
Token.pm 1.20 KiB
package AccountManager::Token;

use strict;
use warnings;

use base 'AccountManager::DB::Object';

use Rose::DB::Object::Manager;

__PACKAGE__->meta->setup(
    table   => 'tokens',

    columns => [
        id              => { type => 'bigserial', not_null => 1 },
        secret          => { type => 'varchar', length => 50, not_null => 1 },
        email_address   => { type => 'varchar', length => 200, not_null => 1 },
        entityid        => { type => 'varchar', length => 200, not_null => 1 },
        creation_date   => { type => 'datetime' },
        expiration_date => { type => 'datetime' },
    ],

    primary_key_columns => [ 'id' ],

    unique_keys => [
        [ 'secret' ],
        [ 'email_address', 'entityid' ],
    ],
);

Rose::DB::Object::Manager->make_manager_methods('tokens');

sub print {
    my ($self, $fd) = @_;
    $fd = \*STDOUT unless $fd;

    printf $fd
        "Token ID=%s; secret=%s; email_address=%s; entityid=%s; creation_date=%s; expiration_date=%s\n",
        $self->id(),
        $self->secret(),
        $self->email_address(),
        $self->entityid(),
        $self->creation_date()->strftime('%Y:%m:%d %H:%M'),
        $self->expiration_date()->strftime('%Y:%m:%d %H:%M');
}

1;