Permalink
Browse files

Implementing confirm process

  • Loading branch information...
1 parent 45309a9 commit 2ec3d6092bf0173b9217952dc51711ddb6878a38 Deepwinter committed Jan 19, 2012
Showing with 62 additions and 0 deletions.
  1. +27 −0 classes/confirmation.php
  2. +16 −0 classes/controller/confirmation.php
  3. +7 −0 init.php
  4. +12 −0 tests/classes/ConfirmationTest.php
View
@@ -36,6 +36,33 @@ public function createMessageSubject(){
return i18n::get('confirmation.'.$this->type.'.subject');
}
+ public static function confirm($confirmation_id){
+ $confirmation = ORM::Factory('confirmation')
+ ->where('confirmation_id','=', $confirmation_id)
+ ->find();
+ if(!$confirmation->loaded()){
+ return false;
+ } else {
+ $body = $this->doRoute($confirmation);
+ $confirmation->confirmed=1;
+ $confirmation->save();
+ return $body;
+ }
+ }
+
+ private static function doRoute($confirmation){
+ $route = $confirmation->controller.'/'.$confirmation->action;
+ if($confirmation->arguments){
+ $arguments = json_decode($confirmation->arguments);
+ foreach($arguments as $arg){
+ $route .= $arg.'/';
+ }
+ }
+ $request = Request::Factory($route);
+ $body = $request->execute()->response->body();
+
+ }
+
private function createConfirmationModel(){
$confirmation = ORM::Factory('confirmation');
$confirmation->email = $this->email;
@@ -0,0 +1,16 @@
+<?
+
+Class Controller_Confirmation extends Controller {
+
+ public function action_process($confirmation_id){
+ $confirmed = confirmation::process($confirmation_id);
+
+ if($confirmed){
+ $this->response->body($confirmed);
+ } else {
+ $view = new View('failedConfirmation');
+ $this->response->body($view->render());
+ }
+
+ }
+}
View
@@ -0,0 +1,7 @@
+<?
+
+Route::set('confirmation', 'confirm/<id>')->defaults(array(
+ 'controller' => 'confirmation',
+ 'action' => 'process',
+));
+
@@ -29,5 +29,17 @@ public function testCreateMessageBody($confirmation){
$this->assertNotNull($body);
}
+
+ /**
+ * @depends testConstructConfirmation
+ */
+ public function testConfirm($confirmation){
+ $body = confirmation::confirm($confirmation->id);
+ }
+
+ public function testConfirmFail(){
+ $rval = confirmation::confirm('#&*#$&*#$&*#$&*');
+ $this->assertFalse($rval);
+ }
}

0 comments on commit 2ec3d60

Please sign in to comment.