def setUp(self): """Prepare model test fixture.""" try: new_attrs = {} new_attrs.update(self.attrs) new_attrs.update(self.do_get_dependencies()) self.obj = self.klass(**new_attrs) DBSession.add(self.obj) DBSession.flush() return self.obj except: DBSession.rollback() raise
def create_user(self, **kwargs): name = kwargs['name'] email = kwargs['login_email'].lower() if DBSession.query(model.User).filter(model.User.user_name==email).count() > 0: flash(email + ' already exists!', 'error') kwargs['login_email']='' return self.admin_panel(**kwargs) #redirect('/admin_panel', kwargs) password = ''.join(random.choice(string.letters + string.digits + string.punctuation) for x in xrange(8)) u = model.User() u.user_name = email u.display_name = name u.password = password licensing_portal_url = "licensing.authorityfx.com" subject = "New Authority FX Licensing Portal Account" body = "Dear " + name + ",\n" \ + "\n" \ + "Please login into your new Authority FX licensing portal account with the following credentials: \n" \ + "\n" \ + licensing_portal_url + "\n" \ + "\n" \ + "username: "******"\n" \ + "password: "******"\n" \ + "\n" \ + "We suggest that you change you password upon first login.\n" \ + "\n" \ + "Remember that all purchases are added into our licensing portal under the email address provided at checkout. "\ + "If you want to make puchases using another email address, please ensure that you change your login email via the " \ + "settings page prior to making any new purchases.\n" \ + "\n" \ + "Thanks!" try: sender = SendMail() sender.send_mail(email, subject, body) DBSession.add(u) DBSession.flush() flash(email + ' added and notified via email.') except Exception, e: flash(('Could not send new login to ' + name + ", " + email + ": " + str(e)), 'error')