
use File::Path;

sub MyBtnLogin()
{
   my $cSessionId;

   $cSessionId =
       ($oDbSessionGL->SqlSelect
        ("SELECT session_id
	  FROM wwwdb_state
          WHERE
             key_name  = 'login' AND
             key_value = ?",
         sprintf("%s,%s",
                 &GetField("username"),
                 crypt(&GetField("password"), "WW"))))->[0]->[0];


   unless ($cSessionId)
   {
      &OkForm("ERROR",
              b(i18n("Eh!!????")) .
              "<BR>" .
              i18n("Not with this password!!!!!"));

   }
   else
   {
      $oDbSessionGL->SqlDo
          ("DELETE FROM wwwdb_state
            WHERE
                session_id = ? AND
                key_name   = 'ActualLogin'",
           $cSessionId);


      $oDbSessionGL->SqlDo
          ("INSERT INTO wwwdb_state
               (session_id, key_name, key_value, last_change)
            VALUES
               (?, 'ActualLogin', '1', ?)",
           $cSessionId,
           $oDbSessionGL->DateToDb(scalar(localtime())));

      # clear the cache
      {
         my $cCacheDir =  sprintf ('%s/tmp/cache/%s/%s',
                                   $ENV{"WWWDB_BASE_PATH"},
                                   &GetAttr("DbDriver"),
                                   &GetAttr("SessionId"));
         rmtree($cCacheDir);

         # delete all cach-files from this user
         #&CGI::Cache::SetRoot($cCacheDir);
         #&CGI::Cache::ExpireLRU(1);
         #$iCacheTimeoutMGL = 0;

         # dump out the cache-file, when the timeout is set
         &CGI::Cache::Stop(0);
      }

      &Redirect($cSessionId, "WWWdb:Index");
   }

}

1;

