def callback(self): require.user.edit(c.user) if 'denied' in request.params: redirect(h.entity_url(c.user, member='edit')) request_token = session.get('request_token') if not request_token: h.flash(_("You have been logged out while authenticating " "at twitter. Please try again."), 'notice') redirect(h.entity_url(c.user, member='edit')) request_token = oauth.OAuthToken.from_string(request_token) req_api = create_oauth(key=request_token.key, secret=request_token.secret) access_token = req_api.getAccessToken() api = create_oauth(key=access_token.key, secret=access_token.secret) user_data = api.GetUserInfo() twitter = model.Twitter(int(user_data.id), c.user, user_data.screen_name, unicode(access_token.key), unicode(access_token.secret)) model.meta.Session.add(twitter) model.meta.Session.commit() try: # workaround to a hashing fuckup in oatuh api._FetchUrl("http://twitter.com/friendships/create.json", post_data={'screen_name': system_user()}, no_cache=True) h.flash(_("You're now following %s on twitter so we " + "can send you notifications as direct messages") % system_user(), 'success') except HTTPError, he: log.warn(he.read())
def update_badges(self, id): user = get_entity_or_abort(model.User, id) badges = self.form_result.get('badge') if not has('global.admin'): # instance admins may only add user badges limited to this instance for badge in badges: if not badge.instance == c.instance: h.flash(_(u'Invalid badge choice.'), u'error') redirect(h.entity_url(user)) creator = c.user added = [] removed = [] for badge in user.badges: if badge not in badges: removed.append(badge) user.badges.remove(badge) for badge in badges: if badge not in user.badges: badge.assign(user, creator) added.append(badge) model.meta.Session.flush() # FIXME: needs commit() cause we do an redirect() which raises # an Exception. model.meta.Session.commit() post_update(user, model.update.UPDATE) redirect(h.entity_url(user, instance=c.instance))
def test_is_local_url_entity(self): from adhocracy.lib import helpers as h instance, user = self._make_content() self.assert_(h.site.is_local_url(h.entity_url(user))) self.assert_(h.site.is_local_url(h.entity_url(instance)))
def activate(self, id): c.page_user = get_entity_or_abort(model.User, id, instance_filter=False) code = self.form_result.get('c') if c.page_user.activation_code is None: h.flash(_(u'Thank you, The address is already activated.')) redirect(h.entity_url(c.page_user)) elif c.page_user.activation_code != code: h.flash(_("The activation code is invalid. Please have it " "resent."), 'error') redirect(h.entity_url(c.page_user)) c.page_user.activation_code = None model.meta.Session.commit() if code.startswith(model.User.IMPORT_MARKER): # Users imported by admins login_user(c.page_user, request) h.flash(_("Welcome to %s") % h.site.name(), 'success') if c.instance: membership = model.Membership(c.page_user, c.instance, c.instance.default_group) model.meta.Session.expunge(membership) model.meta.Session.add(membership) model.meta.Session.commit() redirect(h.entity_url(c.instance)) else: redirect(h.base_url('/instance', None)) else: h.flash(_("Your email has been confirmed."), 'success') redirect(h.entity_url(c.page_user)) redirect(h.entity_url(c.page_user))
def index(self, format='html'): if c.instance: redirect(h.entity_url(c.instance)) if format == 'rss': return EventController().all(format='rss') name = config.get('adhocracy.redirect_startpage_to_instance') if name != u'': # get_entity_or_abort does no work for instances instance = model.Instance.find(name) if instance is not None: redirect(h.entity_url(instance)) data = {} instances_in_root = config.get_int( 'adhocracy.startpage.instances.list_length') if instances_in_root > 0: data['instances'] = model.Instance.all(limit=instances_in_root) elif instances_in_root == -1: data['instances'] = model.Instance.all() add_static_content(data, u'adhocracy.static_index_path') c.body_css_classes += data.get('css_classes', []) c.body_css_classes.append('added_static_content') if data['title'] is None: data['title'] = config.get('adhocracy.site.name') proposals_number = config.get_int( 'adhocracy.startpage.proposals.list_length') if proposals_number > 0: proposals = model.Proposal.all_q()\ .join(model.Instance).filter(not_( model.Instance.key.in_(model.Instance.SPECIAL_KEYS)))\ .order_by(model.Proposal.create_time.desc()) data['new_proposals_pager'] = pager.proposals( proposals, size=proposals_number, default_sort=sorting.entity_newest, enable_pages=False, enable_sorts=False) else: data['new_proposals_pager'] = None if config.get_bool('adhocracy.show_stats_on_frontpage'): data['stats_global'] = { "members": model.User.all_q().count(), "comments": model.Comment.all_q().count(), "proposals": model.Proposal.all_q().count(), "votes": model.Vote.all_q().count(), } if format == 'overlay': return render('index.html', data, overlay=True) else: return render('index.html', data)
def revoke(self): require.user.edit(c.user) if not c.user.twitter: h.flash(_("You have no twitter association."), 'notice') redirect(h.entity_url(c.user, member='edit')) c.user.twitter.delete() model.meta.Session.commit() redirect(h.entity_url(c.user, member='edit'))
def show(self, id, format='html'): c.page_instance = get_entity_or_abort(model.Instance, id) require.instance.show(c.page_instance) if format == 'json': return render_json(c.page_instance) if format == 'rss': return self.activity(id, format) if c.page_instance != c.instance: redirect(h.entity_url(c.page_instance)) c.tile = tiles.instance.InstanceTile(c.page_instance) proposals = model.Proposal.all(instance=c.page_instance) c.new_proposals_pager = pager.proposals( proposals, size=7, enable_sorts=False, enable_pages=False, default_sort=sorting.entity_newest) #pages = model.Page.all(instance=c.page_instance, # functions=[model.Page.NORM]) #c.top_pages_pager = pager.pages( # pages, size=7, enable_sorts=False, # enable_pages=False, default_sort=sorting.norm_selections) #tags = model.Tag.popular_tags(limit=40) #c.tags = sorted(text.tag_cloud_normalize(tags), # key=lambda (k, c, v): k.name) if c.page_instance.milestones: c.milestones = model.Milestone.all(instance=c.page_instance) c.stats = { 'comments': model.Comment.all_q().count(), 'proposals': model.Proposal.all_q( instance=c.page_instance).count(), 'members': model.Membership.all_q().count() } return render("/instance/show.html")
def revoke(self, redirect_url=None): v_id = request.params.get('id', None) if v_id is None: abort(401, "id of velruse account not specified") v = Velruse.by_id(v_id) if v is None: self._failure(_("You are trying to disconnect from a provider" " you are disconnected from already.")) return None elif not (v.user == c.user or can.user.manage()): abort(403, _("You're not authorized to change %s's settings.") % c.user.id) else: v.delete_forever() model.meta.Session.commit() h.flash(_("You successfully disconnected from %(provider)s.") % {'provider': v.domain}, 'success') if redirect_url is None: redirect(h.entity_url(c.user, member='settings/login')) else: redirect(redirect_url)
def index(self, format='html'): require.proposal.index() if c.instance: redirect(h.entity_url(c.instance)) c.instances = model.Instance.all()[:5] c.page = StaticPage('index') #query = self.form_result.get('proposals_q') #proposals = libsearch.query.run(query, # entity_type=model.Proposal)[:10] c.milestones = model.Milestone.all() #c.proposals_pager = pager.proposals(proposals) #c.proposals = c.proposals_pager.here() c.stats_global = { "members": model.User.all_q().count(), "comments": model.Comment.all_q().count(), "proposals": model.Proposal.all_q().count(), "votes": model.Vote.all_q().count(), } if format == 'rss': return EventController().all(format='rss') return render('index.html')
def update(self, id): c.page_user = get_entity_or_abort(model.User, id, instance_filter=False) require.user.edit(c.page_user) if self.form_result.get("password_change"): c.page_user.password = self.form_result.get("password_change") c.page_user.display_name = self.form_result.get("display_name") c.page_user.page_size = self.form_result.get("page_size") c.page_user.no_help = self.form_result.get("no_help") c.page_user.bio = self.form_result.get("bio") email = self.form_result.get("email").lower() email_changed = email != c.page_user.email c.page_user.email = email c.page_user.email_priority = self.form_result.get("email_priority") #if c.page_user.twitter: # c.page_user.twitter.priority = \ # self.form_result.get("twitter_priority") # model.meta.Session.add(c.page_user.twitter) locale = Locale(self.form_result.get("locale")) if locale and locale in i18n.LOCALES: c.page_user.locale = locale model.meta.Session.add(c.page_user) model.meta.Session.commit() if email_changed: libmail.send_activation_link(c.page_user) if c.page_user == c.user: event.emit(event.T_USER_EDIT, c.user) else: event.emit(event.T_USER_ADMIN_EDIT, c.page_user, admin=c.user) redirect(h.entity_url(c.page_user))
def unban(self, id): c.page_user = get_entity_or_abort(model.User, id) require.user.manage(c.page_user) c.page_user.banned = False model.meta.Session.commit() h.flash(_("The account has been re-activated."), 'success') redirect(h.entity_url(c.page_user))
def _rate_url(self, poll, position): params = {'url': h.entity_url(poll, member='rate'), 'token_param': h.url_token(), 'position': position, 'cls': self.widget_size} return ("%(url)s?position=%(position)d&" "%(token_param)s&cls=%(cls)s") % params
def show(self, id, format='html'): c.comment = get_entity_or_abort(model.Comment, id) require.comment.show(c.comment) if format == 'fwd': redirect(h.entity_url(c.comment)) elif format == 'json': return render_json(c.comment) return render('/comment/show.html')
def resend(self, id): c.page_user = get_entity_or_abort(model.User, id, instance_filter=False) require.user.edit(c.page_user) libmail.send_activation_link(c.page_user) h.flash(_("The activation link has been re-sent to your email " "address."), 'notice') redirect(h.entity_url(c.page_user, member='edit'))
def _rate_url(self, poll, position): params = { "url": h.entity_url(poll, member="rate"), "token_param": h.url_token(), "position": position, "cls": self.widget_size, } return ("%(url)s?position=%(position)d&" "%(token_param)s&cls=%(cls)s") % params
def to_dict(self): from adhocracy.lib import helpers as h return dict(id=self.id, url=h.entity_url(self), create_time=self.create_time, principal=self.principal.user_name, agent=self.agent.user_name, scope=self.scope_id)
def create(self, format='html'): delegateable = self.form_result.get('delegateable') for tag_text in text.tag_split(self.form_result.get('tags')): if not model.Tagging.find_by_delegateable_name_creator( delegateable, tag_text, c.user): model.Tagging.create(delegateable, tag_text, c.user) model.meta.Session.commit() redirect(h.entity_url(delegateable, format=format))
def create(self, format='html'): entity = self.form_result.get('ref') try: model.Watch.create(c.user, entity, check_existing=True) model.meta.Session.commit() except model.watch.WatchAlreadyExists: h.flash(_(u"A watchlist entry for this entity already exists."), u'notice') redirect(h.entity_url(entity))
def delete(self, format='html'): watch = self.form_result.get('watch') require.watch.delete(watch) if watch.user != c.user and not h.has_permission('instance.admin'): abort(403, _("You're not authorized to delete %s's watchlist " "entries.") % watch.user.name) watch.delete() model.meta.Session.commit() redirect(h.entity_url(watch.entity))
def to_dict(self): from adhocracy.lib import helpers as h return dict(id=self.id, label=self.label, tags=dict([(k.name, v) for k, v in self.tags]), url=h.entity_url(self), instance=self.instance.key, # comment=self.comment.id, creator=self.creator.user_name, create_time=self.create_time)
def create(self, format='html'): require.watch.create() entity = self.form_result.get('ref') if model.Watch.find_by_entity(c.user, entity): h.flash(_("A watchlist entry for this entity already exists."), 'notice') else: model.Watch.create(c.user, entity) model.meta.Session.commit() redirect(h.entity_url(entity))
def to_dict(self): from adhocracy.lib import helpers as h d = dict(id=self.id, title=self.title, url=h.entity_url(self), create_time=self.create_time, text=self.text, creator=self.creator.user_name, instance=self.instance.key) return d
def test_proposal_entity_url(self): from adhocracy.lib.helpers import entity_url from adhocracy import model instance, user = self._make_content() proposal = model.Proposal.create(instance, u'test_proposal', user) url = u'http://test.test.lan/proposal/%i-test_proposal' % proposal.id self.assertEqual(entity_url(proposal), url)
def untag_all(self, format='html'): # HACK create a proper permission require.instance.edit(c.instance) delegateable = self.form_result.get('delegateable') tag = self.form_result.get('tag') for tagging in delegateable.taggings: if tagging.tag == tag: tagging.delete() model.meta.Session.commit() redirect(h.entity_url(delegateable, format=format))
def rate(self, id, format): # rating is like polling but steps via abstention, i.e. if you have # first voted "for", rating will first go to "abstain" and only # then produce "against"- c.poll = self._get_open_poll(id) if c.poll.action not in [model.Poll.RATE, model.Poll.SELECT]: abort(400, _("This is not a rating poll.")) require.poll.vote(c.poll) decision = democracy.Decision(c.user, c.poll) old = decision.result new = self.form_result.get("position") positions = {(model.Vote.YES, model.Vote.YES): model.Vote.YES, (model.Vote.ABSTAIN, model.Vote.YES): model.Vote.YES, (model.Vote.NO, model.Vote.YES): model.Vote.ABSTAIN, (model.Vote.YES, model.Vote.NO): model.Vote.ABSTAIN, (model.Vote.ABSTAIN, model.Vote.NO): model.Vote.NO, (model.Vote.NO, model.Vote.NO): model.Vote.NO} position = positions.get((old, new), new) votes = decision.make(position) tally = model.Tally.create_from_poll(c.poll) event_type = {model.Poll.RATE: event.T_RATING_CAST, model.Poll.SELECT: event.T_SELECT_VARIANT }.get(c.poll.action) model.meta.Session.commit() if not config.get_bool('adhocracy.hide_individual_votes'): for vote in votes: event.emit(event_type, vote.user, instance=c.instance, topics=[c.poll.scope], vote=vote, poll=c.poll) if format == 'json': vdetail = votedetail.calc_votedetail_dict(c.instance, c.poll)\ if votedetail.is_enabled() else None return render_json(dict(decision=decision, tally=tally.to_dict(), votedetail=vdetail)) elif format == 'ajax': return self.widget(id, format=self.form_result.get('cls')) elif c.poll.action == model.Poll.SELECT: redirect(h.entity_url(c.poll.selection)) else: redirect(h.entity_url(c.poll.subject))
def link(self): try: if not self.event: return None return self.event.link_path(self) except: from adhocracy.lib import helpers as h if self.instance: return h.entity_url(self.instance) return h.base_url(instance=None)
def test_page_edit_entity_url(self): from adhocracy.lib.helpers import entity_url from adhocracy import model instance, user = self._make_content() page = model.Page.create(instance, u'test_page', u'text', user) url = u'http://test.test.lan/page/test_page/edit' self.assertEqual(entity_url(page, member=u'edit'), url)
def to_dict(self): from adhocracy.lib import helpers as h return dict(id=self.id, user=self.user.user_name, action=self.action, begin_time=self.begin_time, end_time=self.end_time, tally=self.tally, url=h.entity_url(self), scope=self.scope, subject=self.subject)
def test_sectionpage_entity_url(self): from adhocracy.lib.helpers import entity_url from adhocracy import model instance, user = self._make_content() page = model.Page.create(instance, u'test_page', u'text', user, sectionpage=True) url = u'http://test.test.lan/page/test_page' self.assertEqual(entity_url(page), url)
def show(self, id, format="html"): c.page_instance = get_entity_or_abort(model.Instance, id) require.instance.show(c.page_instance) if format == "json": return render_json(c.page_instance) if format == "rss": return self.activity(id, format) if c.page_instance != c.instance: redirect(h.entity_url(c.page_instance)) c.tile = tiles.instance.InstanceTile(c.page_instance) proposals = model.Proposal.all(instance=c.page_instance) c.new_proposals_pager = pager.proposals( proposals, size=7, enable_sorts=False, enable_pages=False, default_sort=sorting.entity_newest ) c.sidebar_delegations = ( _("Delegations are enabled.") if c.page_instance.allow_delegate else _("Delegations are disabled.") ) # pages = model.Page.all(instance=c.page_instance, # functions=[model.Page.NORM]) # c.top_pages_pager = pager.pages( # pages, size=7, enable_sorts=False, # enable_pages=False, default_sort=sorting.norm_selections) # tags = model.Tag.popular_tags(limit=40) # c.tags = sorted(text.tag_cloud_normalize(tags), # key=lambda (k, c, v): k.name) if asbool(config.get("adhocracy.show_instance_overview_milestones")) and c.page_instance.milestones: number = asint(config.get("adhocracy.number_instance_overview_milestones", 3)) milestones = model.Milestone.all_future_q(instance=c.page_instance).limit(number).all() c.next_milestones_pager = pager.milestones( milestones, size=number, enable_sorts=False, enable_pages=False, default_sort=sorting.milestone_time ) events = model.Event.find_by_instance(c.page_instance, limit=3) c.events_pager = pager.events(events, enable_pages=False, enable_sorts=False) c.stats = { "comments": model.Comment.all_q().count(), "proposals": model.Proposal.all_q(instance=c.page_instance).count(), "members": model.Membership.all_q().count(), } c.tutorial_intro = _("tutorial_instance_show_intro") c.tutorial = "instance_show" return render("/instance/show.html")
def _common_metadata(self, user, member=None, add_canonical=False): bio = user.bio if not bio: bio = _("%(user)s is using Adhocracy, a democratic " "decision-making tool.") % { 'user': c.page_user.name } description = h.truncate(text.meta_escape(bio), length=200, whole_word=True) h.add_meta("description", description) h.add_meta("dc.title", text.meta_escape(user.name)) h.add_meta("dc.date", user.access_time.strftime("%Y-%m-%d")) h.add_meta("dc.author", text.meta_escape(user.name)) h.add_rss( _("%(user)ss Activity") % {'user': user.name}, h.entity_url(user, format='rss')) if c.instance and not user.is_member(c.instance): h.flash( _("%s is not a member of %s") % (user.name, c.instance.label), 'notice') if user.banned: h.flash(_("%s is banned from the system.") % user.name, 'notice')
def ret_status(type_, message, category=None, entity=None, member=None, code=200, format='html', force_path=None): import adhocracy.lib.helpers as h response.status_int = code if code != 200: if format == 'json': return ret_json_status(type_, message, code) request.environ['adhocracy.error_message'] = message abort(code, message) if message: if format == 'json': return ret_json_status(type_, message, code) h.flash(message, category) if force_path: # neither None nor '' redirect(force_path) if entity is not None: redirect(h.entity_url(entity, format=format, member=member)) redirect(h.base_url())
def index(self, format='html'): require.proposal.index() if c.instance: redirect(h.entity_url(c.instance)) c.instances = model.Instance.all()[:5] c.page = StaticPage('index') #query = self.form_result.get('proposals_q') #proposals = libsearch.query.run(query, # entity_type=model.Proposal)[:10] c.milestones = model.Milestone.all() #c.proposals_pager = pager.proposals(proposals) #c.proposals = c.proposals_pager.here() c.stats_global = { "members": model.User.all_q().count(), "comments": model.Comment.all_q().count(), "proposals": model.Proposal.all_q().count(), "votes": model.Vote.all_q().count(), } #if format == 'json': # return render_json(c.proposals_pager) return render('index.html')
class SelectionController(BaseController): @RequireInstance def index(self, proposal_id, format="html"): return self.not_implemented() @RequireInstance @guard.norm.propose() def propose(self, proposal_id, errors=None, format=u'html'): return self._new(proposal_id, '/selection/propose.html', errors, format=format) @RequireInstance def include(self, proposal_id, errors={}, format=u'html'): return self._new(proposal_id, '/selection/include.html', errors, format=format) def _new(self, proposal_id, template, errors, format=u'html'): c.proposal = get_entity_or_abort(model.Proposal, proposal_id) require.selection.create(c.proposal) defaults = dict(request.params) c.proposal_tile = tiles.proposal.ProposalTile(c.proposal) c.exclude_pages = [s.page for s in c.proposal.selections] q = model.meta.Session.query(model.Page) q = q.filter(model.Page.function == model.Page.NORM) q = q.filter(model.Page.instance == c.instance) q = q.filter(model.Page.allow_selection == False) # noqa c.exclude_pages += q.all() html = render(template, overlay=format == u'overlay') return htmlfill.render(html, defaults=defaults, errors=errors, force_defaults=False) @RequireInstance @RequireInternalRequest(methods=['POST']) def create(self, proposal_id, format='html'): c.proposal = get_entity_or_abort(model.Proposal, proposal_id) require.selection.create(c.proposal) try: self.form_result = SelectionCreateForm().to_python(request.params) except Invalid, i: return self.propose(proposal_id, errors=i.unpack_errors()) page = self.form_result.get('page') selection = model.Selection.create(c.proposal, page, c.user) model.meta.Session.commit() # TODO implement: # TODO emit an event if len(page.variants) < 2: return redirect( h.entity_url(page, member='branch', query={'proposal': c.proposal.id})) return redirect(h.entity_url(selection))
event_msg, text=no_text, notify_self=False): self.event_msg = event_msg super(EventType, self).__init__(code, pri, subject, link_path, text=text, notify_self=notify_self) T_USER_CREATE = EventType(u"t_user_create", pri=2, subject=lambda: _(u"New user: %(user)s"), link_path=lambda e: h.entity_url(e.user), event_msg=lambda: _(u"signed up")) T_USER_EDIT = EventType(u"t_user_edit", pri=1, subject=lambda: _(u"%(user)s: profile updated"), link_path=lambda e: h.entity_url(e.user), event_msg=lambda: _(u"edited their profile"), text=lambda e: e.user.bio, notify_self=True) T_USER_ADMIN_EDIT = EventType( u"t_user_admin_edit", pri=2, subject=lambda: _(u"%(user)s: profile was edited by %(admin)s"), link_path=lambda e: h.entity_url(e.user),
def votes_listing_url(self): return h.entity_url(self.poll, member="votes")
text=no_text, notify_self=False): self.event_msg = event_msg super(EventType, self).__init__(code, pri, subject, link_path, text=text, notify_self=notify_self) T_USER_CREATE = EventType(u"t_user_create", pri=2, subject=lambda: _(u"New user: %(user)s"), link_path=lambda e, absolute=False: (h.entity_url(e.user, absolute=absolute)), event_msg=lambda: _(u"signed up")) T_USER_EDIT = EventType(u"t_user_edit", pri=1, subject=lambda: _(u"%(user)s: profile updated"), link_path=lambda e, absolute=False: (h.entity_url(e.user, absolute=absolute)), event_msg=lambda: _(u"edited their profile"), text=lambda e: e.user.bio, notify_self=True) T_USER_ADMIN_EDIT = EventType( u"t_user_admin_edit", pri=2, subject=lambda: _(u"%(user)s: profile was edited by %(admin)s"),
def verify(self): if not openid_login_allowed(): ret_abort(_("OpenID login has been disabled on this installation"), code=403) self.consumer = create_consumer(self.openid_session) info = self.consumer.complete( request.params, h.base_url('/openid/verify', absolute=True)) if not info.status == SUCCESS: return self._failure(info.identity_url, _("OpenID login failed.")) email = None user_name = None # evaluate Simple Registration Extension data srep = sreg.SRegResponse.fromSuccessResponse(info) if srep: if srep.get('nickname'): user_name = srep.get('nickname').strip() if srep.get('email'): email = srep.get('email') # evaluate Attribute Exchange data # TBD: AXSCHEMA friendlyName # TBD: SignedMembership axrep = ax.FetchResponse.fromSuccessResponse(info) if axrep: ax_mail_schema = get_ax_mail_schema(info.identity_url) try: email = axrep.getSingle(ax_mail_schema) or email except ValueError: email = axrep.get(ax_mail_schema)[0] except KeyError: email = email if 'openid_session' in session: self.delete_session() oid = model.OpenID.find(info.identity_url) if oid: if c.user: if oid.user == c.user: return self._failure( info.identity_url, _("You have already claimed this OpenID.")) else: return self._failure( info.identity_url, _("OpenID %s is already connected to an account.") % (info.identity_url, oid.user.name)) else: self._login(oid.user) # returns else: if c.user: oid = model.OpenID(unicode(info.identity_url), c.user) model.meta.Session.add(oid) model.meta.Session.commit() h.flash(_("Successfully added OpenID to user account."), 'success') redirect(h.entity_url(c.user, member='settings/login')) else: if not h.allow_user_registration(): h.flash( _("OpenID %s doesn't belong to an existing user account " "and user registration is disabled in this " "installation." % info.identity_url), 'warning') redirect(h.base_url('/login')) user_by_email = model.User.find_by_email(email) if user_by_email is not None: if is_trusted_provider(info.identity_url): # A user with the email returned by the OpenID provider # exists. As we trust the OpenID provider, we log in # that account and assign the OpenID to this user. oid = model.OpenID(unicode(info.identity_url), user_by_email) model.meta.Session.add(oid) model.meta.Session.commit() h.flash( _("Successfully added OpenID to user account."), 'success') self._login(user_by_email) else: # A user with the email returned by the OpenID provider # exists. As we don't trust the OpenID provider, we # demand that the user needs to login first. # # Note: We could store the successful OpenID # authentication in the session and assign it after # login. However probably more is gained if the # list of trusted OpenID providers is extended. h.flash( _("The email address %s which was returned by the " "OpenID provider already belongs to a different " "user account. Please login with that account " "or use the forgot password functionality, and " "add the OpenID in your user profile settings " "afterwards. Sorry for the inconvenience." % email), 'warning') redirect(h.base_url('/login')) try: forms.UniqueUsername(not_empty=True).to_python(user_name) formencode.All(validators.PlainText(not_empty=True), forms.UniqueUsername(), forms.ContainsChar()) except: session['openid_req'] = (info.identity_url, user_name, email) session.save() redirect(h.base_url('/openid/username')) user = self._create(user_name, email, info.identity_url) h.flash( _("Successfully created new user account %s" % user_name), 'success') self._login(user, register=True)
def dispatch_delegateable(self, id): dgb = get_entity_or_abort(model.Delegateable, id, instance_filter=False) redirect(h.entity_url(dgb))
def html(self, message): return '<a href="%s">%s</a>' % (h.entity_url(message), cgi.escape(self.unicode(message)))
def show(self, id, format='html'): c.page_instance = get_entity_or_abort(model.Instance, id) require.instance.show(c.page_instance) if format == 'json': return render_json(c.page_instance) elif format == 'rss': return self.activity(id, format) if c.page_instance != c.instance: redirect(h.entity_url(c.page_instance)) c.tile = tiles.instance.InstanceTile(c.page_instance) c.sidebar_delegations = (_('Delegations are enabled.') if c.page_instance.allow_delegate else _('Delegations are disabled.')) overview_contents = config.get_list( 'adhocracy.instance_overview_contents') overview_sidebar_contents = config.get_list( 'adhocracy.instance_overview_sidebar_contents') if u'milestones' in overview_contents and c.page_instance.milestones: number = config.get_int( 'adhocracy.number_instance_overview_milestones') milestones = model.Milestone.all_future_q( instance=c.page_instance).limit(number).all() c.next_milestones_pager = pager.milestones( milestones, size=number, enable_sorts=False, enable_pages=False, default_sort=sorting.milestone_time) c.events_pager = None if u'events' in overview_contents: events = model.Event.find_by_instance(c.page_instance, limit=10) c.events_pager = pager.events(events, enable_pages=False, enable_sorts=False) c.sidebar_events_pager = None if u'events' in overview_sidebar_contents: events = model.Event.find_by_instance(c.page_instance, limit=3) c.sidebar_events_pager = pager.events(events, enable_pages=False, enable_sorts=False, row_type=u'sidebar_row') c.proposals_pager = None if u'proposals' in overview_contents: proposals = model.Proposal.all(instance=c.page_instance) if config.get_bool( 'adhocracy.show_instance_overview_proposals_all'): c.proposals_pager = pager.proposals(proposals, size=100, initial_size=100) else: c.proposals_pager = pager.proposals( proposals, size=7, enable_sorts=False, enable_pages=False, default_sort=sorting.entity_newest) c.stats = None if config.get_bool('adhocracy.show_instance_overview_stats'): c.stats = { 'comments': model.Comment.all_q().count(), 'proposals': model.Proposal.all_q( instance=c.page_instance).count(), 'members': model.Membership.all_q().count() } c.tutorial_intro = _('tutorial_instance_show_intro') c.tutorial = 'instance_show' if c.page_instance.hidden: h.flash(_(u"This instance is not yet open for public " u"participation."), 'warning') elif c.page_instance.frozen: h.flash(_(u"This instance is not active for use and is archived. " u"It isn't possible to perform any changes to the " u"instance, but all content is available to be read."), 'warning') if format == 'overlay': return render("/instance/show.html", overlay=True) else: return render("/instance/show.html")
def for_entity(entity): from adhocracy.lib.helpers import entity_url return for_url(entity_url(entity, absolute=True))
def for_entity(entity): from adhocracy.lib.helpers import entity_url return for_url(entity_url(entity))
def untag(self, format='html'): tagging = self.form_result.get('tagging') require.tag.delete(tagging) tagging.delete() model.meta.Session.commit() redirect(h.entity_url(tagging.delegateable, format=format))
def verify(self): self.consumer = create_consumer(self.openid_session) info = self.consumer.complete(request.params, h.base_url(c.instance, path='/openid/verify')) if not info.status == SUCCESS: return self._failure(info.identity_url, _("OpenID login failed.")) email = None user_name = None # evaluate Simple Registration Extension data srep = sreg.SRegResponse.fromSuccessResponse(info) if srep: if srep.get('nickname'): user_name = srep.get('nickname').strip() if srep.get('email'): email = srep.get('email') # evaluate Attribute Exchange data # TBD: AXSCHEMA friendlyName # TBD: SignedMembership axrep = ax.FetchResponse.fromSuccessResponse(info) if axrep: try: email = axrep.getSingle(AX_MAIL_SCHEMA) or email except ValueError: email = axrep.get(AX_MAIL_SCHEMA)[0] except KeyError: email = email if 'openid_session' in session: del session['openid_session'] oid = model.OpenID.find(info.identity_url) if oid: if c.user: if oid.user == c.user: return self._failure(info.identity_url, _("You have already claimed this OpenID.")) else: return self._failure(info.identity_url, _("OpenID %s already belongs to %s.") % (info.identity_url, oid.user.name)) else: self._login(oid.user) # returns else: if c.user: oid = model.OpenID(unicode(info.identity_url), c.user) model.meta.Session.add(oid) model.meta.Session.commit() redirect(h.entity_url(c.user, member='edit')) else: try: forms.UniqueUsername(not_empty=True).to_python(user_name) except: session['openid_req'] = (info.identity_url, user_name, email) session.save() redirect('/openid/username') user = self._create(user_name, email, info.identity_url) self._login(user) return self._failure(info.identity_url, _("Justin Case has entered the room."))
def html(self, comment): if comment.delete_time: return self.unicode(comment) return "<a href='%s'>%s</a>" % (h.entity_url(comment), cgi.escape(self.unicode(comment)))
def unicode(self, comment): return h.entity_url(comment)
def html(self, instance): return u"<a class='event_instance' href='%s'>%s</a>" % ( h.entity_url(instance), instance.label)
def settings_url(entity, name, force_url=None): full_path = 'settings/%s' % name if force_url is None else force_url if isinstance(entity, model.Instance): return h.entity_url(entity, member=full_path) else: return h.entity_url(entity, instance=c.instance, member=full_path)
def to_dict(self): from adhocracy.lib import helpers as h return dict(id=self.id, name=self.name, count=self.count, url=h.entity_url(self))