1 package Text::Tradition::User;
9 ## 'id' provided by KiokuX::User stores our username
10 has 'password' => (is => 'rw', required => 1);
11 ## Change this default active value if you want/need to have an admin confirm a user after they self-create.
12 has 'active' => (is => 'rw', default => sub { 1; });
13 has 'role' => (is => 'rw', default => sub { 'user' });
14 # 'traits' => ['Array'] ?
15 # https://metacpan.org/module/Moose::Meta::Attribute::Native::Trait::Array
16 has 'traditions' => (is => 'rw',
19 'add_tradition' => 'push',
21 isa => 'ArrayRef[Text::Tradition]',
22 default => sub { [] },
25 after add_tradition => sub {
26 my ($self, $tradition) = @_;
27 $tradition->user($self)
28 unless $tradition->has_user && $tradition->user->id eq $self->id;
31 sub remove_tradition {
32 my ($self, $tradition) = @_;
34 ## FIXME: Is "name" a good unique field to compare traditions on?
35 my @traditions = @{$self->traditions};
36 @traditions = grep { $tradition != $_ } @traditions;
38 $tradition->clear_user;
39 $self->traditions(\@traditions);
45 return $self->role eq 'admin';
52 Text::Tradition::User - Users which own traditions, and can login to the web app
56 ## Users are managed by Text::Tradition::UserStore
58 my $userstore = Text::Tradition::UserStore->new(dsn => 'dbi:SQLite:foo.db');
59 my $newuser = $userstore->add_user({ username => 'fred',
60 password => 'somepassword' });
62 my $fetchuser = $userstore->find_user({ username => 'fred' });
63 if($fetchuser->check_password('somepassword')) {
64 ## login user or .. whatever
67 my $user = $userstore->deactivate_user({ username => 'fred' });
69 ## shouldnt be able to login etc
72 foreach my $t (@{ $user->traditions }) {
73 ## do something with traditions owned by this user.
78 User objects representing owners of L<Text::Tradition>s and authenticated users.
84 Inherited from KiokuX::User, stores the 'username' (login) of the user.
88 User's password, encrypted on creation (by
89 L<KiokuX::User::Util/crypt_password>.
93 Active flag, defaults to true (1). Will be set to false (0) by
94 L<Text::Tradition::UserStore/deactivate_user>.
98 Returns an ArrayRef of L<Text::Tradition> objects belonging to this user.
102 =head3 check_password
104 Inherited from KiokuX::User, verifies a given password string against
105 the stored encrypted version.