Add register and passwd actions
authorMarius Gavrilescu <marius@ieval.ro>
Wed, 5 Feb 2014 15:01:42 +0000 (17:01 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Wed, 5 Feb 2014 15:01:42 +0000 (17:01 +0200)
app.psgi
lib/Gruntmaster/Page/Base.pm
lib/Gruntmaster/Page/Passwd.pm [new file with mode: 0644]
lib/Gruntmaster/Page/Register.pm [new file with mode: 0644]
lib/Plack/App/Gruntmaster.pm

index 25cf90f686f627746f26560b8be9c99b03e680ea..f13ef8e323be37574355c32643612b21cd27bb6e 100644 (file)
--- a/app.psgi
+++ b/app.psgi
@@ -8,6 +8,7 @@ use Plack::Request;
 
 sub some_auth_required {
        my $r = Plack::Request->new($_[0]);
+       return 1 if $r->path eq '/action/passwd';
        0
 }
 
index 3a58c188af55920d61d198f64206aab68d04201b..bc8e9cec1b176e81c63a37cb903cbf880fdd6206 100644 (file)
@@ -29,6 +29,8 @@ sub import {
                local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1;
                $_[0]->{'psgix.logger'}->({qw/level debug message/ => $_[1]})
        };
+       *{"${caller}::reply"} = sub { [200, ['Content-Type' => 'text/plain'], [ @_ ] ] }
+
 }
 
 ##################################################
diff --git a/lib/Gruntmaster/Page/Passwd.pm b/lib/Gruntmaster/Page/Passwd.pm
new file mode 100644 (file)
index 0000000..4604fbc
--- /dev/null
@@ -0,0 +1,27 @@
+package Gruntmaster::Page::Passwd;
+
+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/;
+use Plack::Request;
+
+sub generate{
+       my ($self, $format, $env, $ct, $job, $ext) = @_;
+       my $r = Plack::Request->new($env);
+       my ($oldpass, $newpass, $confirm) = map {scalar $r->param($_)} 'password', 'new_password', 'confirm_new_password';
+
+       return reply 'Incorrect password' unless eval { pwcheck $r->user, $oldpass; 1 };
+       return reply 'The two passwords do not match' unless $newpass eq $confirm;
+
+       pwset $r->user, $newpass;
+       reply 'Password changed successfully';
+}
+
+sub variants{ [[reply => 1, undef, undef, undef, undef, undef]] }
+
+1
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
index 2334235f1670bf64f997eafccde6e5d239c44812..66f86fe47e83052ef3b6feee560687fae2f4f6fb 100644 (file)
@@ -73,6 +73,9 @@ BEGIN{
        get qr,$ct/submit, => 'Submit';
        get qr,$ct/pb/, => 'Pb';
        get qr,$ct/pb/$word, => 'Pb::Entry';
+
+       post qr,/action/register, => 'Register';
+       post qr,/action/passwd, => 'Passwd';
 }
 
 1;
This page took 0.012156 seconds and 4 git commands to generate.