##// END OF EJS Templates
fixes #762, LDAP and container created users are now activated based on...
marcink -
r3470:649ca0cc default
parent child Browse files
Show More
@@ -126,20 +126,16 b' class LoginController(BaseController):'
126 @HasPermissionAnyDecorator('hg.admin', 'hg.register.auto_activate',
126 @HasPermissionAnyDecorator('hg.admin', 'hg.register.auto_activate',
127 'hg.register.manual_activate')
127 'hg.register.manual_activate')
128 def register(self):
128 def register(self):
129 c.auto_active = False
129 c.auto_active = 'hg.register.auto_activate' in User.get_by_username('default')\
130 for perm in User.get_by_username('default').user_perms:
130 .AuthUser.permissions['global']
131 if perm.permission.permission_name == 'hg.register.auto_activate':
132 c.auto_active = True
133 break
134
131
135 if request.POST:
132 if request.POST:
136
137 register_form = RegisterForm()()
133 register_form = RegisterForm()()
138 try:
134 try:
139 form_result = register_form.to_python(dict(request.POST))
135 form_result = register_form.to_python(dict(request.POST))
140 form_result['active'] = c.auto_active
136 form_result['active'] = c.auto_active
141 UserModel().create_registration(form_result)
137 UserModel().create_registration(form_result)
142 h.flash(_('You have successfully registered into rhodecode'),
138 h.flash(_('You have successfully registered into RhodeCode'),
143 category='success')
139 category='success')
144 Session().commit()
140 Session().commit()
145 return redirect(url('login_home'))
141 return redirect(url('login_home'))
@@ -226,6 +226,8 b' def authenticate(username, password):'
226 'name': safe_unicode(get_ldap_attr('ldap_attr_firstname')),
226 'name': safe_unicode(get_ldap_attr('ldap_attr_firstname')),
227 'lastname': safe_unicode(get_ldap_attr('ldap_attr_lastname')),
227 'lastname': safe_unicode(get_ldap_attr('ldap_attr_lastname')),
228 'email': get_ldap_attr('ldap_attr_email'),
228 'email': get_ldap_attr('ldap_attr_email'),
229 'active': 'hg.register.auto_activate' in User\
230 .get_by_username('default').AuthUser.permissions['global']
229 }
231 }
230
232
231 # don't store LDAP password since we don't need it. Override
233 # don't store LDAP password since we don't need it. Override
@@ -254,6 +256,8 b' def login_container_auth(username):'
254 'name': username,
256 'name': username,
255 'lastname': None,
257 'lastname': None,
256 'email': None,
258 'email': None,
259 'active': 'hg.register.auto_activate' in User\
260 .get_by_username('default').AuthUser.permissions['global']
257 }
261 }
258 user = UserModel().create_for_container_auth(username, user_attrs)
262 user = UserModel().create_for_container_auth(username, user_attrs)
259 if not user:
263 if not user:
@@ -399,6 +399,15 b' class User(Base, BaseModel):'
399 def is_admin(self):
399 def is_admin(self):
400 return self.admin
400 return self.admin
401
401
402 @property
403 def AuthUser(self):
404 """
405 Returns instance of AuthUser for this user
406 """
407 from rhodecode.lib.auth import AuthUser
408 return AuthUser(user_id=self.user_id, api_key=self.api_key,
409 username=self.username)
410
402 def __unicode__(self):
411 def __unicode__(self):
403 return u"<%s('id:%s:%s')>" % (self.__class__.__name__,
412 return u"<%s('id:%s:%s')>" % (self.__class__.__name__,
404 self.user_id, self.username)
413 self.user_id, self.username)
General Comments 0
You need to be logged in to leave comments. Login now