Skip to content
Snippets Groups Projects
Select Git revision
  • c64a64b4f2d7618972208ffc630ac91fe772d02e
  • test default
  • main protected
3 results

models.py

Blame
  • User.pm 1.42 KiB
    package CF::Schema::Result::User;
    
    use strict;
    use warnings;
    use feature 'signatures';
    no warnings qw{ experimental::signatures };
    
    use base 'DBIx::Class::Core';
    
    use Data::Random qw(rand_chars);
    
    our $VERSION = 1;
    
    __PACKAGE__->table('users');
    
    __PACKAGE__->add_columns(
        id => {
            data_type         => 'integer',
            is_auto_increment => 1,
            is_nullable       => 0,
            sequence          => 'uid_seq'
        },
        qw(
            uuid
            is_active
            username
            secret
            name
            roles
            main_group_name
            banned_until
            jitsi_allowed
        ),
    );
    
    __PACKAGE__->set_primary_key('id');
    
    __PACKAGE__->add_unique_constraint(
        'uuid' => [qw(uuid)]
    );
    
    __PACKAGE__->has_many(
        posts => 'CF::Schema::Result::Post',
        { 'foreign.user_id' => 'self.id', },
    );
    
    __PACKAGE__->has_many(
        alive => 'CF::Schema::Result::Alive',
        { 'foreign.user_id' => 'self.id', },
    );
    
    sub formatted($self) {
    
        my $user = {
            $self->get_columns,
            group => $self->main_group_name,
            is_banned => $self->banned_until ? 1:0,
        };
    
        return $user;
    
    }
    
    sub set_secret($self, $new='') {
    
        return if $self->secret and not $new;
    
        my $secret = rand_chars( set => 'alphanumeric', size => 16 );
    
        $self->update({