(Bug 5265) Check if $u is defined first

Because logged out users can view the account settings page, which means
$u may be undefined here.