def connect(self, uid, passwd, comp): if (uid != '' and passwd != '' and self.ldap_engine.check_password(uid, passwd)): data_user = usermanager.UserManager.get_by_username(uid) profile = self.ldap_engine.get_profile(uid, passwd) # if user exists update data if profile['picture']: self.assets_manager.save(profile['picture'], uid, {'filename': uid}) picture = self.assets_manager.get_image_url(uid, 'thumb') else: picture = None if not data_user: data_user = usermanager.UserManager().create_user( uid, None, profile['name'], profile['email'], source='ldap', picture=picture) data_user.update(profile['name'], profile['email'], picture=picture) database.session.flush() u = usermanager.UserManager.get_app_user(uid, data=data_user) security.set_user(u) comp.answer(u) else: self.error_message = _('Login failed')
def log_in(self, comp): u = security.get_user() # If user is not local user remove user from security if u and not u.is_local: security.set_user(None) u = None if u is not None: database.session.flush() comp.answer(u) else: self._error_message = _('Login failed')
def start_request(self, root, request, response): """A new request is received, setup its dedicated environment In: - ``root`` -- the application root component - ``request`` -- the web request object - ``response`` -- the web response object """ security.set_manager(self.security) # Set the security manager security.set_user(self.security.create_user(request, response)) # Create the User object self.set_locale(self.default_locale) # Set the default Locale
def start_request(self, root, request, response): """A new request is received, setup its dedicated environment In: - ``root`` -- the application root component - ``request`` -- the web request object - ``response`` -- the web response object """ security.set_manager(self.security) # Set the security manager security.set_user(self.security.create_user( request, response)) # Create the User object self.set_locale(self.default_locale) # Set the default Locale
def authenticate(self, **params): if get_user() is not None: return None, None set_manager(self) # Retrieve the data associated with the connected user principal, credentials, response = self.get_principal(**params) user = self.create_user(principal, **credentials) if isinstance(user, User): user.credentials.setdefault('principal', principal) for k, v in credentials.items(): user.credentials.setdefault(k, v) set_user(user) return user, response
def connect(self, oauth_user, source): if oauth_user is None: u = None else: profile = oauth_user.get_profile()[0] data_user = usermanager.UserManager.get_by_username(profile['id']) # if user exists update data if not data_user: u = profile data_user = usermanager.UserManager().create_user(profile['id'], None, profile.get('name'), profile['email'], source=source, picture=profile.get('picture')) data_user.update(profile.get('name'), profile['email'], picture=profile.get('picture')) database.session.flush() u = usermanager.get_app_user(profile['id'], data=data_user) security.set_user(u) return u
def connect(self, comp, oauth_user, source): if oauth_user is None: self._error_message = i18n._(u'Authentication failed') return profile = oauth_user.get_profile()[0] profile_id = profile['id'] # if user exists update data name = profile['name'] or (i18n._(u'Please provide a full name in %s') % source) if not usermanager.UserManager.get_by_username(profile_id): usermanager.UserManager().create_user(profile['id'], None, name, profile['email'], source=source, picture=profile.get('picture')) # update takes care of not overwriting the existing email with an empty one usermanager.UserManager.get_by_username(profile_id).update(name, profile['email'], picture=profile.get('picture')) # thus if data_user.email is empty, that means it has always been so. if not usermanager.UserManager.get_by_username(profile_id).email: self.content.call( self.services_service( RegistrationTask, self.app_title, self.app_banner, self.theme, username=profile_id ) ) return database.session.flush() u = usermanager.UserManager.get_app_user(profile['id'], data=usermanager.UserManager.get_by_username(profile_id)) security.set_user(u) # After a successful OAuth authentication, we need to manually switch to the user's locale # so the first rendering phase uses the correct language i18n.set_locale(u.get_locale()) comp.answer(u)
def connect(self, uid, passwd, comp): if (uid != '' and passwd != '' and self.ldap_engine.check_password(uid, passwd)): data_user = usermanager.UserManager.get_by_username(uid) profile = self.ldap_engine.get_profile(uid, passwd) # if user exists update data if profile['picture']: self.assetsmanager.save(profile['picture'], uid, {'filename': uid}) picture = self.assetsmanager.get_image_url(uid, 'thumb') else: picture = None if not data_user: data_user = usermanager.UserManager().create_user(uid, None, profile['name'], profile['email'], source='ldap', picture=picture) data_user.update(profile['name'], profile['email'], picture=picture) database.session.flush() u = usermanager.get_app_user(uid, data=data_user) security.set_user(u) comp.answer(u) else: self.error_message = _('Login failed')
def __exit__(self, *args, **kw): """Pop this user from the stack """ security.set_user(self._previous_user)
def __enter__(self): """Push this user to the stack """ self._previous_user = security.get_user() security.set_user(self)
def set_context(user=None): """ """ local.request = local.Thread() security.set_user(user) security.set_manager(SecurityManager('somekey'))
def set_dummy_context(): """Set a dummy context for security permission checks """ local.request = local.Thread() security.set_user(None) security.set_manager(DummySecurityManager())