# HG changeset patch # User Marcin Kuzminski # Date 2019-01-15 10:34:50 # Node ID e8cf67e0ea0d789a6592980cda87fd71d44737a3 # Parent 5a371ab1c333107a9e282af6cfd15f60f65238b7 auth: login/registration changes for upcomming new rules for login using external identities. - show session expiration diff --git a/rhodecode/apps/login/tests/test_password_reset.py b/rhodecode/apps/login/tests/test_password_reset.py --- a/rhodecode/apps/login/tests/test_password_reset.py +++ b/rhodecode/apps/login/tests/test_password_reset.py @@ -74,20 +74,17 @@ class TestPasswordReset(TestController): 'default_password_reset': pwd_reset_setting, 'default_extern_activate': 'hg.extern_activate.auto', } - resp = self.app.post(route_path('admin_permissions_application_update'), params=params) + resp = self.app.post( + route_path('admin_permissions_application_update'), params=params) self.logout_user() login_page = self.app.get(route_path('login')) asr_login = AssertResponse(login_page) - index_page = self.app.get(h.route_path('home')) - asr_index = AssertResponse(index_page) if show_link: asr_login.one_element_exists('a.pwd_reset') - asr_index.one_element_exists('a.pwd_reset') else: asr_login.no_element_exists('a.pwd_reset') - asr_index.no_element_exists('a.pwd_reset') response = self.app.get(route_path('reset_password')) diff --git a/rhodecode/authentication/plugins/auth_rhodecode.py b/rhodecode/authentication/plugins/auth_rhodecode.py --- a/rhodecode/authentication/plugins/auth_rhodecode.py +++ b/rhodecode/authentication/plugins/auth_rhodecode.py @@ -24,6 +24,9 @@ RhodeCode authentication plugin for buil import logging +import colander + +from rhodecode.authentication.schema import AuthnPluginSettingsSchemaBase from rhodecode.translation import _ from rhodecode.authentication.base import RhodeCodeAuthPluginBase, hybrid_property @@ -43,6 +46,18 @@ class RhodecodeAuthnResource(AuthnPlugin pass +class RhodeCodeSettingsSchema(AuthnPluginSettingsSchemaBase): + + superadmin_restriction = colander.SchemaNode( + colander.Bool(), + default=False, + description=_('Only allow super-admins to log-in using this plugin.'), + missing=False, + title=_('Enabled'), + widget='bool', + ) + + class RhodeCodeAuthPlugin(RhodeCodeAuthPluginBase): uid = 'rhodecode' @@ -64,6 +79,9 @@ class RhodeCodeAuthPlugin(RhodeCodeAuthP route_name='auth_home', context=RhodecodeAuthnResource) + def get_settings_schema(self): + return RhodeCodeSettingsSchema() + def get_display_name(self): return _('RhodeCode Internal') diff --git a/rhodecode/lib/helpers.py b/rhodecode/lib/helpers.py --- a/rhodecode/lib/helpers.py +++ b/rhodecode/lib/helpers.py @@ -650,10 +650,9 @@ flash = Flash() # SCM FILTERS available via h. #============================================================================== from rhodecode.lib.vcs.utils import author_name, author_email -from rhodecode.lib.utils2 import credentials_filter, age as _age +from rhodecode.lib.utils2 import credentials_filter, age, age_from_seconds from rhodecode.model.db import User, ChangesetStatus -age = _age capitalize = lambda x: x.capitalize() email = author_email short_id = lambda x: x[:12] diff --git a/rhodecode/lib/utils2.py b/rhodecode/lib/utils2.py --- a/rhodecode/lib/utils2.py +++ b/rhodecode/lib/utils2.py @@ -564,6 +564,12 @@ def age(prevdate, now=None, show_short_v return _(u'just now') +def age_from_seconds(seconds): + seconds = safe_int(seconds) or 0 + prevdate = time_to_datetime(time.time() + seconds) + return age(prevdate, show_suffix=False, show_short_version=True) + + def cleaned_uri(uri): """ Quotes '[' and ']' from uri if there is only one of them. diff --git a/rhodecode/public/css/login.less b/rhodecode/public/css/login.less --- a/rhodecode/public/css/login.less +++ b/rhodecode/public/css/login.less @@ -73,9 +73,6 @@ } .sign-in-title { - h1 { - margin: 0; - } h4 { margin: @padding*2 0; diff --git a/rhodecode/templates/base/base.mako b/rhodecode/templates/base/base.mako --- a/rhodecode/templates/base/base.mako +++ b/rhodecode/templates/base/base.mako @@ -299,87 +299,54 @@ <%def name="usermenu(active=False)"> ## USER MENU
  • - - ${gravatar(c.rhodecode_user.email, 20)} - - %if c.rhodecode_user.username != h.DEFAULT_USER: - ${c.rhodecode_user.username}
    - %else: - ${_('Sign in')} - %endif -
    -
    - -
  • diff --git a/rhodecode/templates/login.mako b/rhodecode/templates/login.mako --- a/rhodecode/templates/login.mako +++ b/rhodecode/templates/login.mako @@ -25,17 +25,16 @@
    +
    + <%block name="above_login_button" />
    ${h.form(request.route_path('login', _query={'came_from': c.came_from}), needs_csrf_token=False)} @@ -47,7 +46,12 @@
    %endif - + ${h.password('password', class_='focus')} %if 'password' in errors: ${errors.get('password')} @@ -55,15 +59,25 @@ %endif ${h.checkbox('remember', value=True, checked=defaults.get('remember'))} - + <% timeout = request.registry.settings.get('beaker.session.timeout', '0') %> + % if timeout == '0': + <% remember_label = _('Remember my indefinitely') %> + % else: + <% remember_label = _('Remember me for {}').format(h.age_from_seconds(timeout)) %> + % endif + - %if h.HasPermissionAny('hg.password_reset.enabled')(): - - %elif h.HasPermissionAny('hg.password_reset.hidden')(): + + + %if not h.HasPermissionAny('hg.password_reset.enabled')(): + ## password reset hidden or disabled.

    - ${_('Password reset is disabled. Please contact ')} + ${_('Password reset is disabled.')}
    + ${_('Please contact ')} % if c.visual.rhodecode_support_url: ${_('Support')} ${_('or')} @@ -72,18 +86,18 @@

    %endif - ${h.submit('sign_in', _('Sign In'), class_="btn sign-in")} -

    - RhodeCode ${c.rhodecode_edition} -

    + ${h.submit('sign_in', _('Sign In'), class_="btn sign-in", title=_('Sign in to {}').format(c.rhodecode_edition))} + ${h.end_form()} +
    + <%block name="below_login_button" />
    diff --git a/rhodecode/templates/register.mako b/rhodecode/templates/register.mako --- a/rhodecode/templates/register.mako +++ b/rhodecode/templates/register.mako @@ -118,10 +118,7 @@ ${register_message|n}

    - ${h.submit('sign_up',_('Create Account'),class_="btn sign-in")} -

    - RhodeCode ${c.rhodecode_edition} -

    + ${h.submit('sign_up',_('Create Account'), class_="btn sign-in", title=_('Create Account in {}').format(c.rhodecode_edition))} ${h.end_form()} <%block name="below_register_button" />