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')
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}