move ajax_login to separate function