diff options
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Session.pm | 21 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 52 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/DefectType.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/ResponsePriority.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/ResponseTemplate.pm | 5 |
5 files changed, 71 insertions, 15 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Session.pm b/perllib/FixMyStreet/DB/Result/Session.pm index 4713c99eb..a478c5444 100644 --- a/perllib/FixMyStreet/DB/Result/Session.pm +++ b/perllib/FixMyStreet/DB/Result/Session.pm @@ -24,5 +24,24 @@ __PACKAGE__->set_primary_key("id"); # Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:MVmCn4gLQWXTDIIaDHiVmA -# You can replace this text with custom code or comments, and it will be preserved on regeneration +use Storable; +use MIME::Base64; + +sub id_code { + my $self = shift; + my $id = $self->id; + $id =~ s/^session://; + $id =~ s/\s+$//; + return $id; +} + +sub user { + my $self = shift; + return unless $self->session_data; + my $data = Storable::thaw(MIME::Base64::decode($self->session_data)); + return unless $data->{__user}; + my $user = $self->result_source->schema->resultset("User")->find($data->{__user}{id}); + return $user; +} + 1; diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index db68236bf..8b539f85d 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -20,10 +20,14 @@ __PACKAGE__->add_columns( }, "email", { data_type => "text", is_nullable => 1 }, + "email_verified", + { data_type => "boolean", default_value => \"false", is_nullable => 0 }, "name", { data_type => "text", is_nullable => 1 }, "phone", { data_type => "text", is_nullable => 1 }, + "phone_verified", + { data_type => "boolean", default_value => \"false", is_nullable => 0 }, "password", { data_type => "text", default_value => "", is_nullable => 0 }, "from_body", @@ -42,10 +46,20 @@ __PACKAGE__->add_columns( { data_type => "integer", is_nullable => 1 }, "extra", { data_type => "text", is_nullable => 1 }, - "email_verified", - { data_type => "boolean", default_value => \"false", is_nullable => 0 }, - "phone_verified", - { data_type => "boolean", default_value => \"false", is_nullable => 0 }, + "created", + { + data_type => "timestamp", + default_value => \"current_timestamp", + is_nullable => 0, + original => { default_value => \"now()" }, + }, + "last_active", + { + data_type => "timestamp", + default_value => \"current_timestamp", + is_nullable => 0, + original => { default_value => \"now()" }, + }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("users_facebook_id_key", ["facebook_id"]); @@ -105,8 +119,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-09-19 18:02:17 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:OKHKCSahWD3Ov6ulj+2f/w +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2018-05-23 18:54:36 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/V7+Ygv/t6VX8dDhNGN16w # These are not fully unique constraints (they only are when the *_verified # is true), but this is managed in ResultSet::User's find() wrapper. @@ -442,6 +456,25 @@ sub adopt { $other->delete; } +sub anonymize_account { + my $self = shift; + + $self->problems->update({ anonymous => 1, name => '', send_questionnaire => 0 }); + $self->comments->update({ anonymous => 1, name => '' }); + $self->alerts->update({ whendisabled => \'current_timestamp' }); + $self->password('', 1); + $self->update({ + email => 'removed-' . $self->id . '@' . FixMyStreet->config('EMAIL_DOMAIN'), + email_verified => 0, + name => '', + phone => '', + phone_verified => 0, + title => undef, + twitter_id => undef, + facebook_id => undef, + }); +} + # Planned reports / shortlist # Override the default auto-created function as we only want one live entry so @@ -511,4 +544,11 @@ has categories => ( }, ); +sub set_last_active { + my $self = shift; + my $time = shift; + $self->unset_extra_metadata('inactive_email_sent'); + $self->last_active($time or \'current_timestamp'); +} + 1; diff --git a/perllib/FixMyStreet/DB/ResultSet/DefectType.pm b/perllib/FixMyStreet/DB/ResultSet/DefectType.pm index b2ef77f7c..5b1247129 100644 --- a/perllib/FixMyStreet/DB/ResultSet/DefectType.pm +++ b/perllib/FixMyStreet/DB/ResultSet/DefectType.pm @@ -4,7 +4,6 @@ use base 'DBIx::Class::ResultSet'; use strict; use warnings; use Moo; -use HTML::Entities; with('FixMyStreet::Roles::ContactExtra'); @@ -16,10 +15,10 @@ sub map_extras { my ($rs, @ts) = @_; return map { my $meta = $_->get_extra_metadata(); - my %extra = map { $_ => encode_entities($meta->{$_}) } keys %$meta; + my %extra = map { $_ => $meta->{$_} } keys %$meta; { id => $_->id, - name => encode_entities($_->name), + name => $_->name, extra => \%extra } } @ts; diff --git a/perllib/FixMyStreet/DB/ResultSet/ResponsePriority.pm b/perllib/FixMyStreet/DB/ResultSet/ResponsePriority.pm index 89bb4dfd7..96f7cf7a0 100644 --- a/perllib/FixMyStreet/DB/ResultSet/ResponsePriority.pm +++ b/perllib/FixMyStreet/DB/ResultSet/ResponsePriority.pm @@ -4,7 +4,6 @@ use base 'DBIx::Class::ResultSet'; use strict; use warnings; use Moo; -use HTML::Entities; with('FixMyStreet::Roles::ContactExtra'); @@ -14,7 +13,7 @@ sub join_table { sub map_extras { my ($rs, @ts) = @_; - return map { { id => $_->id, name => encode_entities($_->name) } } @ts; + return map { { id => $_->id, name => $_->name } } @ts; } 1; diff --git a/perllib/FixMyStreet/DB/ResultSet/ResponseTemplate.pm b/perllib/FixMyStreet/DB/ResultSet/ResponseTemplate.pm index aa070daa3..46fcba153 100644 --- a/perllib/FixMyStreet/DB/ResultSet/ResponseTemplate.pm +++ b/perllib/FixMyStreet/DB/ResultSet/ResponseTemplate.pm @@ -2,7 +2,6 @@ package FixMyStreet::DB::ResultSet::ResponseTemplate; use base 'DBIx::Class::ResultSet'; use Moo; -use HTML::Entities; with('FixMyStreet::Roles::ContactExtra'); @@ -17,8 +16,8 @@ sub name_column { sub map_extras { my ($rs, @ts) = @_; return map { - my $out = { id => encode_entities($_->text), name => encode_entities($_->title) }; - $out->{state} = encode_entities($_->state) if $_->state; + my $out = { id => $_->text, name => $_->title }; + $out->{state} = $_->state if $_->state; $out; } @ts; } |