Exemplo n.º 1
0
def ajax_set_active(request):
    user_id = request.POST.get('id', None)
    if user_id is None:
        return Respose('insufficient params')
    
    try:
        user = request.rel_db_session.query(users.User).filter_by(id=user_id).one()
    except NoResultFound:
        return Respose('nothing to do')

    activation_key = user.registration_profile.activation_key
    
    try:
        user = RegistrationProfileManager.activate_user(activation_key, request)
    except InvalidActivationKey:
        if user.is_active == False:
            user.is_active = True
            request.rel_db_session.add(user)
            try:
                request.rel_db_session.commit()
            except:
                request.rel_db_session.rollback()
                return Response('error')

    except ActivationError:        
        return Response('error')
  
    return Response('done')
Exemplo n.º 2
0
def ajax_set_active(request):
    user_id = request.POST.get('id', None)
    if user_id is None:
        return Respose('insufficient params')

    try:
        user = request.rel_db_session.query(users.User).filter_by(id=user_id).one()
    except NoResultFound:
        return Respose('nothing to do')

    activation_key = user.registration_profile.activation_key

    try:
        user = RegistrationProfileManager.activate_user(activation_key, request)
    except InvalidActivationKey:
        if user.is_active == False:
            user.is_active = True
            request.rel_db_session.add(user)
            try:
                request.rel_db_session.commit()
            except:
                request.rel_db_session.rollback()
                return Response('error')

    except ActivationError:
        return Response('error')

    return Response('done')
Exemplo n.º 3
0
def activation(request):
    main = get_renderer(BASE_TEMPLATE).implementation()

    activation_key = request.params.get('key', None)
    if activation_key is None:
        raise exceptions.NotFound()
    
    try:
        user = RegistrationProfileManager.activate_user(activation_key, request)
    except InvalidActivationKey:
        raise exceptions.NotFound()
    except ActivationError:
        request.session.flash(_('Problems occured when trying to activate the user. Please try again.'))
        return {'main':main, 'active':False}

    request.session.flash(_('User %s has been activated successfuly.' % user.username))

    return {'main':main, 'active':True}
Exemplo n.º 4
0
def activation(request):
    main = get_renderer(BASE_TEMPLATE).implementation()

    activation_key = request.params.get('key', None)
    if activation_key is None:
        raise exceptions.NotFound()

    try:
        user = RegistrationProfileManager.activate_user(activation_key, request)
    except InvalidActivationKey:
        raise exceptions.NotFound()
    except ActivationError:
        request.session.flash(_('Problems occured when trying to activate the user. Please try again.'))
        return {'main':main, 'active':False}

    request.session.flash(_('User %s has been activated successfuly.' % user.username))

    return {'main':main, 'active':True}
Exemplo n.º 5
0
def signup(request):
    FORM_TITLE = _('Signup')
    localizer = get_localizer(request)
    main = get_renderer(BASE_TEMPLATE).implementation()
    publisher = request.rel_db_session.query(models.Publisher.name_slug, models.Publisher.name).all()
    signup_form = SignupForm.get_form(localizer,publisher)

    if request.method == 'POST':
                
        controls = request.POST.items()
        try:
            appstruct = signup_form.validate(controls)
        except deform.ValidationFailure, e:
            
            return {'content':e.render(), 
                    'main':main, 
                    'form_stuff':{'form_title':FORM_TITLE},
                    'user':get_logged_user(request),
                    }

        del(appstruct['__LOCALE__'])

        appstruct['publisher'] = request.rel_db_session.query(models.Publisher).filter_by(name_slug=appstruct['publisher']).one()
        
        #FIXME! so bizarre!
        try:
            group = request.rel_db_session.query(users.Group).filter_by(name=appstruct['group']).one()
        except NoResultFound:
            group = users.Group(name=appstruct['group'])
            request.rel_db_session.add(group)
            request.rel_db_session.commit()
        finally:
            group_name = appstruct['group']
            del(appstruct['group'])
     
        if group_name == 'editor':
            user = models.Editor(group=group,**appstruct)
        elif group_name == 'admin':
            del(appstruct['publisher'])
            user = models.Admin(group=group,**appstruct)
        
        registration_profile = users.RegistrationProfile(user)

        RegistrationProfileManager.clean_expired(request)

        request.rel_db_session.add(user)
        request.rel_db_session.add(registration_profile)

        try:
            request.rel_db_session.commit()
        except IntegrityError:
            request.rel_db_session.rollback()
            request.session.flash(_('This username already exists.'))
            return {'content':signup_form.render(appstruct),
                    'main':main,
                    'form_stuff':{'form_title':FORM_TITLE},
                    'user':get_logged_user(request),
                    }
        else:            
            RegistrationProfileManager.send_activation_mail(user, request)


        request.session.flash(_('Successfully added.'))
        return HTTPFound(location=request.route_url('staff.panel'))
Exemplo n.º 6
0
def signup(request):
    FORM_TITLE = _('Signup')
    localizer = get_localizer(request)
    main = get_renderer(BASE_TEMPLATE).implementation()
    publisher = request.rel_db_session.query(models.Publisher.name_slug, models.Publisher.name).all()
    signup_form = SignupForm.get_form(localizer,publisher)

    if request.method == 'POST':
        if 'btn_cancel' in request.POST:
            return HTTPFound(location=request.route_path('users.list'))

        controls = request.POST.items()
        try:
            appstruct = signup_form.validate(controls)
        except deform.ValidationFailure, e:

            return {'content':e.render(),
                    'main':main,
                    'general_stuff':{'form_title':FORM_TITLE,
                                  'breadcrumb': [
                                     (_('Dashboard'), request.route_path('staff.panel')),
                                     (_('Manage Users'), request.route_path('users.list')),
                                     (_('New User'), None),
                                   ]
                                 },
                    'user':get_logged_user(request),
                    }

        del(appstruct['__LOCALE__'])

        appstruct['publisher'] = request.rel_db_session.query(models.Publisher).filter_by(name_slug=appstruct['publisher']).one()

        #FIXME! so bizarre!
        try:
            group = request.rel_db_session.query(users.Group).filter_by(name=appstruct['group']).one()
        except NoResultFound:
            group = users.Group(name=appstruct['group'])
            request.rel_db_session.add(group)
            request.rel_db_session.commit()
        finally:
            group_name = appstruct['group']
            del(appstruct['group'])

        if group_name == 'editor':
            user = models.Editor(group=group,**appstruct)
        elif group_name == 'admin':
            del(appstruct['publisher'])
            user = models.Admin(group=group,**appstruct)

        registration_profile = users.RegistrationProfile(user)

        RegistrationProfileManager.clean_expired(request)

        request.rel_db_session.add(user)
        request.rel_db_session.add(registration_profile)

        try:
            request.rel_db_session.commit()
        except IntegrityError:
            request.rel_db_session.rollback()
            request.session.flash(_('This username already exists.'))
            return {'content':signup_form.render(appstruct),
                    'main':main,
                    'general_stuff':{'form_title':FORM_TITLE,
                                  'breadcrumb': [
                                    (_('Dashboard'), request.route_path('staff.panel')),
                                    (_('Manage Users'), request.route_path('users.list')),
                                    (_('New User'), None),
                                  ]
                                 },
                    'user':get_logged_user(request),
                    }
        else:
            RegistrationProfileManager.send_activation_mail(user, request)


        request.session.flash(_('Successfully added.'))
        return HTTPFound(location=request.route_path('staff.panel'))