def new_user(username, email): """Add new user function, pass username, email :param username: string of new user :param email: string of new email """ require('hosts', provided_by=[sample]) require('ini', provided_by=[sample]) parse_ini(env["ini_file"]) import transaction from bookie.models import initialize_sql initialize_sql(dict(env.ini.items('app:main'))) from bookie.models import DBSession from bookie.models.auth import get_random_word, User sess = DBSession() u = User() u.username = unicode(username) passwd = get_random_word(8) u.password = passwd u.email = unicode(email) u.activated = True u.is_admin = False u.api_key = User.gen_api_key() print dict(u) print passwd sess.add(u) sess.flush() transaction.commit()
def _new_user(args): """Handle adding a new user to the system. If you don't include the required info, it will prompt you for it """ if not args.username: args.username = raw_input('username? ') if not args.email: args.email = raw_input('email address? ') if not args.username or not args.email: raise Exception('Must supply a username and email address') import transaction _init_sql(args) from bookie.models import DBSession sess = DBSession() u = User() u.username = unicode(args.username) passwd = get_random_word(8) u.password = passwd u.email = unicode(args.email) u.activated = True u.is_admin = False u.api_key = User.gen_api_key() print dict(u) print passwd sess.add(u) sess.flush() transaction.commit()
def testInviteCreatesUser(self): """We should get a new user when inviting something""" me = User() me.username = u'me' me.email = u'me.com' me.invite_ct = 2 you = me.invite(u'you.com') self.assertEqual( 'you.com', you.username, 'The email should be the username') self.assertEqual( 'you.com', you.email, 'The email should be the email') self.assertTrue( len(you.api_key), 'The api key should be generated for the user') self.assertFalse( you.activated, 'The new user should not be activated') self.assertEqual( 1, me.invite_ct, 'My invite count should be deprecated')
def new_user(request): """Add a new user to the system manually.""" rdict = request.params u = User() u.username = unicode(rdict.get('username')) u.email = unicode(rdict.get('email')) passwd = get_random_word(8) u.password = passwd u.activated = True u.is_admin = False u.api_key = User.gen_api_key() try: DBSession.add(u) DBSession.flush() # We need to return the password since the admin added the user # manually. This is only time we should have/give the original # password. ret = dict(u) ret['random_pass'] = passwd return ret except IntegrityError, exc: # We might try to add a user that already exists. LOG.error(exc) request.response.status_int = 400 return { 'error': 'Bad Request: User exists.', }
def new_user(request): """Add a new user to the system manually.""" rdict = request.params u = User() u.username = unicode(rdict.get('username')) u.email = unicode(rdict.get('email')) passwd = get_random_word(8) u.password = passwd u.activated = True u.is_admin = False u.api_key = User.gen_api_key() try: DBSession.add(u) DBSession.flush() # We need to return the password since the admin added the user # manually. This is only time we should have/give the original # password. ret = dict(u) ret['random_pass'] = passwd return _api_response(request, ret) except IntegrityError, exc: # We might try to add a user that already exists. LOG.error(exc) request.response.status_int = 400 return _api_response(request, { 'error': 'Bad Request: User exists.', })
def testInitialUserInactivated(self): """A new user signup should be a deactivated user""" u = User() u.email = gen_random_word(10) DBSession.add(u) eq_(False, u.activated, 'A new signup should start out deactivated by default') ok_(u.activation.code is not None, 'A new signup should start out as deactivated') eq_('signup', u.activation.created_by, 'This is a new signup, so mark is as thus')
def testInviteCreatesUser(self): """We should get a new user when inviting something""" me = User() me.username = '******' me.email = 'me.com' me.invite_ct = 2 you = me.invite('you.com') eq_('you.com', you.username, 'The email should be the username') eq_('you.com', you.email, 'The email should be the email') ok_(len(you.api_key), 'The api key should be generated for the user') ok_(not you.activated, 'The new user should not be activated') eq_(1, me.invite_ct, 'My invite count should be deprecated')