def ipn(self): """The main IPN handler, called by the IPN service.""" # skip over to-be-ignored products if self.params.product_id in self.request.registry.settings.get( 'bimt.products_to_ignore', '').split(','): logger.info('The product is listed on the ignore list: {}'.format( self.params.product_id)) return 'Done.' # try to find an existing user with given email user = User.by_email(self.params.email) if not user: user = User.by_billing_email(self.params.email) # create a new user if no existing user found if not user: password = generate() user = User( email=self.params.email, billing_email=self.params.email, password=encrypt(password), fullname=u'{}'.format(self.params.fullname), affiliate=u'{}'.format(self.params.get('affiliate', '')), ) Session.add(user) comment = COMMENT.format( u'Created', self.provider, self.params.trans_id, self.params.trans_type, '', ) logger.info(comment) self.request.registry.notify( UserCreated(self.request, user, password, comment)) # find a group that is used for given product group = Group.by_product_id(self.params.product_id) if not group: raise ValueError('Cannot find group with product_id "{}"'.format( self.params.product_id)) # perform IPN transaction actions self.ipn_transaction(user, group) # send request with same parameters to the URL specified on group if group.forward_ipn_to_url: requests.post( group.forward_ipn_to_url, params=self.request.POST, ) logger.info('IPN re-posted to {}.'.format( group.forward_ipn_to_url)) logger.info('IPN done.') return 'Done.'
def test_verify_wrong_type(self): from pyramid_bimt.security import generate from pyramid_bimt.security import encrypt from pyramid_bimt.security import verify generated_pass = generate() encrypted_pass = encrypt(generated_pass) self.assertFalse(verify(object(), encrypted_pass))
def test_verify_none(self): from pyramid_bimt.security import generate from pyramid_bimt.security import encrypt from pyramid_bimt.security import verify generated_pass = generate() encrypted_pass = encrypt(generated_pass) self.assertFalse(verify(None, encrypted_pass))
def test_verify(self): from pyramid_bimt.security import generate from pyramid_bimt.security import encrypt from pyramid_bimt.security import verify generated_pass = generate() encrypted_pass = encrypt(generated_pass) self.assertTrue(verify(generated_pass, encrypted_pass))
def reset_password_success(self, appstruct): email = appstruct['email'].lower() user = User.by_email(email) if user is not None: # change user's password and fire event password = generate() user.password = encrypt(password) self.request.registry.notify( UserChangedPassword(self.request, user, password)) self.request.session.flash( u'A new password was sent to your email.') return HTTPFound(location=self.request.route_path('login')) self.request.session.flash( u'Password reset failed. Make sure you ' 'have correctly entered your email address.', 'error')
def generate_api_key(): return re.sub(r'(....)(....)(....)(....)', r'\1-\2-\3-\4', unicode(generate(size=16)))