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 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 setUp(self): self.config = testing.setUp() from sqlalchemy import create_engine engine = create_engine('sqlite://') from {{ cookiecutter.project_name }}.models import ( Base, MyModel, ) DBSession.configure(bind=engine) Base.metadata.create_all(engine) with transaction.manager: model = MyModel(name='one', value=55) DBSession.add(model)
def invite(self, email): """Invite a user""" if not self.has_invites(): return False if not email: raise ValueError('You must supply an email address to invite') else: # get this invite party started, create a new useracct new_user = UserMgr.signup_user(email, self.username) # decrement the invite counter self.invite_ct = self.invite_ct - 1 DBSession.add(new_user) return new_user
def signup_user(email, signup_method): # Get this invite party started, create a new user acct. new_user = User() new_user.email = email new_user.username = email new_user.invited_by = signup_method new_user.api_key = User.gen_api_key() # they need to be deactivated new_user.reactivate('invite') # decrement the invite counter DBSession.add(new_user) return new_user
def signup_user(email, signup_method): # Get this invite party started, create a new user acct. exists = UserMgr.get(email=email) if exists: return exists else: new_user = User() new_user.email = email.lower() new_user.username = email.lower() new_user.invited_by = signup_method new_user.api_key = User.gen_api_key() # they need to be deactivated new_user.reactivate('signup') # decrement the invite counter DBSession.add(new_user) return new_user
def store(**kwargs): """Store a new log record to the db""" stored = AppLog(**kwargs) DBSession.add(stored)
def collection_post(self): # Adds a new task. task = self.request.json DBSession.add(Task.from_json(task))