use utf8; package My::Mailserver::Schema::Result::VirtualUser; # Created by DBIx::Class::Schema::Loader # DO NOT MODIFY THE FIRST PART OF THIS FILE =head1 NAME My::Mailserver::Schema::Result::VirtualUser =cut use strict; use warnings; use base 'DBIx::Class::Core'; =head1 TABLE: C =cut __PACKAGE__->table("virtual_users"); =head1 ACCESSORS =head2 id data_type: 'integer' is_auto_increment: 1 is_nullable: 0 =head2 domain_id data_type: 'integer' is_foreign_key: 1 is_nullable: 0 =head2 password data_type: 'varchar' is_nullable: 0 size: 255 =head2 email data_type: 'varchar' is_nullable: 0 size: 255 =head2 recovery_email data_type: 'varchar' is_nullable: 1 size: 255 =head2 is_manager data_type: 'tinyint' default_value: 0 is_nullable: 1 =cut __PACKAGE__->add_columns( "id", { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, "domain_id", { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, "password", { data_type => "varchar", is_nullable => 0, size => 255 }, "email", { data_type => "varchar", is_nullable => 0, size => 255 }, "recovery_email", { data_type => "varchar", is_nullable => 1, size => 255 }, "is_manager", { data_type => "tinyint", default_value => 0, is_nullable => 1 }, ); =head1 PRIMARY KEY =over 4 =item * L =back =cut __PACKAGE__->set_primary_key("id"); =head1 UNIQUE CONSTRAINTS =head2 C =over 4 =item * L =back =cut __PACKAGE__->add_unique_constraint("email", ["email"]); =head1 RELATIONS =head2 domain Type: belongs_to Related object: L =cut __PACKAGE__->belongs_to( "domain", "My::Mailserver::Schema::Result::VirtualDomain", { id => "domain_id" }, { is_deferrable => 1, on_delete => "CASCADE", on_update => "RESTRICT" }, ); =head2 managers_domains Type: has_many Related object: L =cut __PACKAGE__->has_many( "managers_domains", "My::Mailserver::Schema::Result::ManagersDomain", { "foreign.manager_id" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 }, ); =head2 recovery_codes Type: has_many Related object: L =cut __PACKAGE__->has_many( "recovery_codes", "My::Mailserver::Schema::Result::RecoveryCode", { "foreign.user_id" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 }, ); =head2 domains Type: many_to_many Composing rels: L -> domain =cut __PACKAGE__->many_to_many("domains", "managers_domains", "domain"); # Created by DBIx::Class::Schema::Loader v0.07049 @ 2019-06-17 02:39:38 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:U24kyZS/j+9Gvs2gGlVBIw __PACKAGE__->load_components('PassphraseColumn'); __PACKAGE__->add_columns( '+password' => { passphrase => 'crypt', passphrase_class => 'BlowfishCrypt', passphrase_args => { salt_random => 1, cost => 8, }, passphrase_check_method => 'check_password', }, ); sub new_recovery_code { my $self = shift; my $code; my $max_tries = 10; while (1) { $code = eval { $self->create_related('recovery_codes', { code => _gen_code(), }); }; warn $max_tries; last if $code; last unless $max_tries; $max_tries--; } die "Error generating code" unless $code; return $code; } use String::Random; sub _gen_code { my $gen = String::Random->new; $gen->{'A'} = [@{$gen->{'C'}}, @{$gen->{'c'}}, @{$gen->{'n'}}]; return $gen->randpattern('A' x 64); } # You can replace this text with custom code or comments, and it will be preserved on regeneration 1;