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;
34 Text::Tradition::User - Users which own traditions, and can login to the web app
38 ## Users are managed by Text::Tradition::UserStore
40 my $userstore = Text::Tradition::UserStore->new(dsn => 'dbi:SQLite:foo.db');
41 my $newuser = $userstore->add_user({ username => 'fred',
42 password => 'somepassword' });
44 my $fetchuser = $userstore->find_user({ username => 'fred' });
45 if($fetchuser->check_password('somepassword')) {
46 ## login user or .. whatever
49 my $user = $userstore->deactivate_user({ username => 'fred' });
51 ## shouldnt be able to login etc
54 foreach my $t (@{ $user->traditions }) {
55 ## do something with traditions owned by this user.
60 User objects representing owners of L<Text::Tradition>s and authenticated users.
66 Inherited from KiokuX::User, stores the 'username' (login) of the user.
70 User's password, encrypted on creation (by
71 L<KiokuX::User::Util/crypt_password>.
75 Active flag, defaults to true (1). Will be set to false (0) by
76 L<Text::Tradition::UserStore/deactivate_user>.
80 Returns an ArrayRef of L<Text::Tradition> objects belonging to this user.
86 Inherited from KiokuX::User, verifies a given password string against
87 the stored encrypted version.