Exemplo n.º 1
0
 def get(self):
     current_user_id = get_jwt_identity()
     current_user = User.get(current_user_id)
     schema = UserSchema(partial=True)
     user_dump = schema.dump(current_user).data
     user_dump.pop("password", None)
     return user_dump
Exemplo n.º 2
0
def admin_user(db):
    user_id = str(uuid.uuid4())
    user = User(id=user_id, username='******', password='******', role='admin')

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

    return user
Exemplo n.º 3
0
def get_user_summary(user_id):
    user = User.get(user_id)
    failed_jobs_by_seller_id = get_failed_jobs_by_index("seller_id")
    failed_jobs_by_username = get_failed_jobs_by_index("username")

    return {
        "user_dump":
        UserSchema().dump(user).data,
        "failed_jobs_by_seller_id":
        failed_jobs_by_seller_id.get(user.seller_id, []),
        "failed_jobs_by_username":
        failed_jobs_by_username.get(user.username, []),
    }
Exemplo n.º 4
0
def test_user(db):
    user_id = str(uuid.uuid4())
    user = User(
        id=user_id,
        username='******',
        password='******',
        role='user',
    )

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

    return user
Exemplo n.º 5
0
    def post(self):
        """Authenticate user and return token"""
        username = request.json.get('username', None)
        password = request.json.get('password', None)

        user = User.find_user_by_username(username)

        if user is None or not pwd_context.verify(password, user.password):
            return {'error': 'Bad credentials'}

        access_token = create_access_token(identity=user.id)
        refresh_token = create_refresh_token(identity=user.id)

        ret = {'access_token': access_token, 'refresh_token': refresh_token}
        return ret
Exemplo n.º 6
0
    def post(self):
        reset_password_fields = request.json
        password = reset_password_fields.get('password')
        password_2 = reset_password_fields.get('password_2')
        if not password == password_2:
            return {'error': 'Passwords do not match.'}, 400

        user = User.get(get_jwt_identity())
        user.update_password(password_2)
        try:
            db.session.commit()
            return {'error': None, 'msg': 'Password successfully updated.'}
        except Exception as e:
            db.session.rollback()
            return {'error': 'Failed to save password in database update'}, 400
Exemplo n.º 7
0
def init():
    """Init application, create database tables
    and create a new user named admin with password admin
    """
    from grocery_mart_api.extensions import db
    from grocery_mart_api.models import User
    click.echo("create database")
    db.create_all()
    click.echo("done")

    click.echo("create user")
    user = User(
        username='******',
        business_name="admin_business",
        email='*****@*****.**',
        password='******',
        role="admin"
    )
    db.session.add(user)
    db.session.commit()
    click.echo("created user admin")
Exemplo n.º 8
0
    def post(self):
        username = request.json.get('username')
        password = request.json.get('password')

        user_id = str(uuid.uuid4())
        user = User(id=user_id,
                    username=username.lower(),
                    password=password,
                    role='user')

        db.session.add(user)

        try:
            db.session.commit()
            user_dump = UserSchema().dump(user)
            print(user_dump)
            user_dump.pop("password", None)
            return {'user': user_dump}
        except Exception as e:
            db.session.rollback()
            return {'error': str(e)}, 400
Exemplo n.º 9
0
def user_factory(i):
    return User(username="******".format(i), email="user{}@mail.com".format(i))