예제 #1
0
def create_user(**kwargs):
    """

::

    from apex.lib.libapex import create_user

    create_user(username='******', password='******', active='Y', group='group')


    Returns: AuthUser object
    """
    user = AuthUser()

    if 'group' in kwargs:
        try:
            group = DBSession.query(AuthGroup). \
            filter(AuthGroup.name==kwargs['group']).one()

            user.groups.append(group)
        except NoResultFound:
            pass

        del kwargs['group']

    for key, value in kwargs.items():
        setattr(user, key, value)

    DBSession.add(user)
    DBSession.flush()
    return user
예제 #2
0
파일: libapex.py 프로젝트: webjunkie01/apex
def create_user(**kwargs):
    """
::

    from apex.lib.libapex import create_user

    create_user(username='******', password='******', active='Y', group='group')

    Returns: AuthUser object
    """
    user = AuthUser()

    if 'group' in kwargs:
        try:
            group = DBSession.query(AuthGroup). \
            filter(AuthGroup.name==kwargs['group']).one()

            user.groups.append(group)
        except NoResultFound:
            pass

        del kwargs['group']

    for key, value in kwargs.items():
        setattr(user, key, value)

    DBSession.add(user)
    DBSession.flush()
    return user
예제 #3
0
 def __call__(self, form, field):
     message = _('"%s" is an already existing group.')
     data = field.data
     item = DBSession.query(AuthGroup).filter(
         AuthGroup.name == data).first()
     if item is not None:
         raise ValidationError(message % field.data)
예제 #4
0
 def __acl__(self):
     dbsession = DBSession()
     groups = dbsession.query(AuthGroup.name).all()
     defaultlist = [ (Allow, Everyone, 'view'),
             (Allow, Authenticated, 'authenticated'),]
     for g in groups:
         defaultlist.append( (Allow, 'group:%s' % g, g[0]) )
     return defaultlist
예제 #5
0
 def __acl__(self):
     dbsession = DBSession()
     groups = dbsession.query(AuthGroup.name).all()
     defaultlist = [ (Allow, Everyone, 'view'),
             (Allow, Authenticated, 'authenticated'),]
     for g in groups:
         defaultlist.append( (Allow, 'group:%s' % g, g[0]) )
     return defaultlist
예제 #6
0
    def test_create_user(self):
        # create_user(**kwargs)
        from apex.lib.libapex import create_user
        from apex.models import (AuthUser, DBSession)

        create_user(username='******', password='******')
        # check that auth_id, auth_user, auth_group are added
        self.assertEqual('libtest', DBSession.query(AuthUser.login). \
            filter(AuthUser.login=='libtest').one()[0])
예제 #7
0
    def test_create_user(self):
        # create_user(**kwargs)
        from apex.lib.libapex import create_user
        from apex.models import (AuthUser,
                                 DBSession)

        create_user(username='******', password='******')
        # check that auth_id, auth_user, auth_group are added
        self.assertEqual('libtest', DBSession.query(AuthUser.login). \
            filter(AuthUser.login=='libtest').one()[0])
예제 #8
0
파일: forms.py 프로젝트: webjunkie01/apex
    def create_user(self, username):
        user = AuthUser(username=username, password=self.data["password"], email=self.data["email"])
        DBSession.add(user)
        settings = get_current_registry().settings
        if settings.has_key("apex.default_user_group"):
            group = DBSession.query(AuthGroup).filter(AuthGroup.name == settings["apex.default_user_group"]).one()
            user.groups.append(group)
        DBSession.flush()

        return user
예제 #9
0
def apexid_from_token(token):
    """ Returns the apex id from the OpenID Token
    """
    dbsession = DBSession()
    auth = json.loads(dbsession.query(KeyStorage.value). \
                      filter(KeyStorage.key==token).one()[0])
    if 'profile' in auth:
        auth['id'] = auth['profile']['accounts'][0]['userid']
        auth['provider'] = auth['profile']['accounts'][0]['domain']
        return auth
    return None
예제 #10
0
def apexid_from_token(token):
    """ Returns the apex id from the OpenID Token
    """
    dbsession = DBSession()
    auth = json.loads(dbsession.query(KeyStorage.value). \
                      filter(KeyStorage.key==token).one()[0])
    if 'profile' in auth:
        auth['id'] = auth['profile']['accounts'][0]['userid']
        auth['provider'] = auth['profile']['accounts'][0]['domain']
        return auth
    return None
예제 #11
0
파일: forms.py 프로젝트: LeoKudrik/apex
    def create_user(self, auth_id, login):
        id = DBSession.query(AuthID).filter(AuthID.id==auth_id).one()
        user = AuthUser(
            login=login,
            password=self.data['password'],
            email=self.data['email'],
        )
        id.users.append(user)
        DBSession.add(user)
        DBSession.flush()

        return user
예제 #12
0
파일: views.py 프로젝트: cd34/apex-route53
def webhosts(request):
    form = ProviderForm(request.POST)
    providers = DBSession.query(Provider).order_by(Provider.name).all()
    record = Provider()

    if request.method == 'POST' and form.validate():
        record = merge_session_with_post(record, request.POST.items())
        DBSession.merge(record)
        DBSession.flush()
        return HTTPFound(location= \
            route_url('apex_route53_webhosts', request))
    return {'title':'Web Hosts', 'form':form, 'providers':providers}
예제 #13
0
파일: libapex.py 프로젝트: webjunkie01/apex
def apexid_from_token(token):
    """ Returns the apex id from the OpenID Token
    """
    dbsession = DBSession()
    auth = json.loads(dbsession.query(KeyStorage.value). \
                      filter(KeyStorage.key==token).one()[0])
    if 'profile' in auth:
        id = apexid_from_url(auth['profile']['providerName'], \
                             auth['profile']['identifier'])
        auth['apexid'] = id
        return auth
    return None
예제 #14
0
def webhosts(request):
    form = ProviderForm(request.POST)
    providers = DBSession.query(Provider).order_by(Provider.name).all()
    record = Provider()

    if request.method == 'POST' and form.validate():
        record = merge_session_with_post(record, request.POST.items())
        DBSession.merge(record)
        DBSession.flush()
        return HTTPFound(location= \
            route_url('apex_route53_webhosts', request))
    return {'title': 'Web Hosts', 'form': form, 'providers': providers}
예제 #15
0
파일: libapex.py 프로젝트: webjunkie01/apex
def apexid_from_token(token):
    """ Returns the apex id from the OpenID Token
    """
    dbsession = DBSession()
    auth = json.loads(dbsession.query(KeyStorage.value). \
                      filter(KeyStorage.key==token).one()[0])
    if 'profile' in auth:
        id = apexid_from_url(auth['profile']['providerName'], \
                             auth['profile']['identifier'])
        auth['apexid'] = id
        return auth
    return None
예제 #16
0
파일: forms.py 프로젝트: nycynik/apex
    def create_user(self, auth_id, login):
        id = DBSession.query(AuthID).filter(AuthID.id == auth_id).one()
        user = AuthUser(
            login=login,
            password=self.data['password'],
            email=self.data['email'],
        )
        id.users.append(user)
        DBSession.add(user)
        DBSession.flush()

        return user
예제 #17
0
파일: models.py 프로젝트: jbbrokaw/piktio
def copy_game_to_step(game, step):
    """Make a copy of a game object, but only up to the step
    (integer from 1 to 6)"""
    new_game = Game()
    for i in xrange(step):
        attr_name = _STEPS[i] + "_id"
        attached_object = game.__getattribute__(_STEPS[i])
        new_game.__setattr__(attr_name, attached_object.id)
        author = DBSession.query(PiktioProfile)\
            .filter(PiktioProfile.id == attached_object.author_id).one()
        new_game.authors.append(author)
    return new_game
예제 #18
0
def apex_callback(request):
    """ apex_callback(request):
    no return value, called with route_url('apex_callback', request)

    This is the URL that Velruse returns an OpenID request to
    """
    redir = request.GET.get('came_from', \
                route_url(apex_settings('came_from_route'), request))
    headers = []
    if 'token' in request.POST:
        auth = apexid_from_token(request.POST['token'])
        if auth:
            user = AuthUser.get_by_login(auth['id'])
            if not user:
                auth_info = auth['profile']['accounts'][0]
                id = AuthID()
                DBSession.add(id)
                user = AuthUser(
                    login=auth_info['userid'],
                    provider=auth_info['domain'],
                )
                if auth['profile'].has_key('verifiedEmail'):
                    user.email = auth['profile']['verifiedEmail']
                id.users.append(user)
                if apex_settings('default_user_group'):
                    for name in apex_settings('default_user_group'). \
                                              split(','):
                        group = DBSession.query(AuthGroup). \
                           filter(AuthGroup.name==name.strip()).one()
                        id.groups.append(group)
                if apex_settings('create_openid_after'):
                    openid_after = get_module(
                        apex_settings('create_openid_after'))
                    openid_after().after_signup(user)
                DBSession.flush()
            if apex_settings('openid_required'):
                openid_required = False
                for required in apex_settings('openid_required').split(','):
                    if not getattr(user, required):
                        openid_required = True
                if openid_required:
                    request.session['id'] = id.id
                    request.session['userid'] = user.id
                    return HTTPFound(location='%s?came_from=%s' % \
                        (route_url('apex_openid_required', request), \
                        request.GET.get('came_from', \
                        route_url(apex_settings('came_from_route'), request))))
            headers = apex_remember(request, user)
            redir = request.GET.get('came_from', \
                        route_url(apex_settings('came_from_route'), request))
            flash(_('Successfully Logged in, welcome!'), 'success')
    return HTTPFound(location=redir, headers=headers)
예제 #19
0
파일: views.py 프로젝트: jkoelker/apex
def apex_callback(request):
    """ apex_callback(request):
    no return value, called with route_url('apex_callback', request)

    This is the URL that Velruse returns an OpenID request to
    """
    redir = request.GET.get('came_from', \
                route_url(apex_settings('came_from_route'), request))
    headers = []
    if 'token' in request.POST:
        auth = apexid_from_token(request.POST['token'])
        if auth:
            user = AuthUser.get_by_login(auth['id'])
            if not user:
                auth_info = auth['profile']['accounts'][0]
                id = AuthID()
                DBSession.add(id)
                user = AuthUser(
                    login=auth_info['userid'],
                    provider=auth_info['domain'],
                )
                if auth['profile'].has_key('verifiedEmail'):
                    user.email = auth['profile']['verifiedEmail']
                id.users.append(user)
                if apex_settings('default_user_group'):
                    for name in apex_settings('default_user_group'). \
                                              split(','):
                        group = DBSession.query(AuthGroup). \
                           filter(AuthGroup.name==name.strip()).one()
                        id.groups.append(group)
                if apex_settings('create_openid_after'):
                    openid_after = get_module(apex_settings('create_openid_after'))
                    openid_after().after_signup(user)
                DBSession.flush()
            if apex_settings('openid_required'):
                openid_required = False
                for required in apex_settings('openid_required').split(','):
                    if not getattr(user, required):
                        openid_required = True
                if openid_required:
                    request.session['id'] = id.id
                    request.session['userid'] = user.id
                    return HTTPFound(location='%s?came_from=%s' % \
                        (route_url('apex_openid_required', request), \
                        request.GET.get('came_from', \
                        route_url(apex_settings('came_from_route'), request))))
            headers = apex_remember(request, user)
            redir = request.GET.get('came_from', \
                        route_url(apex_settings('came_from_route'), request))
            flash(_('Successfully Logged in, welcome!'), 'success')
    return HTTPFound(location=redir, headers=headers)
예제 #20
0
def referrer_update(user, refer_id):
    """ user = user object
    refer_id = referring user ID

    No return value
    """

    try:
        fkp = DBSession.query(ForeignKeyProfile). \
                  filter(ForeignKeyProfile.user_id==refer_id).one()
    except:
        fkp = ForeignKeyProfile(user_id = refer_id, score = 0)
    fkp.score = fkp.score + 1
    DBSession.merge(fkp)

    try:
        fkp = DBSession.query(ForeignKeyProfile). \
                  filter(ForeignKeyProfile.user_id==user.id).one()
    except:
        fkp = ForeignKeyProfile(user_id = user.id, score = 0)
    fkp.parent_id = refer_id
    DBSession.merge(fkp)

    DBSession.flush()
예제 #21
0
파일: forms.py 프로젝트: webjunkie01/apex
    def create_user(self, username):
        user = AuthUser(
            username=username,
            password=self.data['password'],
            email=self.data['email'],
        )
        DBSession.add(user)
        settings = get_current_registry().settings
        if settings.has_key('apex.default_user_group'):
            group = DBSession.query(AuthGroup). \
               filter(AuthGroup.name==settings['apex.default_user_group']).one()
            user.groups.append(group)
        DBSession.flush()

        return user
예제 #22
0
def create_user(**kwargs):
    """

::

    from apex.lib.libapex import create_user

    create_user(username='******', password='******', active='Y')

    Optional Parameters:

    display_name
    group



    Returns: AuthID object
    """
    auth_id = AuthID(active=kwargs.get('active', 'Y'))
    if 'display_name' in kwargs:
        auth_id.display_name = kwargs['display_name']
        del kwargs['display_name']

    user = AuthUser(login=kwargs['username'], password=kwargs['password'], \
               active=kwargs.get('active', 'Y'))
    auth_id.users.append(user)

    if 'group' in kwargs:
        try:
            group = DBSession.query(AuthGroup). \
            filter(AuthGroup.name==kwargs['group']).one()

            auth_id.groups.append(group)
        except NoResultFound:
            pass

        del kwargs['group']

    for key, value in kwargs.items():
        setattr(user, key, value)

    DBSession.add(auth_id)
    DBSession.add(user)
    DBSession.flush()
    return user
예제 #23
0
파일: libapex.py 프로젝트: nicfit/apex
def create_user(**kwargs):
    """

::

    from apex.lib.libapex import create_user

    create_user(username='******', password='******', active='Y')

    Optional Parameters:

    display_name
    group



    Returns: AuthID object
    """
    auth_id = AuthID(active=kwargs.get('active', 'Y'))
    if 'display_name' in kwargs:
        auth_id.display_name = kwargs['display_name']
        del kwargs['display_name']

    user = AuthUser(login=kwargs['username'], password=kwargs['password'],
               active=kwargs.get('active', 'Y'))
    auth_id.users.append(user)

    if 'group' in kwargs:
        try:
            group = DBSession.query(AuthGroup). \
                    filter(AuthGroup.name == kwargs['group']).one()

            auth_id.groups.append(group)
        except NoResultFound:
            pass

        del kwargs['group']

    for key, value in list(kwargs.items()):
        setattr(user, key, value)

    DBSession.add(auth_id)
    DBSession.add(user)
    DBSession.flush()
    return user
예제 #24
0
파일: forms.py 프로젝트: elliotpeele/apex
    def create_user(self, login):
        id = AuthID()
        DBSession.add(id)
        user = AuthUser(
            login=login,
            password=self.data['password'],
            email=self.data['email'],
        )
        id.users.append(user)
        DBSession.add(user)
        settings = get_current_registry().settings
        if settings.has_key('apex.default_user_group'):
            group = DBSession.query(AuthGroup). \
               filter(AuthGroup.name==settings['apex.default_user_group']).one()
            id.groups.append(group)
        DBSession.flush()

        return user
예제 #25
0
파일: views.py 프로젝트: nycynik/apex
def change_password(request):
    """ change_password(request):
        no return value, called with route_url('apex_change_password', request)
        FIXME doesn't adjust auth_user based on local ID, how do we handle
        multiple IDs that are local? Do we tell person that they don't have
        local permissions?
    """
    title = _('Change your Password')

    came_from = get_came_from(request)
    user = DBSession.query(AuthUser). \
               filter(AuthUser.auth_id==authenticated_userid(request)). \
               filter(AuthUser.provider=='local').first()
    form = ChangePasswordForm(request.POST, user_id=user.id)

    if request.method == 'POST' and form.validate():
        #user = AuthID.get_by_id(authenticated_userid(request))
        user.password = form.data['password']
        DBSession.merge(user)
        DBSession.flush()
        return HTTPFound(location=came_from)

    return {'title': title, 'form': form, 'action': 'changepass'}
예제 #26
0
파일: views.py 프로젝트: jkoelker/apex
def change_password(request):
    """ change_password(request):
    no return value, called with route_url('apex_change_password', request)
    FIXME doesn't adjust auth_user based on local ID, how do we handle multiple
        IDs that are local? Do we tell person that they don't have local
        permissions?
    """
    title = _('Change your Password')

    came_from = get_came_from(request)
    user = DBSession.query(AuthUser). \
               filter(AuthUser.auth_id==authenticated_userid(request)). \
               filter(AuthUser.provider=='local').first()
    form = ChangePasswordForm(request.POST, user_id=user.id)

    if request.method == 'POST' and form.validate():
        #user = AuthID.get_by_id(authenticated_userid(request))
        user.password = form.data['password']
        DBSession.merge(user)
        DBSession.flush()
        return HTTPFound(location=came_from)

    return {'title': title, 'form': form, 'action': 'changepass'}
예제 #27
0
 def __call__(self, form, field):
     message = _('"%s" is an already existing group.')
     data = field.data
     item = DBSession.query(AuthGroup).filter(AuthGroup.name == data).first()
     if item is not None:
         raise ValidationError(message % field.data)
예제 #28
0
파일: libapex.py 프로젝트: nicfit/apex
def apex_id_providers(auth_id):
    """ return a list of the providers that are currently active for
        this auth_id
    """
    return [x[0] for x in DBSession.query(AuthUser.provider).
                                    filter(AuthUser.auth_id == auth_id).all()]
예제 #29
0
파일: models.py 프로젝트: jbbrokaw/piktio
def get_valid_game(request):
    """Get a valid game for the step in request.session['step']
    'Valid' means the game is complete to the previous step, has not been
    worked on by request.user, and the prompt/drawing has not been previously
    rejected by request.user"""
    if request.session['step'] == 'predicate':
        next_game = DBSession.query(Game)\
            .filter(
                ~Game.subject_id.is_(None),
                Game.predicate_id.is_(None),
                ~Game.authors.contains(request.user),
            ).first()
        return next_game

    if request.session['step'] == 'first_drawing':
        subject_strikes = DBSession.query(Strikes)\
            .filter(
                Strikes.author_id == request.user.id,
                ~Strikes.subject_id.is_(None)
            ).all()

        predicate_strikes = DBSession.query(Strikes)\
            .filter(
                Strikes.author_id == request.user.id,
                ~Strikes.predicate_id.is_(None)
            ).all()

        bad_subject_ids = [strike.subject_id for strike in subject_strikes]
        bad_predicate_ids = [strike.predicate_id for strike in predicate_strikes]

        next_game = DBSession.query(Game)\
            .filter(
                ~Game.predicate_id.is_(None),
                Game.first_drawing_id.is_(None),
                ~Game.authors.contains(request.user),
                ~Game.subject_id.in_(bad_subject_ids),
                ~Game.predicate_id.in_(bad_predicate_ids)
            ).first()

        return next_game

    if request.session['step'] == 'first_description':
        drawing_strikes = DBSession.query(Strikes)\
            .filter(
                Strikes.author_id == request.user.id,
                ~Strikes.drawing_id.is_(None)
            ).all()

        bad_drawing_ids = [strike.drawing_id for strike in drawing_strikes]

        next_game = DBSession.query(Game)\
            .filter(
                ~Game.first_drawing_id.is_(None),
                Game.first_description_id.is_(None),
                ~Game.authors.contains(request.user),
                ~Game.first_drawing_id.in_(bad_drawing_ids)
            ).first()

        return next_game

    if request.session['step'] == 'second_drawing':
        description_strikes = DBSession.query(Strikes)\
            .filter(
                Strikes.author_id == request.user.id,
                ~Strikes.description_id.is_(None)
            ).all()

        bad_description_ids = [strike.description_id for strike in description_strikes]

        next_game = DBSession.query(Game)\
            .filter(
                ~Game.first_description_id.is_(None),
                Game.second_drawing_id.is_(None),
                ~Game.authors.contains(request.user),
                ~Game.first_description_id.in_(bad_description_ids)
            ).first()

        return next_game

    if request.session['step'] == 'second_description':
        drawing_strikes = DBSession.query(Strikes)\
            .filter(
                Strikes.author_id == request.user.id,
                ~Strikes.drawing_id.is_(None)
            ).all()

        bad_drawing_ids = [strike.drawing_id for strike in drawing_strikes]

        next_game = DBSession.query(Game)\
            .filter(
                ~Game.second_drawing_id.is_(None),
                Game.second_description_id.is_(None),
                ~Game.authors.contains(request.user),
                ~Game.second_drawing_id.in_(bad_drawing_ids)
            ).first()

        return next_game
예제 #30
0
def apex_id_providers(auth_id):
    """ return a list of the providers that are currently active for 
        this auth_id
    """
    return [x[0] for x in DBSession.query(AuthUser.provider). \
        filter(AuthUser.auth_id==auth_id).all()]