Ejemplo n.º 1
0
 def create_users(self, count=100):
     queue = []
     # First build a list of specific users.
     for first, last in self.default_users:
         u = self._create_users(first, last, first.lower())
         queue.append(u)
     # Second build a list of random users.
     i = 0
     while i < count:
         u = self._create_users()
         queue.append(u)
         i += 1
     for r in queue:
         user = User(**r)
         user.set_password('testing')
         db.session.add(user)
         t = (r.get('first_name'), r.get('last_name'))
         if t in self.default_users:
             setattr(self, user.first_name.lower(), user)
         try:
             db.session.commit()
         except IntegrityError:
             db.session.rollback()
Ejemplo n.º 2
0
Archivo: api.py Proyecto: ralfeus/order
def create_user():
    '''Creates new user'''
    with UserValidator(request) as validator:
        if not validator.validate():
            return jsonify({
                'data': [],
                'error':
                "Couldn't create a user",
                'fieldErrors': [{
                    'name': message.split(':')[0],
                    'status': message.split(':')[1]
                } for message in validator.errors]
            }), 400
    payload = request.get_json()
    user = User(username=payload['username'],
                email=payload['email'],
                phone=payload['phone'],
                atomy_id=payload['atomy_id'],
                enabled=True)
    user.set_password(payload['password'])
    db.session.add(user)
    db.session.commit()
    return jsonify({'data': [user.to_dict()]})