/**
  * Set VerificationString if not set
  * If not verified log out user and display message.
  */
 function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (!$this->owner->VerificationString) {
         $this->owner->VerificationString = MD5(rand());
     }
     if (!$this->owner->Verified) {
         if (!$this->owner->VerificationEmailSent) {
             if (!self::$hasOnBeforeWrite) {
                 self::$hasOnBeforeWrite = true;
                 $this->owner->sendemail($this->owner, false);
             }
         }
         if (Member::currentUserID() && $this->owner->Email == Member::currentUser()->Email) {
             Security::logout(false);
             if (!is_null(Controller::redirectedTo())) {
                 $messageSet = array('default' => _t('EmailVerifiedMember.EMAILVERIFY', 'Please verify your email address by clicking on the link in the email before logging in.'));
             }
             Session::set("Security.Message.type", 'bad');
             Security::permissionFailure(Controller::curr(), $messageSet);
         } else {
             return;
         }
     } else {
         return;
     }
 }