]> iEval git - gruntmaster-page.git/blob - lib/Gruntmaster/Page/Register.pm
Add register and passwd actions
[gruntmaster-page.git] / lib / Gruntmaster / Page / Register.pm
1 package Gruntmaster::Page::Register;
2
3 use 5.014000;
4 use strict;
5 use warnings;
6 use Gruntmaster::Page::Base;
7 our @ISA = qw/Gruntmaster::Page::Base/;
8 our $VERSION = '0.001';
9
10 use Apache2::Authen::Passphrase qw/pwcheck pwset USER_REGEX/;
11 use Plack::Request;
12
13 sub generate{
14 my ($self, $format, $env, $ct, $job, $ext) = @_;
15 my $r = Plack::Request->new($env);
16 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/;
17
18 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;
19 return reply 'Username already in use' if -e "$Apache2::Authen::Passphrase::rootdir/$username.yml";
20 return reply 'The two passwords do not match' unless $password eq $confirm_password;
21 return reply 'All fields are required' if grep { !length } $username, $password, $confirm_password, $name, $email, $phone, $town, $university, $level;
22 pwset $username, $password;
23
24 insert_user $username, name => $name, email => $email, phone => $phone, town => $town, university => $university, level => $level;
25
26 #PUBLISH genpage => "us/index.html";
27 #PUBLISH genpage => "us/$username.html";
28 reply 'Registered successfully';
29 }
30
31 sub variants{ [[reply => 1, undef, undef, undef, undef, undef]] }
32
33 1
This page took 0.04873 seconds and 5 git commands to generate.