1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
package FixMyStreet::DB::Result::User;
# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->load_components("FilterColumn");
__PACKAGE__->table("users");
__PACKAGE__->add_columns(
"id",
{
data_type => "integer",
is_auto_increment => 1,
is_nullable => 0,
sequence => "users_id_seq",
},
"email",
{ data_type => "text", is_nullable => 0 },
"name",
{ data_type => "text", is_nullable => 1 },
"phone",
{ data_type => "text", is_nullable => 1 },
"password",
{ data_type => "text", default_value => "", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->add_unique_constraint("users_email_key", ["email"]);
__PACKAGE__->has_many(
"alerts",
"FixMyStreet::DB::Result::Alert",
{ "foreign.user_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->has_many(
"problems",
"FixMyStreet::DB::Result::Problem",
{ "foreign.user_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-05-11 14:21:33
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Qaw6SZ5my5MnH7B5sB9NDw
use mySociety::EmailUtil;
=head2 check_for_errors
$error_hashref = $problem->check_for_errors();
Look at all the fields and return a hashref with all errors found, keyed on the
field name. This is intended to be passed back to the form to display the
errors.
TODO - ideally we'd pass back error codes which would be humanised in the
templates (eg: 'missing','email_not_valid', etc).
=cut
sub check_for_errors {
my $self = shift;
my %errors = ();
if ( $self->name !~ m/\S/ ) {
$errors{name} = _('Please enter your name');
}
elsif (length( $self->name ) < 5
|| $self->name !~ m/\s/
|| $self->name =~ m/\ba\s*n+on+((y|o)mo?u?s)?(ly)?\b/i )
{
$errors{name} = _(
'Please enter your full name, councils need this information - if you do not wish your name to be shown on the site, untick the box'
);
}
if ( $self->email !~ /\S/ ) {
$errors{email} = _('Please enter your email');
}
elsif ( !mySociety::EmailUtil::is_valid_email( $self->email ) ) {
$errors{email} = _('Please enter a valid email');
}
return \%errors;
}
1;
|