def test_playlist_get_all_empty(self): from balistos.models.playlist import Playlist playlist = Playlist.get('test_playlist') Session.delete(playlist) Session.flush() self.assertEqual(0, Playlist.get_all().count()) self.assertIsNone(Playlist.get('test_playlist'))
def test_unique_constraint(self): Session.add(UserProperty(key='foo', user_id=1)) Session.flush() with self.assertRaises(IntegrityError) as cm: Session.add(UserProperty(key='foo', user_id=1)) Session.flush() self.assertIn('key, user_id are not unique', cm.exception.message)
def includeme(config): registry = config.registry settings = registry.settings config.include('pyramid_basemodel') config.include('pyramid_tm') models = [(interfaces.IActivationClass, Activation), (interfaces.IUserClass, User), (interfaces.IUIStrings, UIStringsBase), (IConsumerClass, Consumer), (IDBSession, Session)] for iface, imp in models: if not registry.queryUtility(iface): registry.registerUtility(imp, iface) if asbool(settings.get('basemodel.should_create_all', True)): key = settings['api.key'] secret = settings.get('api.secret') ttl = settings.get('api.ttl', auth.DEFAULT_TTL) session = Session() consumer = session.query(Consumer).filter(Consumer.key == key).first() if not consumer: with transaction.manager: consumer = Consumer(key=key, secret=secret, ttl=ttl) session.add(consumer) session.flush()
def test_user_get_all_empty(self): from balistos.models.user import User user = User.get_by_username('test_user') Session.delete(user) Session.flush() self.assertEqual(0, User.get_all().count()) self.assertIsNone(User.get_by_username('test_user'))
def submit_success(self, appstruct): user = User( email=appstruct.get('email'), fullname=appstruct.get('fullname'), affiliate=appstruct.get('affiliate'), billing_email=appstruct.get('billing_email'), valid_to=appstruct.get('valid_to'), last_payment=appstruct.get('last_payment'), groups=[Group.by_id(group_id) for group_id in appstruct.get('groups', [])], # noqa properties=[UserProperty(key=prop.get('key'), value=prop.get('value')) # noqa for prop in appstruct.get('properties', [])], ) if appstruct.get('password'): # pragma: no branch user.password = encrypt(appstruct['password']) Session.add(user) Session.flush() self.request.registry.notify( UserCreated( self.request, user, appstruct.get('password'), u'Created manually by {}'.format(self.request.user.email) ) ) self.request.session.flash(u'User "{}" added.'.format(user.email)) return HTTPFound( location=self.request.route_path('user_view', user_id=user.id))
def setUp(self): from pyramid_bimt.views import DatatablesDataView from pyramid_bimt.models import AuditLogEntry from pyramid_bimt.models import User self.config = testing.setUp() initTestingDB(auditlog_types=True, users=True, groups=True) self.request = testing.DummyRequest(user=User.by_email('*****@*****.**')) self.view = DatatablesDataView(self.request) self.view.model = mock.Mock() self.view.columns = OrderedDict() self.view.columns['foo'] = None self.view.columns['bar'] = None Session.add( AuditLogEntry(user=User.by_email('*****@*****.**'), comment=u'föo')) Session.add( AuditLogEntry(user=User.by_email('*****@*****.**'), comment=u'bar')) Session.flush() class DummyDatatablesAJAXView(DatatablesDataView): model = AuditLogEntry columns = OrderedDict() columns['id'] = None columns['comment'] = None def populate_columns(self, entry): self.columns['id'] = entry.id self.columns['comment'] = entry.comment self.columns['DT_RowClass'] = 'info' self.datatable_view = DummyDatatablesAJAXView
def includeme(config): registry = config.registry config.include('pyramid_basemodel') config.include('pyramid_tm') config.set_request_property(lib.user_property, 'user') if not registry.queryUtility(IDBSession): registry.registerUtility(Session, IDBSession) if not registry.queryUtility(interfaces.IUserClass): registry.registerUtility(User, interfaces.IUserClass) if not registry.queryUtility(interfaces.IConsumerClass): registry.registerUtility(Consumer, interfaces.IConsumerClass) if not registry.queryUtility(interfaces.IActivationClass): registry.registerUtility(Activation, interfaces.IActivationClass) settings = config.get_settings() key = settings['api.key'] secret = settings.get('api.secret') ttl = settings.get('api.ttl', DEFAULT_TTL) session = Session() with transaction.manager: consumer = Consumer.get_by_key(key) if not consumer: consumer = Consumer(key=key) consumer.secret = secret consumer.ttl = ttl session.add(consumer) session.flush() registry.consumer = consumer
def includeme(config): registry = config.registry settings = registry.settings config.include('pyramid_basemodel') config.include('pyramid_tm') models = [ (IActivationClass, Activation), (IUserClass, User), (IUIStrings, UIStringsBase), (IConsumerClass, Consumer), (IDBSession, Session) ] for iface, imp in models: if not registry.queryUtility(iface): registry.registerUtility(imp, iface) if asbool(settings.get('basemodel.should_create_all', True)): key = settings['api.key'] secret = settings.get('api.secret') ttl = settings.get('api.ttl', auth.DEFAULT_TTL) session = Session() consumer = session.query(Consumer).filter(Consumer.key == key).first() if not consumer: with transaction.manager: consumer = Consumer(key=key, secret=secret, ttl=ttl) session.add(consumer) session.flush()
def test_add_pclip(self): from balistos.models.clip import PlaylistClip from balistos.models.clip import Clip from balistos.models.playlist import Playlist from datetime import datetime playlist = Playlist(uri='test', title=u'Test') clip = Clip( youtube_video_id='test', title=u'Test', likes=5, image_url='test_url', duration=1 ) Session.add(clip) Session.add(playlist) Session.flush() pclip = PlaylistClip( playlist=playlist, clip=clip, likes=0, state=0, added=datetime.now() ) Session.add(pclip) Session.flush() pclip = PlaylistClip.get_by_playlist_and_clip(playlist, clip) self.assertEqual(playlist, pclip.playlist) self.assertEqual(clip, pclip.clip) self.assertEqual(0, pclip.state) self.assertEqual(0, pclip.likes)
def test_billing_email_is_unique(self): _make_user(billing_email='*****@*****.**') _make_user(billing_email='*****@*****.**') with self.assertRaises(IntegrityError) as cm: Session.flush() self.assertIn( 'column billing_email is not unique', cm.exception.message)
def setUp(self): self.config = testing.setUp() initTestingDB(groups=True) Group.by_id(1).product_id = 'old_id' Session.flush() self.request = testing.DummyRequest()
def submit_success(self, appstruct): group = Group( name=appstruct.get('name'), product_id=appstruct.get('product_id'), validity=appstruct.get('validity'), trial_validity=appstruct.get('trial_validity'), addon=appstruct.get('addon'), forward_ipn_to_url=appstruct.get('forward_ipn_to_url'), users=[ User.by_id(user_id) for user_id in appstruct.get('users', []) ], # noqa upgrade_groups=[ Group.by_id(group_id) for group_id in appstruct.get('upgrade_groups', []) ], # noqa properties=[ GroupProperty(key=prop['key'], value=prop['value']) for prop in appstruct.get('properties', []) ], ) Session.add(group) Session.flush() self.request.session.flash(u'Group "{}" added.'.format(group.name)) return HTTPFound( location=self.request.route_path('group_edit', group_id=group.id))
def includeme(config): registry = config.registry config.include('pyramid_basemodel') config.include('pyramid_tm') config.set_request_property(lib.user_property, 'user') if not registry.queryUtility(interfaces.IDBSession): registry.registerUtility(Session, interfaces.IDBSession) if not registry.queryUtility(interfaces.IUserClass): registry.registerUtility(User, interfaces.IUserClass) if not registry.queryUtility(interfaces.IConsumerClass): registry.registerUtility(Consumer, interfaces.IConsumerClass) if not registry.queryUtility(interfaces.IActivationClass): registry.registerUtility(Activation, interfaces.IActivationClass) settings = config.get_settings() key = settings['api.key'] secret = settings.get('api.secret') ttl = settings.get('api.ttl', DEFAULT_TTL) session = Session() with transaction.manager: consumer = Consumer.get_by_key(key) if not consumer: consumer = Consumer(key=key) consumer.secret = secret consumer.ttl = ttl session.add(consumer) session.flush() registry.consumer = consumer
def get_or_create_user_by_email(email, cls=User): """Gets or creates an user given an email.""" # If the email is in the database we just return its user. # First try by confirmed then just any email. db_email = Email.query.filter_by(address=email, is_confirmed=True).first() if db_email: return db_email.user # Now just by email. db_email = Email.query.filter_by(address=email).first() if db_email: return db_email.user # If we got this far it doesn't exist, create a new user... username = generate_random_digest(num_bytes=15) # Build a dict with keys that the user_cls.factory method expects. # Note that the raw password will be encrypted before being saved. data = { 'password': '', 'username': username, } user = cls(**data) Session.add(user) db_email = Email(user=user, address=email) Session.add(db_email) Session.flush() return user
def test_pclip_get_all_empty(self): from balistos.models.clip import PlaylistClip pclips = PlaylistClip.get_all() for pclip in pclips: Session.delete(pclip) Session.flush() self.assertEqual(0, PlaylistClip.get_all().count()) self.assertEqual(0, PlaylistClip.get_all().count())
def test_clip_get_all_empty(self): from balistos.models.clip import Clip clips = Clip.get_all() for clip in clips: Session.delete(clip) Session.flush() self.assertEqual(0, Clip.get_all().count()) self.assertIsNone(Clip.get('cpV0ygkmhP4'))
def test_add_user_username_only(self): from balistos.models.user import User user = User(username='******') Session.add(user) Session.flush() user = User.get_by_username('test') self.assertEqual('test', user.username) self.assertIsNone(user.email) self.assertIsNone(user.fullname)
def test_add_playlist(self): from balistos.models.playlist import Playlist playlist = Playlist(uri='test', title=u'Test') Session.add(playlist) Session.flush() playlist = Playlist.get('test') self.assertEqual('test', playlist.uri) self.assertEqual(u'Test', playlist.title)
def test_disabled_correct(self): self.user.disable() self._make_disabled_entry() Session.flush() from pyramid_bimt.sanitycheck import CheckUsersEnabledDisabled self.assertEqual( CheckUsersEnabledDisabled()(), [], )
def test_populate_columns_entry_without_user(self): self.config.testing_securitypolicy(userid='*****@*****.**', permissive=False) Session.delete(User.by_id(3)) Session.flush() view = self._make_view() self.assertEqual(view.columns['comment'], u'unread entry') self.assertEqual(view.columns['event_type_id'], 'User Changed Password') self.assertEqual(view.columns['user_id'], None) self.assertEqual(view.columns['action'], None)
def create_user(self, update_data=None): user = User(**self.user_data) Session.add(user) # Flush to put to the DB and generate defaults Session.flush() if update_data: for update in update_data.items(): setattr(user, update[0], update[1]) transaction.commit()
def reset_continue(self): ''' Method that serves password reset page ''' user = self.request.matchdict.get('user') if self.check_csrf: token = self.request.session.get_csrf_token() else: token = '' if self.request.method == 'POST': # if turned on, check for csrf token if self.check_csrf and token != self.request.POST.get('token'): return {'status': False, 'msg': self.request._('csrf-mismatch', default='CSRF token did not match.', domain='pyramid_fullauth'), 'token': token} password = self.request.POST.get('password', None) password_confirm = self.request.POST.get('confirm_password', None) if password == password_confirm: try: self.request.registry.notify(BeforeReset(self.request, user)) validate_passsword(self.request, password, user) user.reset_key = None try: Session.query(AuthenticationProvider).filter( AuthenticationProvider.user_id == user.id, AuthenticationProvider.provider == u'email').one() except NoResultFound: user.providers.append( AuthenticationProvider(provider=u'email', provider_id=user.id)) Session.flush() except (ValidateError, AttributeError) as e: return {'status': False, 'msg': str(e), 'token': token} try: self.request.registry.notify(AfterReset(self.request, user)) except HTTPFound as redirect: return redirect else: return {'status': False, 'msg': self.request._('password-mismatch', default='Password doesn\'t match', domain='pyramid_fullauth'), 'token': token} return {'status': True, 'token': token}
def create_api_consumer(target, connection, **kwargs): key = settings['api.key'] secret = settings.get('api.secret') ttl = settings.get('api.ttl', auth.DEFAULT_TTL) session = Session() consumer = session.query(Consumer).filter(Consumer.key == key).first() if not consumer: with transaction.manager: consumer = Consumer(key=key, secret=secret, ttl=ttl) session.add(consumer) session.flush()
def dispatch_user_notifications(user, user_notifications): """ 4. for each channel loop and either write out a single or a batch dispatch task with the NotificationDispatcher ids e.g: /dispatch_email, /dispatch_sms and etc. """ for ch in AVAILABLE_CHANNELS: # XXX check for preferences e.g: and user.channel == ch to_dispatch = [d for d in user_notifications if d.category == ch] for dispatch in to_dispatch: post_notification_dispatch(dispatch) else: print "nothing here", to_dispatch Session.flush()
def dispatch_user_notifications(user, user_notifications): """ 4. for each channel loop and either write out a single or a batch dispatch task with the NotificationDispatcher ids e.g: /dispatch_email, /dispatch_sms and etc. """ for ch in AVAILABLE_CHANNELS: # XXX check for preferences e.g: and user.channel == ch to_dispatch = [d for d in user_notifications if d.category == ch] for dispatch in to_dispatch: post_notification_dispatch(dispatch) else: print 'nothing here', to_dispatch Session.flush()
def test_add_user(self): from balistos.models.user import User user = User( username='******', email='*****@*****.**', fullname=u'Főo čar' ) Session.add(user) Session.flush() user = User.get_by_username('test') self.assertEqual('test', user.username) self.assertEqual('*****@*****.**', user.email) self.assertEqual(u'Főo čar', user.fullname)
def test_disabled_enabled_entry_after_disabled(self): self.user.disable() self._make_enabled_entry() self._make_disabled_entry() self._make_enabled_entry() Session.flush() from pyramid_bimt.sanitycheck import CheckUsersEnabledDisabled self.assertEqual( CheckUsersEnabledDisabled()(), [ 'User [email protected] (1) is disabled, but has an UserEnabled entry' ' after UserDisabled entry.' ], )
def test_add_clip(self): from balistos.models.clip import Clip clip = Clip( youtube_video_id='test', title=u'Test', likes=5, image_url='test_url', duration=1, ) Session.add(clip) Session.flush() clip = Clip.get('test') self.assertEqual('test', clip.youtube_video_id) self.assertEqual(u'Test', clip.title) self.assertEqual(5, clip.likes) self.assertEqual('test_url', clip.image_url) self.assertEqual(1, clip.duration)
def setUp(self): settings = { 'bimt.app_title': 'BIMT', } self.request = testing.DummyRequest() self.config = testing.setUp(request=self.request, settings=settings) self.config.scan('pyramid_bimt.models.mailing') self.config.include('pyramid_mailer.testing') self.config.include('pyramid_chameleon') self.mailer = get_mailer(self.request) initTestingDB(users=True, groups=True, mailings=True, auditlog_types=True) # noqa add_routes_auth(self.config) self.user = User(email='*****@*****.**') Session.add(self.user) Session.flush()
def setUp(self): settings = { 'bimt.app_title': 'BIMT', } self.request = testing.DummyRequest() self.config = testing.setUp(request=self.request, settings=settings) self.config.include('pyramid_mailer.testing') self.config.include('pyramid_chameleon') self.mailer = get_mailer(self.request) initTestingDB(users=True, groups=True) self.group = Group(name='foo') Session.add(self.group) self.user = User(email='*****@*****.**') Session.add(self.user) self.user.groups = [ self.group, ] Session.flush()
def submit_success(self, appstruct): portlet = Portlet( name=appstruct.get('name'), groups=[ Group.by_id(group_id) for group_id in appstruct.get('groups') ], # noqa exclude_groups=[ Group.by_id(group_id) for group_id in appstruct.get('exclude_groups') ], # noqa position=appstruct.get('position'), weight=appstruct.get('weight'), html=appstruct.get('html'), ) Session.add(portlet) Session.flush() self.request.session.flash(u'Portlet "{}" added.'.format(portlet.name)) return HTTPFound(location=self.request.route_path( 'portlet_edit', portlet_id=portlet.id))
def submit_success(self, appstruct): mailing = Mailing( name=appstruct['name'], groups=[ Group.by_id(group_id) for group_id in appstruct.get('groups') ], # noqa exclude_groups=[ Group.by_id(group_id) for group_id in appstruct.get('exclude_groups') ], # noqa trigger=appstruct['trigger'], days=appstruct['days'], subject=appstruct['subject'], body=appstruct['body'], ) Session.add(mailing) Session.flush() self.request.session.flash(u'Mailing "{}" added.'.format(mailing.name)) return HTTPFound(location=self.request.route_path( 'mailing_edit', mailing_id=mailing.id))
def get_playlist_videos(playlist, username=None): """ Method that returns all the clips that are part of playlist :param playlist: playlist of which we want to get videos :type playlist: balistos.models.playlist.Playlist :returns: dict for each clip that is part of playlist :rtype: list of dicts """ pclips = [] user = User.get_by_username(username) if user: playlist_user = PlaylistUser.get_by_playlist_and_user(playlist, user) playlist_user.last_active = datetime.now() playlist.last_active = datetime.now() Session.flush() active_pclip = PlaylistClip.get_active_playlist_clip(playlist) if not active_pclip: return [] next_pclip = PlaylistClip.get_queue_playlist_clip(playlist) if not next_pclip: next_pclip = set_next_in_queue( playlist, active_pclip.clip.youtube_video_id ) # if check_if_finished(active_pclip): # try: # a, b = play_next_clip(playlist, active_pclip, next_pclip) # active_pclip, next_pclip = a, b # except IntegrityError: # transaction.abort() pclips.append(active_pclip) pclips.append(next_pclip) wait_clips = PlaylistClip.get_by_playlist_waiting(playlist) if wait_clips: pclips = pclips + wait_clips return get_clips_information(user, pclips)
def __call__(self, *args, **kwargs): """Create a TaskModel object and log start of task execution.""" with transaction.manager: if kwargs.get('app_task_id'): task = self.TaskModel.by_id(kwargs['app_task_id']) task.task_id = self.request.id task.state = TaskStates.rerun.name else: task = self.TaskModel( user_id=kwargs['user_id'], task_id=self.request.id, task_name=self.name, args=args, kwargs=kwargs, state=TaskStates.started.name, ) Session.add(task) Session.flush() logger.info( 'START {} (celery task id: {}, app task id: {})'.format( self.name, self.request.id, task.id)) return self.run(*args, **kwargs)
def play_next_clip(playlist, active_pclip, next_pclip): """ Play next clip (clip in queue) in playlist :param playlist: current playlist :type playlist: balistos.models.playlist.Playlist """ if next_pclip: youtube_video_id = next_pclip.clip.youtube_video_id Session.delete(active_pclip) Session.flush() active_pclip = next_pclip active_pclip.state = 2 active_pclip.started = datetime.now() Session.flush() next_pclip = set_next_in_queue( playlist, youtube_video_id, ) Session.flush() return active_pclip, next_pclip
def test_default_values(self): portlet = _make_portlet() Session.flush() self.assertEqual(portlet.html, u'') self.assertEqual(portlet.weight, 0)
def insert_data(): with transaction.manager: admin_group = Group(name='admins') Session.add(admin_group) Session.flush() test_user = User( username='******', email='*****@*****.**', fullname=u'Test User', # password = '******', pregenerated hash to speed up tests password=u'3d91b58504a6cc3a159005ee7b16c7ae503ca6ac2a6a3c893837083c236b864a', # noqa group=admin_group, ) Session.add(test_user) test_playlist = Playlist( uri='test_playlist', title=u'Test Playlist', ) Session.add(test_playlist) Session.flush() test_playlist_user = PlaylistUser( playlist=test_playlist, user=test_user, permission=1, ) Session.add(test_playlist_user) test_clip = Clip( title=u'fernando torres song with lyric', image_url='http://i1.ytimg.com/vi/cpV0ygkmhP4/mqdefault.jpg', likes=0, youtube_video_id='cpV0ygkmhP4', duration=50, ) test_clip2 = Clip( title=u'nba spoof', image_url='http://i1.ytimg.com/vi/cpV0ygkmhP4/mqdefault.jpg', likes=0, youtube_video_id='hi60QeNjIDk', duration=136, ) Session.add(test_clip) Session.add(test_clip2) Session.flush() test_playlist_clip = PlaylistClip( likes=0, added=datetime.now(), started=datetime.now(), state=2, clip=test_clip, playlist=test_playlist, username=test_user.username, ) test_playlist_clip2 = PlaylistClip( likes=0, added=datetime.now(), state=1, clip=test_clip2, playlist=test_playlist, username=test_user.username, ) Session.add(test_playlist_clip) Session.add(test_playlist_clip2)
def register_social(self): ''' Action provides social authorization functionality. When authorization with facebook or twitter is done successfully action tries to find existing user in database, if it exists - login this user, otherwise creates new user. ''' def set_provider(user, provider_name, user_provider_id): ''' Method sets the provider authentication method for user. ''' if user.id: try: provider_auth = Session.query( AuthenticationProvider).filter(AuthenticationProvider.user_id == user.id, AuthenticationProvider.provider == provider_name).one() if provider_auth.provider_id != user_provider_id: return False return True except NoResultFound: pass provider_auth = AuthenticationProvider() provider_auth.provider = provider_name provider_auth.provider_id = user_provider_id user.providers.append(provider_auth) return True context = self.request.context response_values = {'status': False, 'csrf_token': self.request.session.get_csrf_token()} user = self.request.user if user: # when user is logged in already, just connect social account to # this app account try: if set_provider(user, context.provider_name, context.profile['accounts'][0]['userid']): Session.flush() else: response_values['msg'] = 'Your account is already connected to other {provider} account.'.format( provider=context.provider_name) return response_values except IntegrityError: response_values['msg'] = 'This {provider} account is already connected with other account.'.format( provider=context.provider_name) try: self.request.registry.notify(SocialAccountAlreadyConnected( self.request, user, context.profile, response_values)) except HTTPFound as redirect: # it's a redirect, let's follow it! return redirect return response_values else: # getting verified email from provider if 'verifiedEmail' in context.profile: email = context.profile['verifiedEmail'] # getting first of the emails provided by social login provider elif 'emails' in context.profile and context.profile['emails'] and 'value' in context.profile['emails'][0]: email = context.profile['emails'][0]['value'] # generating some random email address based on social userid and provider domain else: email = u'{0}@{1}'.format(context.profile['accounts'][ 0]['userid'], context.profile['accounts'][0]['domain']) try: user = Session.query( User).join(AuthenticationProvider).filter(AuthenticationProvider.provider == context.provider_name, AuthenticationProvider.provider_id == context.profile['accounts'][0]['userid']).one() except NoResultFound: user = None # If the user for the provider was not found then check if in the DB exists user with the same email if not user: try: user = Session.query(User).filter(User.email == email).one() # If we are here that means that in the DB exists user with the same email but without the provider # then we connect social account to this user set_provider(user, context.provider_name, context.profile['accounts'][0]['userid']) Session.flush() except NoResultFound: length_min = self.request.config.fullauth.register.password.length_min user = User(email=email, password=tools.password_generator(length_min), address_ip=self.request.remote_addr) self.request.registry.notify(BeforeSocialRegister(self.request, user, context.profile)) set_provider(user, context.provider_name, context.profile['accounts'][0]['userid']) Session.add(user) Session.flush() user.is_active = True try: self.request.registry.notify(AfterSocialRegister( self.request, user, context.profile, response_values)) except HTTPFound as redirect: # it's a redirect, let's follow it! return redirect # if we're here, user exists try: self.request.registry.notify(AfterSocialLogIn(self.request, user, context.profile)) except HTTPFound as redirect: # it's a redirect, let's follow it! return self.request.login_perform(user, location=redirect.location) else: return self.request.login_perform(user)
def test_name_is_unique(self): _make_mailing(name='foo') _make_mailing(name='foo') with self.assertRaises(IntegrityError) as cm: Session.flush() self.assertIn('column name is not unique', cm.exception.message)
def test_default_values(self): user = _make_user() Session.flush() self.assertEqual(user.valid_to, date.today())
def register_POST(self): ''' Process POST register request ''' invalid_fields = {} response_values = { 'status': False, 'msg': self.request._('You have an error in your registration form', domain='pyramid_fullauth'), 'csrf_token': self.request.session.get_csrf_token()} response_values['errors'] = invalid_fields email = self.request.POST.get('email', u'') # here if e-mail is already in database try: Session.query(User).filter(User.email == email).one() invalid_fields['email'] = self.request._('User with given e-mail already exists!', domain='pyramid_fullauth') except NoResultFound: pass try: user = User() try: user.email = email except ValidateError as e: # do not overwrite existing error if not 'email' in invalid_fields: invalid_fields['email'] = str(e) user.address_ip = self.request.remote_addr if self.request.config.fullauth.register.password.require: try: tools.validate_passsword(self.request, self.request.POST.get('password', u''), user) except ValidateError as e: invalid_fields['password'] = e.message else: user.password = tools.password_generator( self.request.config.fullauth.register.password.length_min) self.request.registry.notify(BeforeRegister(self.request, user, invalid_fields)) if not invalid_fields: Session.add(user) Session.flush() # lets add AuthenticationProvider as email! user.providers.append( AuthenticationProvider(provider=u'email', provider_id=user.id)) else: return response_values except AttributeError as e: invalid_fields['msg'] = str(e) return response_values response_values['status'] = True response_values['msg'] = self.request._('You have successfully registered', domain='pyramid_fullauth') try: self.request.registry.notify(AfterRegister(self.request, user, response_values)) except HTTPFound as redirect: return redirect return response_values