Moved session user ID to write() call

More accurate reading (e.g. for errors on Security/LoginForm POST requests),
but also avoids cases where DB::getConn() is used before its initialized.
That's the case when a user has "Remmber me" set, in which case
Member::currentUserID() will trigger a Convert::raw2sql() call that
relies on a valid database object to perform its escaping.