'Handle Galaxy Log in'

@web.expose
def login(self, trans, refresh_frames=[], **kwd):

    referer = (trans.request.referer or '')
    redirect = self.__get_redirect_url(kwd.get('redirect', referer).strip())
    redirect_url = ''
    use_panels = util.string_as_bool(kwd.get('use_panels', False))
    message = kwd.get('message', '')
    status = kwd.get('status', 'done')
    header = ''
    user = trans.user
    login = kwd.get('login', '')
    if user:
        redirect_url = redirect
        message = 'You    are    already    logged    in.'
        status = 'info'
    elif kwd.get('login_button', False):
        if ((trans.webapp.name == 'galaxy') and (not refresh_frames)):
            if trans.app.config.require_login:
                refresh_frames = ['masthead', 'history', 'tools']
            else:
                refresh_frames = ['masthead', 'history']
        csrf_check = trans.check_csrf_token()
        if csrf_check:
            return csrf_check
        (message, status, user, success) = self.__validate_login(trans, **kwd)
        if success:
            redirect_url = redirect
    if ((not user) and trans.app.config.require_login):
        if trans.app.config.allow_user_creation:
            create_account_str = ("        If    you    don't    already    have    an    account,    <a    href='%s'>you    may    create    one</a>." % web.url_for(controller='user', action='create', cntrller='user'))
            if (trans.webapp.name == 'galaxy'):
                header = (REQUIRE_LOGIN_TEMPLATE % ('Galaxy    instance', create_account_str))
            else:
                header = (REQUIRE_LOGIN_TEMPLATE % ('Galaxy    tool    shed', create_account_str))
        elif (trans.webapp.name == 'galaxy'):
            header = (REQUIRE_LOGIN_TEMPLATE % ('Galaxy    instance', ''))
        else:
            header = (REQUIRE_LOGIN_TEMPLATE % ('Galaxy    tool    shed', ''))
    return trans.fill_template('/user/login.mako', login=login, header=header, use_panels=use_panels, redirect_url=redirect_url, redirect=redirect, refresh_frames=refresh_frames, message=message, status=status, openid_providers=trans.app.openid_providers, form_input_auto_focus=True, active_view='user')
