示例#1
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade
    from app.models.users import Role

    upgrade()
    Role.insert_roles()
示例#2
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade
    from app.models.users import Role

    upgrade()
    Role.insert_roles()
示例#3
0
def new_db():
    """
    清空数据,重置数据库
    :return:
    """
    db.drop_all()
    db.create_all()
    Role.insert_role()
示例#4
0
def new_db():
    """
    清空数据,重置数据库
    clean all data and reset database
    :return:
    """
    db.drop_all()
    db.create_all()
    Role.insert_role()
示例#5
0
def test_posts(client):
    Role.insert_roles()
    role = Role.query.filter_by(name="User").first()
    user = User(email="*****@*****.**",
                password="******",
                confirmed=True,
                role=role)
    db.session.add(user)
    db.session.commit()
    data = {"body": "body of the blog test "}
    res = client.post("/api/posts", json=data)
    print(res.status_code)
示例#6
0
def setup():
    role = Role.first(name='user') #Get the 'user' role or create it
    if not role:
       role = Role.create(name='user', description='provides basic system access', bitmask=2)

    if not User.first(email="*****@*****.**"):
        mixer.blend('app.models.users.User', email="*****@*****.**", password=encrypt_password('hello'),
                confirmed_at=datetime.now(), roles=[role])

    if not User.first(email="*****@*****.**"):
        mixer.blend('app.models.users.User', email="*****@*****.**", password=encrypt_password('world'),
                roles=[role])
示例#7
0
def test_db():
    """
    清空数据,创建测试数据库
    :return:
    """
    db.drop_all()
    db.create_all()
    Role.insert_role()
    user_generate_fake()
    vip_user_generate_fake()
    admin_user_generate_fake()
    tag_generate_fake()
    commodity_generate_fake()
    comment_generate_fake()
示例#8
0
文件: auth.py 项目: dwcaraway/govly
    def register_user(self):

        schema = RELS['v1.AuthView:register'][request.method]

        try:
            data = request_register_options.parse_args()
            validate(data, schema, format_checker=FormatChecker())

            invite_token = data['token']
            if invite_token:
                expired, invalid, invitor = get_token_status(invite_token, 'invite', 'USE_INVITE')

                if invalid or not invitor:
                    return dict(status=409, message="Invite is invalid"), 409

                if expired:
                    return dict(status=409, message="Invite has expired"), 409

                inviteTokenObj = Invite.find(token=invite_token).first()

                if not inviteTokenObj:
                    return dict(status=409, message="Invite not found"), 409

                if inviteTokenObj.invitee_id:
                    return dict(status=409, message="Invite already used"), 409

            password = encrypt_password(data['password'])
            user = register_user(email=data['email'], password=password, first_name=data['firstName'],
                   last_name=data['lastName'], roles=[Role.first(name='user')])

            if invite_token:
                inviteTokenObj.invitee_id = user.id
                inviteTokenObj.save()

            token = generate_confirmation_token(user)
            confirmation_link = urljoin(current_app.config['CLIENT_DOMAIN'], '/#/confirm?token='+token)

            #TODO this mail send should be performed asynchronously using celery, see issue #88850472
            send_message(
                subject='Please Confirm Your FogMine Account',
                sender="*****@*****.**",
                recipients = [user.email],
                html_body=render_template('email/activate.html', user=user, confirmation_link=confirmation_link),
                text_body=render_template('email/activate.txt', user=user, confirmation_link=confirmation_link)
            )

            user_data = generate_response_dict(user=user)

            #SEE 90454516, Login the user
            login_user(user)
            user.save() #saving the user as a precaution, want the log data

            return dict(status=201, message='A confirmation email has been sent to '+user.email, user=user_data), 201

        except ValidationError as e:
            return dict(status=400, message=e.message), 400
        except IntegrityError:
            return {'status': 409, 'message': 'An account with that email already exists.'}, 409
        except werkzeug.exceptions.ClientDisconnected:
            return dict(status=400, message='one or more required arguments missing from this request'), 400
def find_or_create_role(name):
    role = Role.query.filter_by(name=name).first()

    if not role:
        role = Role(name)

        db.session.add(role)

    return role
示例#10
0
def setup():
    userRole = Role.first(name='user') #Get the 'user' role or create it
    if not userRole:
       userRole = Role.create(name='user', description='provides basic system access', bitmask=2)

    adminRole = Role.first(name='admin') #Get the 'admin' role or create it
    if not adminRole:
       adminRole = Role.create(name='admin', description='provides admin level system access', bitmask=4)


    if not User.first(email="*****@*****.**"):
        mixer.blend('app.models.users.User', email="*****@*****.**", password=encrypt_password('hello'),
                confirmed_at=datetime.now(), roles=[userRole])

    if not User.first(email="*****@*****.**"):
        mixer.blend('app.models.users.User', email="*****@*****.**", password=encrypt_password('world'),
                roles=[userRole])

    if not User.first(email="*****@*****.**"):
        mixer.blend('app.models.users.User', email="*****@*****.**", password=encrypt_password('supersecret'),
                roles=[adminRole])
示例#11
0
def add_initial_roles_to_database():

    try:
        user_role = Role(name='user', description="Application users")
        super_user_role = Role(name='superuser', description="Application superusers")
        no_ads_role = Role(name='no_ads', description="Won't display ads")
        basic_role = Role(name='basic', description="Basic users")
        pro_role = Role(name='pro', description="Pro users")
        enterprise_role = Role(name='enterprise', description="Enterprise users")

        db.session.add(user_role)
        db.session.add(super_user_role)
        db.session.add(no_ads_role)
        db.session.add(basic_role)
        db.session.add(pro_role)
        db.session.add(enterprise_role)
        db.session.commit()
    except IntegrityError as error:
        current_app.logger.debug("Role already exists: %s" % error)
示例#12
0
def test_api(client):
    Role.insert_roles()
    res = client.get("/api/roles")
    assert res.status_code == 200
    assert len(res.json) == 3