Skip to content

Commit

Permalink
Add initial user activation page
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbennett committed Aug 23, 2019
1 parent 9b56ca0 commit 3c34650
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/controllers/User/Activate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace BNETDocs\Controllers\User;

use \BNETDocs\Models\User\Activate as UserActivateModel;
use \CarlBennett\MVC\Libraries\Common;
use \CarlBennett\MVC\Libraries\Controller;
use \CarlBennett\MVC\Libraries\Router;
use \CarlBennett\MVC\Libraries\View;

class Activate extends Controller {

public function &run( Router &$router, View &$view, array &$args ) {

$model = new UserActivateModel();

$data = $router->getRequestQueryArray();

$model->token = isset( $data[ 't' ] ) ? $data[ 't' ] : null;
$model->error = 'INVALID_TOKEN';

$view->render( $model );

$model->_responseCode = 200;
$model->_responseHeaders[ 'Content-Type' ] = $view->getMimeType();
$model->_responseTTL = 0;

return $model;

}

}
3 changes: 3 additions & 0 deletions src/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ function main() {
$router->addRoute( // URL: /user/:id
"#^/user/(\d+)/?#", "User\\View", "User\\ViewHtml"
);
$router->addRoute( // URL: /user/activate
"#^/user/activate/?$#", "User\\Activate", "User\\ActivateHtml"
);
$router->addRoute( // URL: /user/changepassword
"#^/user/changepassword/?$#",
"User\\ChangePassword", "User\\ChangePasswordHtml"
Expand Down
12 changes: 12 additions & 0 deletions src/models/User/Activate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace BNETDocs\Models\User;

use \CarlBennett\MVC\Libraries\Model;

class Activate extends Model {

public $token;
public $error;

}
60 changes: 60 additions & 0 deletions src/templates/User/Activate.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace BNETDocs\Templates\User;

use \CarlBennett\MVC\Libraries\Common;
use \CarlBennett\MVC\Libraries\Pair;

$title = 'Activate Account';
$description = 'This form allows an individual to activate their account with a token.';
$this->opengraph->attach( new Pair( 'url', '/user/activate' ));

switch ( $this->getContext()->error ) {
case 'INVALID_TOKEN':
$message = 'The token is expired or invalid and therefore cannot be used.';
break;
default:
$message = $this->getContext()->error;
}

$this->additional_css[] = '/a/forms.css';
require('./header.inc.phtml');
?>
<article>
<?php if ($this->getContext()->error !== false) { ?>
<header>Activate Account</header>
<?php if (!empty($message)) { ?>
<section class="red">
<p><?php echo $message; ?></p>
</section>
<?php } ?>
<form method="GET" action="?">
<section>
<label for="t">Token:</label><br/>
<input
type="text"
name="t"
id="token"
value="<?php echo filter_var($this->getContext()->token, FILTER_SANITIZE_FULL_SPECIAL_CHARS); ?>"
tabindex="1"
required
autofocus="autofocus"
/>
</section>
<section>
<input
type="submit"
value="Activate Account"
tabindex="2"
/>
</section>
</form>
<?php } else { ?>
<header class="green">Account Activated</header>
<section class="green">
<p>Your account has been activated successfully!</p>
<p>Use the navigation to the left to move to another page.</p>
</section>
<?php } ?>
</article>
<?php require('./footer.inc.phtml'); ?>
25 changes: 25 additions & 0 deletions src/views/User/ActivateHtml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace BNETDocs\Views\User;

use \BNETDocs\Models\User\Activate as UserActivateModel;

use \CarlBennett\MVC\Libraries\Exceptions\IncorrectModelException;
use \CarlBennett\MVC\Libraries\Model;
use \CarlBennett\MVC\Libraries\Template;
use \CarlBennett\MVC\Libraries\View;

class ActivateHtml extends View {

public function getMimeType() {
return 'text/html;charset=utf-8';
}

public function render( Model &$model ) {
if (!$model instanceof UserActivateModel) {
throw new IncorrectModelException();
}
(new Template( $model, 'User/Activate' ))->render();
}

}

0 comments on commit 3c34650

Please sign in to comment.