##// END OF EJS Templates
auth: introduce AuthUser.is_default_user attribute...
Søren Løvborg -
r5545:ba30adf2 default
parent child Browse files
Show More
@@ -69,7 +69,7 b' class GistsController(BaseController):'
69 def index(self):
69 def index(self):
70 """GET /admin/gists: All items in the collection"""
70 """GET /admin/gists: All items in the collection"""
71 # url('gists')
71 # url('gists')
72 not_default_user = c.authuser.username != User.DEFAULT_USER
72 not_default_user = not c.authuser.is_default_user
73 c.show_private = request.GET.get('private') and not_default_user
73 c.show_private = request.GET.get('private') and not_default_user
74 c.show_public = request.GET.get('public') and not_default_user
74 c.show_public = request.GET.get('public') and not_default_user
75
75
@@ -78,11 +78,10 b' class LoginController(BaseController):'
78 else:
78 else:
79 c.came_from = url('home')
79 c.came_from = url('home')
80
80
81 not_default = self.authuser.username != User.DEFAULT_USER
82 ip_allowed = AuthUser.check_ip_allowed(self.authuser, self.ip_addr)
81 ip_allowed = AuthUser.check_ip_allowed(self.authuser, self.ip_addr)
83
82
84 # redirect if already logged in
83 # redirect if already logged in
85 if self.authuser.is_authenticated and not_default and ip_allowed:
84 if self.authuser.is_authenticated and not self.authuser.is_default_user and ip_allowed:
86 raise HTTPFound(location=c.came_from)
85 raise HTTPFound(location=c.came_from)
87
86
88 if request.POST:
87 if request.POST:
@@ -114,8 +114,9 b' class SummaryController(BaseRepoControll'
114 def index(self, repo_name):
114 def index(self, repo_name):
115 _load_changelog_summary()
115 _load_changelog_summary()
116
116
117 username = ''
117 if self.authuser.is_default_user:
118 if self.authuser.username != User.DEFAULT_USER:
118 username = ''
119 else:
119 username = safe_str(self.authuser.username)
120 username = safe_str(self.authuser.username)
120
121
121 _def_clone_uri = _def_clone_uri_by_id = c.clone_uri_tmpl
122 _def_clone_uri = _def_clone_uri_by_id = c.clone_uri_tmpl
@@ -509,7 +509,8 b' class AuthUser(object):'
509 is_user_loaded = self._fill_data(self.anonymous_user)
509 is_user_loaded = self._fill_data(self.anonymous_user)
510
510
511 # The anonymous user is always "logged in".
511 # The anonymous user is always "logged in".
512 if self.user_id == self.anonymous_user.user_id:
512 self.is_default_user = (self.user_id == self.anonymous_user.user_id)
513 if self.is_default_user:
513 self.is_authenticated = True
514 self.is_authenticated = True
514
515
515 if not self.username:
516 if not self.username:
@@ -626,7 +627,7 b' class AuthUser(object):'
626 % (self.user_id, self.username, self.is_authenticated)
627 % (self.user_id, self.username, self.is_authenticated)
627
628
628 def set_authenticated(self, authenticated=True):
629 def set_authenticated(self, authenticated=True):
629 if self.user_id != self.anonymous_user.user_id:
630 if not self.is_default_user:
630 self.is_authenticated = authenticated
631 self.is_authenticated = authenticated
631
632
632 def to_cookie(self):
633 def to_cookie(self):
@@ -816,9 +817,7 b' class NotAnonymous(object):'
816
817
817 log.debug('Checking if user is not anonymous @%s', cls)
818 log.debug('Checking if user is not anonymous @%s', cls)
818
819
819 anonymous = self.user.username == User.DEFAULT_USER
820 if self.user.is_default_user:
820
821 if anonymous:
822 return redirect_to_login(_('You need to be a registered user to '
821 return redirect_to_login(_('You need to be a registered user to '
823 'perform this action'))
822 'perform this action'))
824 else:
823 else:
@@ -848,9 +847,7 b' class PermsDecorator(object):'
848
847
849 else:
848 else:
850 log.debug('Permission denied for %s %s', cls, self.user)
849 log.debug('Permission denied for %s %s', cls, self.user)
851 anonymous = self.user.username == User.DEFAULT_USER
850 if self.user.is_default_user:
852
853 if anonymous:
854 return redirect_to_login(_('You need to be signed in to view this page'))
851 return redirect_to_login(_('You need to be signed in to view this page'))
855 else:
852 else:
856 raise HTTPForbidden()
853 raise HTTPForbidden()
General Comments 0
You need to be logged in to leave comments. Login now