Show More
@@ -700,13 +700,16 b' def set_available_permissions(config):' | |||||
700 | # CHECK DECORATORS |
|
700 | # CHECK DECORATORS | |
701 | #============================================================================== |
|
701 | #============================================================================== | |
702 |
|
702 | |||
703 | def redirect_to_login(message=None): |
|
703 | def _redirect_to_login(message=None): | |
|
704 | """Return an exception that must be raised. It will redirect to the login | |||
|
705 | page which will redirect back to the current URL after authentication. | |||
|
706 | The optional message will be shown in a flash message.""" | |||
704 | from kallithea.lib import helpers as h |
|
707 | from kallithea.lib import helpers as h | |
705 | p = request.path_qs |
|
|||
706 | if message: |
|
708 | if message: | |
707 | h.flash(h.literal(message), category='warning') |
|
709 | h.flash(h.literal(message), category='warning') | |
|
710 | p = request.path_qs | |||
708 | log.debug('Redirecting to login page, origin: %s', p) |
|
711 | log.debug('Redirecting to login page, origin: %s', p) | |
709 |
r |
|
712 | return HTTPFound(location=url('login_home', came_from=p)) | |
710 |
|
713 | |||
711 |
|
714 | |||
712 | class LoginRequired(object): |
|
715 | class LoginRequired(object): | |
@@ -731,7 +734,7 b' class LoginRequired(object):' | |||||
731 | log.debug('Checking access for user %s @ %s', user, loc) |
|
734 | log.debug('Checking access for user %s @ %s', user, loc) | |
732 |
|
735 | |||
733 | if not AuthUser.check_ip_allowed(user, controller.ip_addr): |
|
736 | if not AuthUser.check_ip_allowed(user, controller.ip_addr): | |
734 |
re |
|
737 | raise _redirect_to_login(_('IP %s not allowed') % controller.ip_addr) | |
735 |
|
738 | |||
736 | # check if we used an API key and it's a valid one |
|
739 | # check if we used an API key and it's a valid one | |
737 | api_key = request.GET.get('api_key') |
|
740 | api_key = request.GET.get('api_key') | |
@@ -744,7 +747,7 b' class LoginRequired(object):' | |||||
744 | return func(*fargs, **fkwargs) |
|
747 | return func(*fargs, **fkwargs) | |
745 | else: |
|
748 | else: | |
746 | log.warning('API key ****%s is NOT valid', api_key[-4:]) |
|
749 | log.warning('API key ****%s is NOT valid', api_key[-4:]) | |
747 |
re |
|
750 | raise _redirect_to_login(_('Invalid API key')) | |
748 | else: |
|
751 | else: | |
749 | # controller does not allow API access |
|
752 | # controller does not allow API access | |
750 | log.warning('API access to %s is not allowed', loc) |
|
753 | log.warning('API access to %s is not allowed', loc) | |
@@ -790,7 +793,7 b' class LoginRequired(object):' | |||||
790 | return func(*fargs, **fkwargs) |
|
793 | return func(*fargs, **fkwargs) | |
791 | else: |
|
794 | else: | |
792 | log.warning('user %s NOT authenticated with regular auth @ %s', user, loc) |
|
795 | log.warning('user %s NOT authenticated with regular auth @ %s', user, loc) | |
793 |
re |
|
796 | raise _redirect_to_login() | |
794 |
|
797 | |||
795 | class NotAnonymous(object): |
|
798 | class NotAnonymous(object): | |
796 | """ |
|
799 | """ | |
@@ -807,8 +810,8 b' class NotAnonymous(object):' | |||||
807 | log.debug('Checking if user is not anonymous @%s', cls) |
|
810 | log.debug('Checking if user is not anonymous @%s', cls) | |
808 |
|
811 | |||
809 | if self.user.is_default_user: |
|
812 | if self.user.is_default_user: | |
810 |
re |
|
813 | raise _redirect_to_login(_('You need to be a registered user to ' | |
811 | 'perform this action')) |
|
814 | 'perform this action')) | |
812 | else: |
|
815 | else: | |
813 | return func(*fargs, **fkwargs) |
|
816 | return func(*fargs, **fkwargs) | |
814 |
|
817 | |||
@@ -837,7 +840,7 b' class PermsDecorator(object):' | |||||
837 | else: |
|
840 | else: | |
838 | log.debug('Permission denied for %s %s', cls, self.user) |
|
841 | log.debug('Permission denied for %s %s', cls, self.user) | |
839 | if self.user.is_default_user: |
|
842 | if self.user.is_default_user: | |
840 |
re |
|
843 | raise _redirect_to_login(_('You need to be signed in to view this page')) | |
841 | else: |
|
844 | else: | |
842 | raise HTTPForbidden() |
|
845 | raise HTTPForbidden() | |
843 |
|
846 |
General Comments 0
You need to be logged in to leave comments.
Login now