public function actionRegister()
 {
     $model = new RegisterForm();
     $processOutput = true;
     $isMobileClient = false;
     // collect user input data
     if (isset($_POST['RegisterForm'])) {
         $isMobileClient = false;
         if (isset($_REQUEST['client']) && $_REQUEST['client'] == 'mobile') {
             $isMobileClient = true;
         }
         $model->attributes = $_POST['RegisterForm'];
         // validate user input and if ok return json data and end application.
         if ($model->validate()) {
             $time = date('Y-m-d h:i:s');
             $userCandidates = new UserCandidates();
             $userCandidates->email = $model->email;
             $userCandidates->realname = $model->name;
             $userCandidates->password = md5($model->password);
             $userCandidates->time = $time;
             if ($userCandidates->save()) {
                 $key = md5($model->email . $time);
                 $message = 'Hi ' . $model->name . ',<br/> <a href="http://' . Yii::app()->request->getServerName() . $this->createUrl('site/activate', array('email' => $model->email, 'key' => $key)) . '">' . 'Click here to register to traceper</a> <br/>';
                 $message .= '<br/> Your Password is :' . $model->password;
                 $message .= '<br/> The Traceper Team';
                 $headers = 'MIME-Version: 1.0' . "\r\n";
                 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                 $headers .= 'From: ' . Yii::app()->params->contactEmail . '' . "\r\n";
                 //echo $message;
                 mail($model->email, "Traceper Activation", $message, $headers);
                 echo CJSON::encode(array("result" => "1"));
             } else {
                 echo CJSON::encode(array("result" => "Unknown error"));
             }
             Yii::app()->end();
         }
         if (Yii::app()->request->isAjaxRequest) {
             $processOutput = false;
         }
     }
     if ($isMobileClient == true) {
         if ($model->getError('password') != null) {
             $result = $model->getError('password');
         } else {
             if ($model->getError('email') != null) {
                 $result = $model->getError('email');
             } else {
                 if ($model->getError('passwordAgain') != null) {
                     $result = $model->getError('passwordAgain');
                 } else {
                     if ($model->getError('passwordAgain') != null) {
                         $result = $model->getError('passwordAgain');
                     }
                 }
             }
         }
         echo CJSON::encode(array("result" => $result));
         Yii::app()->end();
     } else {
         Yii::app()->clientScript->scriptMap['jquery.js'] = false;
         Yii::app()->clientScript->scriptMap['jquery-ui.min.js'] = false;
         $this->renderPartial('register', array('model' => $model), false, $processOutput);
     }
 }