MyRedland/lib/MyRedland/Luser.pm

89 lines
1.2 KiB
Perl

package MyRedland::Luser;
use v5.34.1;
use strict;
use warnings;
use Moo;
use Types::Standard qw/Maybe Str Bool InstanceOf/;
use Crypt::Bcrypt qw/bcrypt bcrypt_check/;
has uuid => (
is => 'ro',
isa => Str,
required => 0,
);
has username => (
is => 'ro',
isa => Str,
required => 1,
);
has email => (
is => 'rw',
isa => Str,
required => 1,
);
has verified => (
is => 'rw',
isa => Bool,
required => 1,
);
has password => (
is => 'rw',
isa => Str,
required => 1,
);
has mail_verification_payload => (
is => 'rw',
isa => Str,
required => 0,
);
has mail_verification_expiration => (
is => 'rw',
isa => InstanceOf['DateTime'],
required => 0,
);
has creation_date => (
is => 'ro',
isa => InstanceOf['DateTime']
);
has last_access => (
is => 'rw',
isa => InstanceOf['DateTime'],
);
has avatar => (
is => 'rw',
isa => Str,
);
has stripe_customer_id => (
is => 'rw',
isa => Maybe[Str],
);
sub check_password {
my $self = shift;
my $password = shift;
if (!defined $password) {
warn "Password not defined";
return;
}
if (!length $password) {
# Not accepting empty passwords.
return;
}
return bcrypt_check($password, $self->password);
}
1;