]>
Commit | Line | Data |
---|---|---|
31d70015 MG |
1 | package Gruntmaster::Page::Register; |
2 | ||
31d70015 | 3 | use Gruntmaster::Page::Base; |
31d70015 | 4 | use Apache2::Authen::Passphrase qw/pwcheck pwset USER_REGEX/; |
31d70015 MG |
5 | |
6 | sub generate{ | |
8d29b3b1 | 7 | my ($self, $format, $env) = @_; |
31d70015 MG |
8 | my $r = Plack::Request->new($env); |
9 | my ($username, $password, $confirm_password, $name, $email, $phone, $town, $university, $level) = map { die if length > 200; $_ } map {scalar $r->param($_)} qw/username password confirm_password name email phone town university level/; | |
10 | ||
11 | return reply 'Bad username. Allowed characters are letters, digits and underscores, and the username must be between 2 and 20 characters long.' unless $username =~ USER_REGEX; | |
12 | return reply 'Username already in use' if -e "$Apache2::Authen::Passphrase::rootdir/$username.yml"; | |
13 | return reply 'The two passwords do not match' unless $password eq $confirm_password; | |
14 | return reply 'All fields are required' if grep { !length } $username, $password, $confirm_password, $name, $email, $phone, $town, $university, $level; | |
15 | pwset $username, $password; | |
16 | ||
d3200993 | 17 | db($env)->create({id => $username, name => $name, email => $email, phone => $phone, town => $town, university => $university, level => $level}); |
31d70015 | 18 | |
49c1467a | 19 | purge "/us/"; |
31d70015 MG |
20 | reply 'Registered successfully'; |
21 | } | |
22 | ||
31d70015 | 23 | 1 |