From 58e47a7590f9b17dc365606762778ec6d0724158 Mon Sep 17 00:00:00 2001
From: Kayden Tebau
Date: Fri, 14 Oct 2022 23:12:39 -0700
Subject: [PATCH] Add register page
---
Makefile.PL | 4 +-
lib/unix_dog.pm | 3 +
lib/unix_dog/Controller/Example.pm | 11 --
lib/unix_dog/Controller/Register.pm | 153 ++++++++++++++++++++++++
public/css/main.css | 38 ++++++
templates/exception.html.ep | 7 ++
templates/layouts/default.html.ep | 7 +-
templates/main/index.html.ep | 2 +-
templates/main/rules.html.ep | 1 +
templates/not_found.html.ep | 4 +
templates/register/registerDone.html.ep | 17 +++
templates/register/registerPage.html.ep | 57 +++++++++
unix_dog.default.yml | 5 +
13 files changed, 294 insertions(+), 15 deletions(-)
delete mode 100644 lib/unix_dog/Controller/Example.pm
create mode 100644 lib/unix_dog/Controller/Register.pm
create mode 100644 templates/exception.html.ep
create mode 100644 templates/not_found.html.ep
create mode 100644 templates/register/registerDone.html.ep
create mode 100644 templates/register/registerPage.html.ep
diff --git a/Makefile.PL b/Makefile.PL
index 32b4073..9260e20 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -6,7 +6,9 @@ use ExtUtils::MakeMaker;
WriteMakefile(
VERSION => '0.01',
PREREQ_PM => {
- 'Mojolicious' => '9.27'
+ 'Mojolicious' => '9.27',
+ 'Email::MIME' => '1.952',
+ 'Email::Sender::Simple' => '2.500'
},
test => {TESTS => 't/*.t'}
);
diff --git a/lib/unix_dog.pm b/lib/unix_dog.pm
index 31bd7bc..c4f5772 100644
--- a/lib/unix_dog.pm
+++ b/lib/unix_dog.pm
@@ -19,6 +19,9 @@ sub startup ($self) {
$r->get('/')->to('Main#index');
$r->get('/index.xhtml')->to('Main#index');
$r->get('/rules')->to('Main#rules');
+
+ $r->get('/register')->to('Register#registration');
+ $r->post('/register')->to('Register#register');
}
1;
diff --git a/lib/unix_dog/Controller/Example.pm b/lib/unix_dog/Controller/Example.pm
deleted file mode 100644
index f23c710..0000000
--- a/lib/unix_dog/Controller/Example.pm
+++ /dev/null
@@ -1,11 +0,0 @@
-package unix_dog::Controller::Example;
-use Mojo::Base 'Mojolicious::Controller', -signatures;
-
-# This action will render a template
-sub welcome ($self) {
-
- # Render template "example/welcome.html.ep" with message
- $self->render(msg => 'Welcome to the Mojolicious real-time web framework!');
-}
-
-1;
diff --git a/lib/unix_dog/Controller/Register.pm b/lib/unix_dog/Controller/Register.pm
new file mode 100644
index 0000000..6cede98
--- /dev/null
+++ b/lib/unix_dog/Controller/Register.pm
@@ -0,0 +1,153 @@
+package unix_dog::Controller::Register;
+use Mojo::Base 'Mojolicious::Controller', -signatures;
+use Net::LDAPS;
+use Net::LDAP::Extension::SetPassword;
+use Email::Simple;
+use Email::Sender::Simple;
+use Email::Sender::Transport::Sendmail;
+
+sub registration($self) {
+ $self->render('register/registerPage');
+}
+
+sub register($self) {
+ my $v = $self->validation;
+
+ $v->required('username', 'trim')->size(1,32)->like(qr/^([a-z_][a-z0-9_-]*[\$]?)$/);
+ $v->required('password')->size(8, 256);
+ $v->required('email')->size(1, 512);
+ $v->required('pub-key')->size(1,4096);
+ $v->required('bio')->size(1, 2048);
+
+ if ($v->has_error) {
+ $self->stash(err => 'Your input was invalid. Please try again.');
+ return $self->render('register/registerPage');
+ }
+
+ my $username = $self->param('username');
+ my $password = $self->param('password');
+ my $email = $self->param('email');
+ my $pubkeys = $self->param('pub-key');
+ my $bio = $self->param('bio');
+ my $fromIP = $self->tx->remote_address;
+
+
+ $self->stash(email => $email);
+ $self->stash(username => $username);
+
+ my $config = $self->config;
+ return Mojo::IOLoop->subprocess->run_p(sub {
+ my $connStr = $config->{'ldap'}->{'uri'};
+ my $bindDN = $config->{'ldap'}->{'bindDN'};
+ my $bindPasswd = $config->{'ldap'}->{'password'};
+
+ my $ldap = Net::LDAPS->new($connStr, verify=>'none', version => 3) or die "$@";
+ my $mesg = $ldap->bind($bindDN, password=>$bindPasswd);
+ $mesg->code and die $mesg->error;
+
+ $mesg = $ldap->search(
+ base => 'cn=NextID,ou=Unverified,dc=unix,dc=dog',
+ scope => 'base',
+ filter => '(&)'
+ );
+ $mesg->code and die $mesg->error;
+
+ my @searchEntries = $mesg->entries;
+ my $uidEntry = $searchEntries[0];
+ $uidEntry or die 'Entry not found';
+
+ my $nextUID = int($uidEntry->get_value('uidnumber'));
+ my $nextGID = int($uidEntry->get_value('gidnumber'));
+
+ $mesg = $ldap->modify(
+ $uidEntry,
+ replace => {
+ uidNumber => $nextUID + 1,
+ gidNumber => $nextGID + 1,
+ }
+ );
+ $mesg->code and die $mesg->error;
+
+ my $userDN = 'CN='.$username.',OU=Dogs,OU=Unverified,DC=unix,DC=dog';
+
+ $mesg = $ldap->add(
+ $userDN,
+ attrs => [
+ cn => $username,
+ mail => $email,
+ sshPublicKey => (split "\n", $pubkeys),
+ objectClass => [
+ 'top',
+ 'extensibleObject',
+ 'inetOrgPerson',
+ 'person',
+ 'organizationalPerson',
+ 'posixAccount',
+ 'shadowAccount',
+ 'uidObject',
+ 'ldapPublicKey'
+ ],
+ uid => $username,
+ uidNumber => $nextUID,
+ gidNumber => $nextGID,
+ homeDirectory => '/home/' . $username,
+ loginShell => '/bin/bash',
+ ]
+ );
+ $mesg->code and die $mesg->error;
+
+ $mesg = $ldap->set_password(
+ user => $userDN,
+ newpasswd => $password,
+ );
+ $mesg->code and die $mesg->error;
+
+ my $groupDN = 'CN='.$username.',OU=Group,OU=Unverified,DC=unix,DC=dog';
+ $mesg = $ldap->add(
+ $groupDN,
+ attrs => [
+ cn => $username,
+ objectClass => [ 'groupOfNames', 'posixGroup' ],
+ gidNumber => $nextGID,
+ member => [ $userDN ],
+ memberUid => [ $username ],
+ ]
+ );
+ $mesg->code and die $mesg->error;
+
+ my $message = Email::Simple->create(
+ header => [
+ From => 'registration@unix.dog',
+ To => 'alpha@unix.dog',
+ Subject => 'New Woof Registration',
+ ],
+ body => "ARF WOOF!! There's a dog waiting at the door!
+Woofname: $username
+EMail: $email
+More info: $bio
+IP: $fromIP
+Conformation LDIF:
+dn: $userDN
+changetype: moddn
+newsuperior: ou=Dogs,dc=unix,dc=dog
+deleteoldrdn: 1
+-
+dn: $groupDN
+changetype: moddn
+newsuperior: ou=Group,dc=unix,dc=dog
+deleteoldrdn: 1"
+ );
+
+ Email::Sender::Simple->send($message);
+
+ })->then(sub (@results) {
+ $self->render('register/registerDone');
+ })->catch(sub ($err) {
+ $self->stash(err => $err);
+ $self->render('register/registerPage');
+ })->wait;
+
+
+}
+
+1;
diff --git a/public/css/main.css b/public/css/main.css
index cb1a25c..7f04757 100644
--- a/public/css/main.css
+++ b/public/css/main.css
@@ -112,3 +112,41 @@ footer a:link, footer a:visited {
footer a:hover {
text-decoration: underline;
}
+
+
+input {
+ background: #332c29;
+ color: #f6f6f6;
+}
+
+textarea {
+ background: #332c29;
+ color: #f6f6f6;
+}
+
+.error {
+ color: #f00;
+}
+
+#nav {
+ margin: auto 0 auto auto;
+ display: flex;
+ flex-direction: row;
+}
+
+#nav a {
+ display: block;
+}
+
+#header-content a:link {
+ text-decoration: none;
+ color: black;
+}
+#header-content a:visited {
+ text-decoration: none;
+ color: black;
+}
+
+#header-content a:hover {
+ text-decoration: underline;
+}
diff --git a/templates/exception.html.ep b/templates/exception.html.ep
new file mode 100644
index 0000000..0ded539
--- /dev/null
+++ b/templates/exception.html.ep
@@ -0,0 +1,7 @@
+% title 'Internal Server Error';
+% layout 'default';
+
+Internal Server Error
+
+ Our best dogs are working on it...
+
diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep
index 3a81932..e8120ea 100644
--- a/templates/layouts/default.html.ep
+++ b/templates/layouts/default.html.ep
@@ -17,14 +17,17 @@
<%= content %>
- © Copyleft UNIX.dog, 2022. All pages licensed under CC BY-NC-SA 4.0.
+ © Copyleft UNIX.dog, 2022. All pages licensed under CC BY-NC-SA 4.0.
Please follow all rules while using these services.
diff --git a/templates/main/index.html.ep b/templates/main/index.html.ep
index b552e8c..2f2035f 100644
--- a/templates/main/index.html.ep
+++ b/templates/main/index.html.ep
@@ -6,7 +6,7 @@
We aim to provide a welcoming space for furries,
queer folks, and their allies to hang out, create, and communicate!
- Registration will open soon!
+ Registration is open!
diff --git a/templates/main/rules.html.ep b/templates/main/rules.html.ep
index 907a505..a6930da 100644
--- a/templates/main/rules.html.ep
+++ b/templates/main/rules.html.ep
@@ -1,4 +1,5 @@
% layout 'default';
+% title 'UNIX.dog Rules';
UNIX.dog Rules
diff --git a/templates/not_found.html.ep b/templates/not_found.html.ep
new file mode 100644
index 0000000..2bf77a2
--- /dev/null
+++ b/templates/not_found.html.ep
@@ -0,0 +1,4 @@
+% title 'Not Found';
+% layout 'default';
+
Page Not Found
+Looks like you better start sniffing elsewhere.
diff --git a/templates/register/registerDone.html.ep b/templates/register/registerDone.html.ep
new file mode 100644
index 0000000..10de9f9
--- /dev/null
+++ b/templates/register/registerDone.html.ep
@@ -0,0 +1,17 @@
+% layout 'default';
+% title 'UNIX.dog Registration';
+Registration Complete!
+
+ Your registration was submitted successfully!
+ We will review your registration and email you when
+ your registration is verified. Thanks!
+
+
+ Registration Info:
+
+ Username: <%= $username %>
+
+ Contact Email: <%= $email %>
+
+ If this doesn't seem correct, feel free to reach out!
+
diff --git a/templates/register/registerPage.html.ep b/templates/register/registerPage.html.ep
new file mode 100644
index 0000000..c83f437
--- /dev/null
+++ b/templates/register/registerPage.html.ep
@@ -0,0 +1,57 @@
+% layout 'default';
+% title 'UNIX.dog Registration';
+Register
+<% if (my $err = stash 'err') { %>
+
+ <%= $err %>
+
+<% } %>
+
+ Before registering for UNIX.dog, please be sure you agree
+ with our rules. Once you've read them,
+ you can register! Please keep in mind that accounts will be
+ verified by hand. An email will be sent to you from one of the
+ admins when your account has been verified. Please make sure
+ that you check your spam folder.
+
+
+ If you have more concerns about your registration, feel free
+ to contact alpha at this domain.
+
+
+ Self-service password management and SSH key management will
+ be coming soon, but if you know how, you can update all your
+ information over LDAP under cn=username,ou=Dogs,dc=unix,dc=dog.
+
+
+
diff --git a/unix_dog.default.yml b/unix_dog.default.yml
index b0a4f4f..b4bfbb9 100644
--- a/unix_dog.default.yml
+++ b/unix_dog.default.yml
@@ -7,3 +7,8 @@ hypnotoad:
- 'http://127.0.0.1:3005'
workers: 5
proxy: 1
+
+ldap:
+ uri: 'ldaps://127.0.0.1'
+ bindDN: 'here'
+ password: 'here'