/**
  * Displays the login page
  */
 public function actionRegister()
 {
     $model = new RegisterForm();
     // if it is ajax validation request
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'register-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     // collect user input data
     if (isset($_POST['RegisterForm'])) {
         $model->attributes = $_POST['RegisterForm'];
         // validate user input and redirect to the previous page if valid
         if ($model->validate()) {
             $user = new User();
             $user->username = $model->username;
             $user->password = $user->createHash($model->password);
             $user->email = $model->email;
             //generate activation code
             $activationcode = $user->createHash($this->createRandomPassword());
             $user->activationcode = $activationcode;
             $user->activated = 0;
             $user->registration_date = new CDbExpression('NOW()');
             $user->last_login_date = new CDbExpression('NOW()');
             $user->last_login_ip = 'asdsa';
             //CHttpRequest::getUserHostAddress();
             if ($user->save()) {
                 $profile = new Profile();
                 $profile->user_id = $user->id;
                 $profile->emailNewsLetter = $model->emailNewsLetter;
                 $profile->emailUpdates = $model->emailUpdates;
                 $profile->last_emailed = new CDbExpression('FROM_UNIXTIME(' . time() . ')');
                 $profile->save();
                 if (!$this->sendRegistrationEmail($user)) {
                     $this->render('message', array('title' => 'Registration Error', 'message' => 'There was a problem during registration.'));
                 } else {
                     $this->render('message', array('title' => 'Account Registered', 'message' => 'You have successfully registered. You have been emailed an activation code. Sometimes it gets caught by the spam filter. I am working on that. If you dont see it, please check your junk/spam email box. I appreciate your patience.'));
                 }
             } else {
                 $this->render('message', array('title' => 'Registration Error', 'message' => 'There was a problem during registration.'));
             }
         } else {
             $this->render('register', array('model' => $model));
         }
         return null;
     }
     // display the login form
     $this->render('register', array('model' => $model));
 }