]> iEval git - gruntmaster-page.git/blobdiff - lib/Gruntmaster/Page/Register.pm
Add register and passwd actions
[gruntmaster-page.git] / lib / Gruntmaster / Page / Register.pm
diff --git a/lib/Gruntmaster/Page/Register.pm b/lib/Gruntmaster/Page/Register.pm
new file mode 100644 (file)
index 0000000..599f1c4
--- /dev/null
@@ -0,0 +1,33 @@
+package Gruntmaster::Page::Register;
+
+use 5.014000;
+use strict;
+use warnings;
+use Gruntmaster::Page::Base;
+our @ISA = qw/Gruntmaster::Page::Base/;
+our $VERSION = '0.001';
+
+use Apache2::Authen::Passphrase qw/pwcheck pwset USER_REGEX/;
+use Plack::Request;
+
+sub generate{
+       my ($self, $format, $env, $ct, $job, $ext) = @_;
+       my $r = Plack::Request->new($env);
+       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/;
+
+       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;
+       return reply 'Username already in use' if -e "$Apache2::Authen::Passphrase::rootdir/$username.yml";
+       return reply 'The two passwords do not match' unless $password eq $confirm_password;
+       return reply 'All fields are required' if grep { !length } $username, $password, $confirm_password, $name, $email, $phone, $town, $university, $level;
+       pwset $username, $password;
+
+       insert_user $username, name => $name, email => $email, phone => $phone, town => $town, university => $university, level => $level;
+
+       #PUBLISH genpage =>  "us/index.html";
+       #PUBLISH genpage =>  "us/$username.html";
+       reply 'Registered successfully';
+}
+
+sub variants{ [[reply => 1, undef, undef, undef, undef, undef]] }
+
+1
This page took 0.02572 seconds and 4 git commands to generate.