예제 #1
0
def update_user(user_id):
    """Update the user associated with the given user_id
    From Data: email (str), admin (bool), password (str), active (bool)
    Return: user dictionary"""
    user = KBUser.query.get(user_id)
    if not user:
        abort(404)

    if not current_user.admin and not user.id == current_user.id:
        return abort(403)

    user = KBUser(
        email=request.json['email'],
        password=bcrypt.generate_password_hash(request.json['password'])
        if 'password' in request.json else user.password,
        admin=request.json['admin'],
        active=request.json['active'],
        first_name=request.json.get('first_name', ""),
        last_name=request.json.get('last_name', ""),
        id=user.id
    )

    if not user.active:
        yara_rule.Yara_rule.query.filter(yara_rule.Yara_rule.owner_user_id == user_id).update(dict(owner_user_id=None))
        c2dns.C2dns.query.filter(c2dns.C2dns.owner_user_id == user_id).update(dict(owner_user_id=None))
        c2ip.C2ip.query.filter(c2ip.C2ip.owner_user_id == user_id).update(dict(owner_user_id=None))

    db.session.merge(user)
    db.session.commit()
    user = KBUser.query.get(user_id)

    return jsonify(user.to_dict()), 200
예제 #2
0
def create_user():
    """Create a user.
    From Data: email (str), admin (bool), password (str), active (bool)
    Return: user dictionary"""
    user = KBUser(email=request.json['email'],
                  admin=request.json['admin'],
                  password=bcrypt.generate_password_hash(
                      request.json['password']),
                  active=request.json['active'])

    db.session.add(user)
    db.session.commit()

    return jsonify(user.to_dict()), 201
예제 #3
0
 def register(self):
     self.user = KBUser(email=testing_config.TEST_USER,
                        password=testing_config.TEST_PASSWORD_HASHED,
                        admin=True,
                        active=True)
     app.db.session.add(self.user)
     app.db.session.commit()