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 # 'traits' => ['Array'] ?
14 # https://metacpan.org/module/Moose::Meta::Attribute::Native::Trait::Array
15 has 'traditions' => (is => 'rw',
18 'add_tradition' => 'push',
20 isa => 'ArrayRef[Text::Tradition]',
21 default => sub { [] },
24 after add_tradition => sub {
25 my ($self, $tradition) = @_;
26 $tradition->user($self)
27 unless $tradition->has_user && $tradition->user->id eq $self->id;
30 sub remove_tradition {
31 my ($self, $tradition) = @_;
33 ## FIXME: Is "name" a good unique field to compare traditions on?
34 my @traditions = @{$self->traditions};
35 @traditions = grep { $tradition != $_ } @traditions;
37 $tradition->clear_user;
38 $self->traditions(\@traditions);
45 Text::Tradition::User - Users which own traditions, and can login to the web app
49 ## Users are managed by Text::Tradition::UserStore
51 my $userstore = Text::Tradition::UserStore->new(dsn => 'dbi:SQLite:foo.db');
52 my $newuser = $userstore->add_user({ username => 'fred',
53 password => 'somepassword' });
55 my $fetchuser = $userstore->find_user({ username => 'fred' });
56 if($fetchuser->check_password('somepassword')) {
57 ## login user or .. whatever
60 my $user = $userstore->deactivate_user({ username => 'fred' });
62 ## shouldnt be able to login etc
65 foreach my $t (@{ $user->traditions }) {
66 ## do something with traditions owned by this user.
71 User objects representing owners of L<Text::Tradition>s and authenticated users.
77 Inherited from KiokuX::User, stores the 'username' (login) of the user.
81 User's password, encrypted on creation (by
82 L<KiokuX::User::Util/crypt_password>.
86 Active flag, defaults to true (1). Will be set to false (0) by
87 L<Text::Tradition::UserStore/deactivate_user>.
91 Returns an ArrayRef of L<Text::Tradition> objects belonging to this user.
97 Inherited from KiokuX::User, verifies a given password string against
98 the stored encrypted version.