Adding verification web endpoint.
This commit is contained in:
parent
deeb0da8cd
commit
dcee164488
@ -8,6 +8,9 @@
|
||||
<li>
|
||||
<a href="lib/Peace.pm.html">Peace</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="lib/Peace/Controller/AccountVerification.pm.html">Peace::Controller::AccountVerification</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="lib/Peace/Controller/Application.pm.html">Peace::Controller::Application</a>
|
||||
</li>
|
||||
|
55
doc/lib/Peace/Controller/AccountVerification.pm.html
Normal file
55
doc/lib/Peace/Controller/AccountVerification.pm.html
Normal file
@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>Peace::Controller::AccountVerification - Account verification controller.</title>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
|
||||
<link href="mailto:Alpine@build-edge-aarch64.nonet" rev="made" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
|
||||
|
||||
<ul id="index">
|
||||
<li><a href="#NAME">NAME</a></li>
|
||||
<li><a href="#SYNOPSIS">SYNOPSIS</a></li>
|
||||
<li><a href="#DESCRIPTION">DESCRIPTION</a></li>
|
||||
<li><a href="#METHODS">METHODS</a>
|
||||
<ul>
|
||||
<li><a href="#verify">verify</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#SEE-ALSO">SEE ALSO</a></li>
|
||||
</ul>
|
||||
|
||||
<h1 id="NAME">NAME</h1>
|
||||
|
||||
<p>Peace::Controller::AccountVerification - Account verification controller.</p>
|
||||
|
||||
<h1 id="SYNOPSIS">SYNOPSIS</h1>
|
||||
|
||||
<pre><code># This class is not to be used in Perl code.</code></pre>
|
||||
|
||||
<h1 id="DESCRIPTION">DESCRIPTION</h1>
|
||||
|
||||
<p>This class handles account verification from the web.</p>
|
||||
|
||||
<h1 id="METHODS">METHODS</h1>
|
||||
|
||||
<p>Peace::Controller::AccountVerification implements the following methods.</p>
|
||||
|
||||
<h2 id="verify">verify</h2>
|
||||
|
||||
<p>For internal usage.</p>
|
||||
|
||||
<h1 id="SEE-ALSO">SEE ALSO</h1>
|
||||
|
||||
<p><a href="../DAO/Developer.pm.html">Peace::DAO::Developer</a></p>
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
<li><a href="#create">create</a></li>
|
||||
<li><a href="#recover_by_uuid">recover_by_uuid</a></li>
|
||||
<li><a href="#recover_by_identifier">recover_by_identifier</a></li>
|
||||
<li><a href="#verify">verify</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#SEE-ALSO">SEE ALSO</a></li>
|
||||
@ -80,6 +81,12 @@ my $developer = $developer_dao->recover_by_uuid( uuid => $uuid );</code></
|
||||
|
||||
<p>Recovers the <a href="../Model/Developer.pm.html">Peace::Model::Developer</a> associated from an identifier from database.</p>
|
||||
|
||||
<h2 id="verify">verify</h2>
|
||||
|
||||
<pre><code>$developer_dao->verify( verification_secret => $verification_secret );</code></pre>
|
||||
|
||||
<p>Verifies the developer by its verification_secret.</p>
|
||||
|
||||
<h1 id="SEE-ALSO">SEE ALSO</h1>
|
||||
|
||||
<p><a href="../DB.pm.html">Peace::DB</a>, <a href="../Model/Developer.pm.html">Peace::Model::Developer</a></p>
|
||||
|
@ -19,6 +19,8 @@ sub startup {
|
||||
$r->post('/developer')->to('developer#post');
|
||||
$r->post('/developer/#identifier/application')
|
||||
->to('application#developer_application_post');
|
||||
$r->get('/web/account-verification/#verification_secret')
|
||||
->to('account_verification#verify');
|
||||
}
|
||||
|
||||
sub peace_config {
|
||||
|
57
lib/Peace/Controller/AccountVerification.pm
Normal file
57
lib/Peace/Controller/AccountVerification.pm
Normal file
@ -0,0 +1,57 @@
|
||||
package Peace::Controller::AccountVerification;
|
||||
|
||||
use Mojo::Base 'Mojolicious::Controller';
|
||||
|
||||
use v5.30.0;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Peace;
|
||||
use Peace::DB;
|
||||
use Peace::DAO::Developer;
|
||||
|
||||
sub verify {
|
||||
my $self = shift;
|
||||
my $config = Peace->new->peace_config;
|
||||
my $got_verification_secret = $self->stash->{verification_secret};
|
||||
my $dbh = Peace::DB->dbh( config => $config );
|
||||
my $developer_dao = Peace::DAO::Developer->new( dbh => $dbh );
|
||||
eval {
|
||||
$developer_dao->verify( verification_secret => $got_verification_secret );
|
||||
};
|
||||
if ($@) {
|
||||
$self->render( text => $@, status => '400' );
|
||||
return;
|
||||
}
|
||||
$self->render( text => 'Successfully verified.' );
|
||||
}
|
||||
1;
|
||||
=encoding utf8
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Peace::Controller::AccountVerification - Account verification controller.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
# This class is not to be used in Perl code.
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This class handles account verification from the web.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
Peace::Controller::AccountVerification implements the following methods.
|
||||
|
||||
=head2 verify
|
||||
|
||||
For internal usage.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<Peace::DAO::Developer>
|
||||
|
||||
=cut
|
||||
|
@ -139,6 +139,28 @@ EOF
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
my $validator = validation_for(
|
||||
params => {
|
||||
verification_secret => { type => Str },
|
||||
}
|
||||
);
|
||||
|
||||
sub verify {
|
||||
my $self = shift;
|
||||
my %params = $validator->(@_);
|
||||
my $verification_secret = $params{verification_secret};
|
||||
my $dbh = $self->_dbh;
|
||||
my $result = 0+$dbh->do(<<'EOF', {}, $verification_secret);
|
||||
UPDATE developers SET verified=true WHERE verification_secret=? and not verified;
|
||||
EOF
|
||||
|
||||
if (!$result) {
|
||||
die 'No such developer to verify.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub _dbh {
|
||||
my $self = shift;
|
||||
return $self->{dbh};
|
||||
@ -200,6 +222,12 @@ Recovers the L<Peace::Model::Developer> associated from an uuid from database.
|
||||
|
||||
Recovers the L<Peace::Model::Developer> associated from an identifier from database.
|
||||
|
||||
=head2 verify
|
||||
|
||||
$developer_dao->verify( verification_secret => $verification_secret );
|
||||
|
||||
Verifies the developer by its verification_secret.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<Peace::DB>, L<Peace::Model::Developer>
|
||||
|
Loading…
Reference in New Issue
Block a user