Permalink
Browse files

Added full confirm and call custom controller support.

  • Loading branch information...
Deepwinter
Deepwinter committed Jan 20, 2012
1 parent 2ec3d60 commit 2981563b530e12fc7baf93088a6ef1edae414e2a
View
@@ -28,7 +28,7 @@ public function send(){
public function createMessageBody(){
$body = i18n::get('confirmation.'.$this->type.'.body');
- $confirmationLink = url::base('confirmation/'.$this->model->confirmation_id, 'http');
+ $confirmationLink = url::base('http').'confirmation/'.$this->model->confirmation_id;
return str_replace(':confirmationLink', $confirmationLink, $body);
}
@@ -40,10 +40,10 @@ public static function confirm($confirmation_id){
$confirmation = ORM::Factory('confirmation')
->where('confirmation_id','=', $confirmation_id)
->find();
- if(!$confirmation->loaded()){
+ if(!$confirmation->loaded() || $confirmation->confirmed){
return false;
} else {
- $body = $this->doRoute($confirmation);
+ $body = self::doRoute($confirmation);
$confirmation->confirmed=1;
$confirmation->save();
return $body;
@@ -55,11 +55,12 @@ private static function doRoute($confirmation){
if($confirmation->arguments){
$arguments = json_decode($confirmation->arguments);
foreach($arguments as $arg){
- $route .= $arg.'/';
+ $route .= '/'.$arg;
}
}
$request = Request::Factory($route);
- $body = $request->execute()->response->body();
+ $body = $request->execute()->body();
+ return $body;
}
@@ -2,8 +2,8 @@
Class Controller_Confirmation extends Controller {
- public function action_process($confirmation_id){
- $confirmed = confirmation::process($confirmation_id);
+ public function action_confirm($confirmation_id){
+ $confirmed = confirmation::confirm($confirmation_id);
if($confirmed){
$this->response->body($confirmed);
@@ -0,0 +1,16 @@
+<?
+
+Class Controller_ConfirmationExample extends Controller {
+
+ public function action_sendExample($email='deepwinter@winterroot.net'){
+ $confirmation = new Confirmation('example', $email, 'confirmationexample', 'confirm', array('id') );
+ echo $confirmation->createMessageBody();
+ die();
+ $confirmation->send();
+ echo 'Example Sent';
+ }
+
+ public function action_confirm($id){
+ $this->response->body("You've been confirmed, thanks for using the example controller");
+ }
+}
View
@@ -2,8 +2,9 @@
$lang = array(
'confirmation.default.subject' => 'Confirm your information',
- 'confirmation.default.body' => "Clink the link to confirm your information
- :link",
+ 'confirmation.default.body' => 'Clink the link to confirm your information <a href=":confirmationLink">:confirmationLink</a>',
+ 'confirmation.example.subject' => 'Example: Confirm your information',
+ 'confirmation.example.body' => 'Example: Clink the link to confirm your information <a href=":confirmationLink">:confirmationLink</a>',
);
return $lang;
View
@@ -1,7 +1,7 @@
<?
-Route::set('confirmation', 'confirm/<id>')->defaults(array(
+Route::set('confirmation', 'confirmation/<id>')->defaults(array(
'controller' => 'confirmation',
- 'action' => 'process',
+ 'action' => 'confirm',
));
View
@@ -1,10 +1,13 @@
CREATE TABLE `confirmations` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`confirmation_id` varchar(100) CHARACTER SET latin1 NOT NULL,
+ `type` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`controller` varchar(100) CHARACTER SET latin1 NOT NULL,
`action` varchar(100) CHARACTER SET latin1 NOT NULL,
- `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- `timeouthours` int(11) NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
+ `arguments` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `timeouthours` int(11) NOT NULL DEFAULT '5',
+ `confirmed` tinyint(1) NOT NULL DEFAULT '0',
+ PRIMARY KEY (`id`,`confirmation_id`)
+) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
@@ -0,0 +1 @@
+Your confirmation link was invalid or has expired.

0 comments on commit 2981563

Please sign in to comment.