diff --git a/doc/index.html b/doc/index.html index 930460e..8020ee5 100644 --- a/doc/index.html +++ b/doc/index.html @@ -8,6 +8,9 @@
  • Peace
  • +
  • + Peace::Controller::AccountVerification +
  • Peace::Controller::Application
  • diff --git a/doc/lib/Peace/Controller/AccountVerification.pm.html b/doc/lib/Peace/Controller/AccountVerification.pm.html new file mode 100644 index 0000000..7996f62 --- /dev/null +++ b/doc/lib/Peace/Controller/AccountVerification.pm.html @@ -0,0 +1,55 @@ + + + + +Peace::Controller::AccountVerification - Account verification controller. + + + + + + + + + + +

    NAME

    + +

    Peace::Controller::AccountVerification - Account verification controller.

    + +

    SYNOPSIS

    + +
    # This class is not to be used in Perl code.
    + +

    DESCRIPTION

    + +

    This class handles account verification from the web.

    + +

    METHODS

    + +

    Peace::Controller::AccountVerification implements the following methods.

    + +

    verify

    + +

    For internal usage.

    + +

    SEE ALSO

    + +

    Peace::DAO::Developer

    + + + + + + + diff --git a/doc/lib/Peace/DAO/Developer.pm.html b/doc/lib/Peace/DAO/Developer.pm.html index 49b8cda..35d1931 100644 --- a/doc/lib/Peace/DAO/Developer.pm.html +++ b/doc/lib/Peace/DAO/Developer.pm.html @@ -25,6 +25,7 @@
  • create
  • recover_by_uuid
  • recover_by_identifier
  • +
  • verify
  • SEE ALSO
  • @@ -80,6 +81,12 @@ my $developer = $developer_dao->recover_by_uuid( uuid => $uuid );Recovers the Peace::Model::Developer associated from an identifier from database.

    +

    verify

    + +
    $developer_dao->verify( verification_secret => $verification_secret );
    + +

    Verifies the developer by its verification_secret.

    +

    SEE ALSO

    Peace::DB, Peace::Model::Developer

    diff --git a/lib/Peace.pm b/lib/Peace.pm index 55369b1..9b057ee 100644 --- a/lib/Peace.pm +++ b/lib/Peace.pm @@ -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 { diff --git a/lib/Peace/Controller/AccountVerification.pm b/lib/Peace/Controller/AccountVerification.pm new file mode 100644 index 0000000..29cd84c --- /dev/null +++ b/lib/Peace/Controller/AccountVerification.pm @@ -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 + +=cut + diff --git a/lib/Peace/DAO/Developer.pm b/lib/Peace/DAO/Developer.pm index d0b1fa0..c699930 100644 --- a/lib/Peace/DAO/Developer.pm +++ b/lib/Peace/DAO/Developer.pm @@ -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 associated from an uuid from database. Recovers the L 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, L