public function actionClaim()
 {
     $this->layout = "home";
     $model = new Users();
     //Check if user has entered the email id or not
     if (isset($_POST['email'])) {
         $_SESSION['claimEmailVal'] = $_POST['email'];
         $_SESSION['claimUniqueCodeVal'] = $_POST['unique_code'];
         $user = Users::model()->findByAttributes(array('email' => $_POST['email']));
         $codeVal = Codes::model()->findByAttributes(array('uniquecode' => $_POST['unique_code']));
         if (!$user) {
             Yii::app()->user->setFlash('email', 'Please enter a registered email address');
         } else {
             if (!$codeVal) {
                 Yii::app()->user->setFlash('failmessage', 'Please try your unique code again');
             } elseif ($codeVal->status == 0) {
                 //updating Codes table for status and other values
                 $updateCodes = Yii::app()->db->createCommand()->update('codes', array('status' => 1, 'date_claimed' => date('Y-m-d H:i:s'), 'claimed_by' => $user['id']), 'uniquecode=:uniquecode', array(':uniquecode' => $codeVal->uniquecode));
                 //updating User table for status
                 $updateUsers = Yii::app()->db->createCommand()->update('users', array('status' => 'Claimed'), 'id=:id', array(':id' => $user->id));
                 //for sending email to users who successfully claims
                 $userFname = $user->first_name;
                 $userEmail = $user->email;
                 $message = new YiiMailMessage();
                 //this points to the file claim.php inside the view path
                 $message->view = "claim";
                 $params = array('name' => $userFname);
                 $message->subject = 'Congratulations';
                 $message->setBody($params, 'text/html');
                 $message->addTo($userEmail);
                 $message->from = '*****@*****.**';
                 Yii::app()->mail->send($message);
                 //for sending email to users who successfully claims ends here
                 session_destroy();
                 session_start();
                 $_SESSION['claimed'] = 'success';
                 $this->redirect(array('success'));
                 //$this->redirect(array('failure'));
             } elseif ($codeVal->status == 1) {
                 session_destroy();
                 session_start();
                 $_SESSION['claimed'] = 'failure';
                 $this->redirect(array('failure'));
             } else {
                 $this->redirect(array('success'));
             }
         }
     }
     $this->render('claim', array('model' => $model));
 }