diff options
| author | 2017-05-08 02:06:38 +0000 | |
|---|---|---|
| committer | 2017-05-08 02:25:18 +0000 | |
| commit | 7342c7f0e19e15ab3c7ba2133a56393c15989f08 (patch) | |
| tree | 5e00a9c2a3164bd49d18ded9263f1ea7ae99d7f6 /lib/ASM/DB | |
| parent | 62d8fcde1c6dc5be2f535f6fcffa1afd838b62bd (diff) | |
Move users to DB
Summary:
This will automatically take care of migrating the users from
users.json; you may delete that file.
Note that this removes htpasswd support. We now store (hashed) user
passwords in the database.
See T19 for rationale.
Test Plan: Run this on a testnet for a while, try to break it.
Reviewers: ilbelkyr, #antispammeta
Reviewed By: ilbelkyr, #antispammeta
Tags: #antispammeta, #database
Differential Revision: https://dev.antispammeta.net/D2
Diffstat (limited to 'lib/ASM/DB')
| -rw-r--r-- | lib/ASM/DB/Result/User.pm | 34 | ||||
| -rw-r--r-- | lib/ASM/DB/ResultSet/User.pm | 23 |
2 files changed, 57 insertions, 0 deletions
diff --git a/lib/ASM/DB/Result/User.pm b/lib/ASM/DB/Result/User.pm index 5e5d17c..675ccba 100644 --- a/lib/ASM/DB/Result/User.pm +++ b/lib/ASM/DB/Result/User.pm @@ -6,6 +6,8 @@ use warnings; use parent 'DBIx::Class::Core'; +use Authen::Passphrase::RejectAll; + __PACKAGE__->load_components('InflateColumn::DateTime', 'PassphraseColumn'); __PACKAGE__->table('users'); __PACKAGE__->add_columns( @@ -30,9 +32,41 @@ __PACKAGE__->add_columns( passphrase_check_method => 'check_password', is_nullable => 0, }, + flag_secret => { + data_type => 'boolean', + is_nullable => 0, + default_value => 0, + }, + flag_hilights => { + data_type => 'boolean', + is_nullable => 0, + default_value => 0, + }, + flag_admin => { + data_type => 'boolean', + is_nullable => 0, + default_value => 0, + }, + flag_plugin => { + data_type => 'boolean', + is_nullable => 0, + default_value => 0, + }, + flag_debug => { + data_type => 'boolean', + is_nullable => 0, + default_value => 0, + }, ); __PACKAGE__->set_primary_key('id'); __PACKAGE__->add_unique_constraint(uniq_user_name => ['name']); +sub new { + my $self = shift; + $_[0]{passphrase} //= Authen::Passphrase::RejectAll->new; + + $self->SUPER::new(@_); +} + 1; diff --git a/lib/ASM/DB/ResultSet/User.pm b/lib/ASM/DB/ResultSet/User.pm new file mode 100644 index 0000000..68c0871 --- /dev/null +++ b/lib/ASM/DB/ResultSet/User.pm @@ -0,0 +1,23 @@ +use utf8; + +package ASM::DB::ResultSet::User; + +use strict; +use warnings; + +use parent 'DBIx::Class::ResultSet'; +use namespace::autoclean; + +sub by_name { + my ( $self, $name ) = @_; + + return $self->find( { name => $name }, { key => 'uniq_user_name' } ); +} + +sub by_name_or_new { + my ( $self, $name ) = @_; + + return $self->find_or_new( { name => $name }, { key => 'uniq_user_name' } ); +} + +1; |
