Exemplo n.º 1
0
def does_user_exist():
    params = request.json
    username = params['username']
    registry = get_registry()
    user_repo = registry['USER_REPO']
    user = user_repo.get_user_from_username(username)
    return {'result': user is not None}
Exemplo n.º 2
0
 def __init__(self):
     registry = get_registry()
     self.call_repo = registry['CALL_REPO']
     self.user_repo = registry['USER_REPO']
     self.device_repo = registry['DEVICE_REPO']
     self.tokbox = registry['TOKBOX']
     self.push_notifications = PushNotifications()
Exemplo n.º 3
0
 def __init__(self):
     registry = get_registry()
     self.deck_repo = registry['DECK_REPO']
     self.db = registry['DB']
     self.upload_helper = UploadHelper()
     self.notification_repo = registry['NOTIFICATION_REPO']
     self.user_repo = registry['USER_REPO']
Exemplo n.º 4
0
def create_test_environment():
    app = create_app('test')
    Manager(app)
    db = get_registry()['DB']
    Migrate(app, db)
    with app.app_context():
        upgrade()
    set_app(app)
    return app
Exemplo n.º 5
0
    def setUp(self):
        self.app = environment.get_app()
        self.db = get_registry()['DB']
        self.clean_db()

        self.test_request_context = self.app.test_request_context(self.url)
        self.test_request_context.push()

        self.client = self.app.test_client()
Exemplo n.º 6
0
def create_roles():
    """Creates the roles."""
    user_datastore = get_registry()['USER_DATASTORE']
    user_datastore.find_or_create_role(name='admin', description='Admin')
    user_datastore.find_or_create_role(name='user', description='User')
    db.session.commit()
    print "successfully created roles: " + arrow.utcnow().format(
        'YYYY-MM-DD HH:mm:ss ZZ'
    )
Exemplo n.º 7
0
    def name(self):
        if self.username:
            return self.username

        user_repo = get_registry()['USER_REPO']
        user = user_repo.set_default_username(self)
        if self.username:
            return user.username
        return '%s %s' % (self.first_name, self.last_name)
Exemplo n.º 8
0
def get_related_users(card, role_id):
    db = get_registry()['DB']
    sql_str = '''SELECT u.id, u.email, u.stripped_email, u.first_name, u.last_name, u.username,
u.bio, u.thumbnail_url, u.linkedin_profile, u.linkedin_headline, u.active, u.confirmed_at, u.source,
u.tier, urc.role_id, urc.contribution, urc.prize
FROM "user" u JOIN user_role_card urc ON (u.id = urc.user_id)
WHERE urc.role_id = :role_id and urc.card_id = :card_id'''
    sql = text(sql_str)
    result = list(db.engine.execute(sql, {'role_id': role_id, 'card_id': card.id}))
    return result
Exemplo n.º 9
0
def unfollow_user():
    registry = get_registry()
    user_repo = registry['USER_REPO']
    account_manager = current_app.managers.account_manager

    params = request.json
    following_id = params['following_id']

    account_manager.unfollow_user(follower=current_user,
                                  following=user_repo.get_user(following_id))
    return account_manager.get_profile(user_repo.get_user(following_id),
                                       current_user)
Exemplo n.º 10
0
    def setUp(self):
        super(SignUpTestCase, self).setUp()
        self.code_patcher = mock.patch(
            'lib.repo.user_repo.generate_verification_code')
        self.code_mock = self.code_patcher.start()

        self.registry = get_registry()
        self.original_mail = self.registry['MAIL']
        self.mail_mock = mock.Mock()
        self.registry['MAIL'] = self.mail_mock

        self.code_mock.return_value = "abscdef"
Exemplo n.º 11
0
def create_test_user():
    """Creates the roles."""
    user_datastore = get_registry()['USER_DATASTORE']
    email = '*****@*****.**'
    user_data = {
        'email': email,
        'password': '******',
        'silver_points': 30000
    }
    user = user_datastore.create_user(**user_data)
    db.session.commit()
    user_datastore.add_role_to_user(email, 'user')
    db.session.commit()
Exemplo n.º 12
0
def create_app(env):
    init_config(env)
    app = _initialize_flask_app()
    app.wsgi_app = RequestLoggerMiddleware(app.wsgi_app)
    app = _configure_logging(app)
    app.config.from_object(Ivysaur.Config)
    app = _register_blueprints(app)
    app = _register_version_and_log(app)

    db = SQLAlchemy(app, session_options={"autoflush": False})
    reg = get_registry()
    reg['DB'] = db

    mail = Mail(app)
    reg['MAIL'] = mail

    reg['TOKBOX'] = OpenTok(
        Ivysaur.Config.TOKBOX_API_KEY, Ivysaur.Config.TOKBOX_API_SECRET
    )

    from lib.models.user import User
    from lib.models.role import Role

    user_datastore = SQLAlchemyUserDatastore(db, User, Role)
    Security(app, user_datastore)

    from lib.repo.user_repo import UserRepo
    from lib.repo.device_repo import DeviceRepo
    from lib.repo.deck_repo import DeckRepo
    from lib.repo.notification_repo import NotificationRepo
    from lib.repo.ask_repo import AskRepo

    # see comment for this method
    _initialize_models()

    reg['USER_DATASTORE'] = user_datastore
    reg['USER_REPO'] = UserRepo()
    reg['DEVICE_REPO'] = DeviceRepo()
    reg['DECK_REPO'] = DeckRepo()
    reg['NOTIFICATION_REPO'] = NotificationRepo()
    reg['ASK_REPO'] = AskRepo()

    app = _initialize_managers(app)
    app.json_encoder = AppJSONEncoder
    return app
Exemplo n.º 13
0
    def create_inactive_account(self, username, email):
        user = self.user_repo.get_user_by_email(email)
        if user:
            raise self.CreateInactiveUserException('email_exists')

        user = self.user_repo.get_user_from_username(username)
        if user:
            raise self.CreateInactiveUserException('username_exists')

        if email.endswith("@noschool.edu"):
            raise self.CreateInactiveUserException('no_school')

        user = self.user_repo.create_inactive_user(username, email)
        self.db.session.commit()
        mail = get_registry()['MAIL']
        msg = Message(
            'Verification code for user: {} {}'.format(
                user.first_name, user.last_name
            ),
            sender=Ivysaur.Config.MAIL_USERNAME,
            recipients=[user.email])
        msg.html = u'Verification Code {}'.format(user.verification_code)
        mail.send(msg)
        return user
Exemplo n.º 14
0
 class Meta:
     model = user_role_card.UserRoleCard
     sqlalchemy_session = get_registry()['DB'].session
Exemplo n.º 15
0
 class Meta:
     model = tag.Tag
     sqlalchemy_session = get_registry()['DB'].session
Exemplo n.º 16
0
 def __init__(self):
     registry = get_registry()
     self.deck_repo = registry['DECK_REPO']
     self.user_repo = registry['USER_REPO']
     self.db = registry['DB']
Exemplo n.º 17
0
def add_from_gspreadsheet():
    _init_app()
    sh = _get_worksheet()
    db = get_registry()['DB']
    deck_repo = get_registry()['DECK_REPO']

    deck_repo.truncate_tables()

    folder1 = None
    folder2 = None
    deck = None
    for row in sh.get_all_values()[1:]:
        if not any(row):
            continue

        # root folder
        if row[0]:
            folder1 = deck_repo.add_folder(row[0],
                                           CHRIS,
                                           row[1],
                                           root_level=True)
            continue

        # next layer of folders
        if row[1]:
            folder2 = deck_repo.add_folder(row[1],
                                           CHRIS,
                                           row[2],
                                           root_level=False)
            folder1.folders.append(folder2)
            continue

        # deck
        if row[2]:
            deck = deck_repo.add_deck(row[2], CHRIS, row[3])
            folder2.decks.append(deck)
            continue

        new_set = deck_repo.add_set(row[3], CHRIS)
        deck.content.append(new_set)

        # card 1
        card1 = deck_repo.add_card(row[3])
        new_set.content.append(card1)
        card_content1_1 = deck_repo.add_card_content('text', row[3], JP)
        card1.content.append(card_content1_1)
        card_content1_2 = deck_repo.add_card_content('text', row[4], EN)
        card1.content.append(card_content1_2)
        card_content1_3 = deck_repo.add_card_content('audio', row[3], JP)
        card1.content.append(card_content1_3)

        # card 2
        card2 = deck_repo.add_card(row[5])
        new_set.content.append(card2)
        card_content2 = deck_repo.add_card_content('text', row[5], EN)
        card2.content.append(card_content2)

        if row[6]:
            # card 3
            card3 = deck_repo.add_card('image')
            new_set.content.append(card3)
            card_content3 = deck_repo.add_card_content('image', row[6], EN)
            card3.content.append(card_content3)

        if row[7]:
            # card 4
            card4 = deck_repo.add_card('video')
            new_set.content.append(card4)
            card_content4 = deck_repo.add_card_content('video', row[7], EN)
            card4.content.append(card_content4)

        if row[8]:
            # card 5
            card5 = deck_repo.add_card('example')
            new_set.content.append(card5)
            card_content5 = deck_repo.add_card_content('web', row[8], EN)
            card5.content.append(card_content5)

    db.session.commit()
Exemplo n.º 18
0
 class Meta:
     model = transfer.Transfer
     sqlalchemy_session = get_registry()['DB'].session
Exemplo n.º 19
0
 class Meta:
     model = user.User
     sqlalchemy_session = get_registry()['DB'].session
Exemplo n.º 20
0
 class Meta:
     model = card_likes.CardLikes
     sqlalchemy_session = get_registry()['DB'].session
Exemplo n.º 21
0
 class Meta:
     model = card_comments.CardComments
     sqlalchemy_session = get_registry()['DB'].session
Exemplo n.º 22
0
 def __init__(self):
     self.cert = Ivysaur.Config.CERT_FILE
     self.key = Ivysaur.Config.KEY_FILE
     self.use_sandbox = Ivysaur.Config.APN_USE_SANDBOX
     self.device_repo = get_registry()['DEVICE_REPO']
     self.skill_repo = get_registry()['SKILL_REPO']
Exemplo n.º 23
0
 def __init__(self):
     registry = get_registry()
     self.user_repo = registry['USER_REPO']
Exemplo n.º 24
0
 def __init__(self, role_id):
     self.db = get_registry()['DB']
     self.role_id = role_id
     self.model = user_role_card.UserRoleCard
Exemplo n.º 25
0
 def __init__(self):
     self.db = get_registry()['DB']
Exemplo n.º 26
0
# -*- coding: utf-8 -*-
import os
import sys
import pprint

_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(_root)


from app.ivysaur_app import create_app
ivysaur_env = os.environ.get('IVYSAUR_ENV')
if not ivysaur_env:
    print "please set IVYSAUR_ENV environment var"
    sys.exit(1)

create_app(ivysaur_env)


if __name__ == '__main__':
    from lib.registry import get_registry
    card_id = raw_input('Card or Deck ID: ')
    deck_repo = get_registry()['DECK_REPO']
    card = deck_repo.get_card(card_id)
    if not card:
        print "Card or Deck Doesn't Exist"
        sys.exit()

    pprint.pprint(card.to_dict())
Exemplo n.º 27
0
 def __init__(self):
     registry = get_registry()
     self.notification_repo = registry['NOTIFICATION_REPO']
Exemplo n.º 28
0
 class Meta:
     model = comment_like.CommentLike
     sqlalchemy_session = get_registry()['DB'].session
Exemplo n.º 29
0
# -*- coding: utf-8 -*-
import uuid
from lib.registry import get_registry
from lib.models.comment_like import CommentLike


db = get_registry()['DB']


def uuid_gen():
    return str(uuid.uuid4())


class CardComments(db.Model):
    __tablename__ = 'card_comments'
    id = db.Column(db.String(255), primary_key=True, default=uuid_gen)
    user_id = db.Column(db.String, db.ForeignKey('user.id'))
    card_id = db.Column(db.String, db.ForeignKey('card.id'), nullable=True)
    comment_id = db.Column(db.String, db.ForeignKey('card_comments.id', name='fk_sub_comments'), nullable=True)
    content = db.Column(db.Text)
    created_at = db.Column(db.Integer)
    updated_at = db.Column(db.Integer)
    liked_users = db.relationship("CommentLike", back_populates="comment")

    user = db.relationship("User", back_populates="comments")
    card = db.relationship("Card", back_populates="comments")
    sub_comments = db.relationship("CardComments", backref=db.backref("comment", remote_side=[id]))

    __table_args__ = (
        db.PrimaryKeyConstraint('id', name='pk_card_comments'),
        db.UniqueConstraint('user_id', 'card_id', 'comment_id', name='uq_card_comments'),
Exemplo n.º 30
0
 def __init__(self):
     registry = get_registry()
     self.user_datastore = registry['USER_DATASTORE']
     self.db = registry['DB']
     self.device_repo = registry['DEVICE_REPO']
     self.user_repo = registry['USER_REPO']