Add register page

This commit is contained in:
Citlali del Rey 2022-10-14 23:12:39 -07:00
parent 8ede963666
commit 58e47a7590
Signed by: nullobsi
GPG Key ID: 933A1F44222C2634
13 changed files with 294 additions and 15 deletions

View File

@ -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'}
);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -0,0 +1,7 @@
% title 'Internal Server Error';
% layout 'default';
<h1>Internal Server Error</h1>
<p>
Our best dogs are working on it...
</p>

View File

@ -17,14 +17,17 @@
<header>
<div id="header-content">
<img src="favicon.ico" width="32" height="32" alt="UNIX.dog"/>
<h1>UNIX.dog</h1>
<a href="/"><h1>UNIX.dog</h1></a>
<div id="nav">
<a href="/register">Register</a>
</div>
</div>
</header>
<main>
<%= content %>
</main>
<footer>
<span class="copyleft">&copy;</span> <a href="https://git.unix.dog/nullobsi/website">Copyleft</a> UNIX.dog, 2022. All pages licensed under CC BY-NC-SA 4.0.
<span class="copyleft">&copy;</span> <a href="https://git.unix.dog/UNIX.dog/website">Copyleft</a> UNIX.dog, 2022. All pages licensed under CC BY-NC-SA 4.0.
<br>
Please follow <a href="/rules">all rules</a> while using these services.
</footer>

View File

@ -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!
<a href="/register">Registration is open!</a>
</p>
<section>

View File

@ -1,4 +1,5 @@
% layout 'default';
% title 'UNIX.dog Rules';
<article>
<h1>UNIX.dog Rules</h1>
<p>

View File

@ -0,0 +1,4 @@
% title 'Not Found';
% layout 'default';
<h1>Page Not Found</h1>
<p>Looks like you better start sniffing elsewhere.</p>

View File

@ -0,0 +1,17 @@
% layout 'default';
% title 'UNIX.dog Registration';
<h1>Registration Complete!</h1>
<p>
Your registration was submitted successfully!
We will review your registration and email you when
your registration is verified. Thanks!
</p>
<p>
Registration Info:
<br>
Username: <%= $username %>
<br>
Contact Email: <%= $email %>
<br>
If this doesn't seem correct, feel free to reach out!
</p>

View File

@ -0,0 +1,57 @@
% layout 'default';
% title 'UNIX.dog Registration';
<h1>Register</h1>
<% if (my $err = stash 'err') { %>
<p class="error">
<%= $err %>
</p>
<% } %>
<p>
Before registering for UNIX.dog, please be sure you agree
with <a href="/rules">our rules.</a> 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.
</p>
<p>
If you have more concerns about your registration, feel free
to contact alpha at this domain.
</p>
<p>
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.
</p>
<form action="/register" method="POST">
<p>
<label for="username">Username:</label>
<input type="text" id="username" name="username">
</p>
<p>
<label for="password">Password:</label>
<input type="password" id="password" name="password">
</p>
<p>
<label for="email">EMail:</label>
<input type="email" id="email" name="email">
</p>
<p>
<label for="pub-key">
Put your SSH keys here.
Separate them by a newline if you have multiple.
</label>
<br>
<textarea name="pub-key" id="pub-key"></textarea>
</p>
<p>
<label for="bio">
Tell us a bit about yourself here.
Feel free to put some links, too :)
</label>
<br>
<textarea name="bio" id="bio"></textarea>
</p>
<input type="submit" value="Submit!" id="submit">
</form>

View File

@ -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'