コード例 #1
0
ファイル: mail.py プロジェクト: tonny/CollabQ
def email_comment_notification(actor_to_ref, actor_from_ref, 
                               comment_ref, entry_ref):
    
  """Send an email in response to a comment being posted.
  PARAMETERS:
    actor_to_ref - actor whom this email is going to
    actor_from_ref - actor who posted the comment
    comment_ref - the comment that was posted
    entry_ref - the entry that was commented on
  RETURNS: (subject, message)
  """

  SITE_NAME = util.get_metadata('SITE_NAME')
  DOMAIN = settings.DOMAIN
  POST_NAME = util.get_metadata('POST_NAME')
  entry_url = entry_ref.url()
  entry_mobile_url = entry_ref.url(mobile=True)
  from_name = actor_from_ref.display_nick()
  my_entry = (actor_to_ref.nick == entry_ref.actor)
  entry_actor_name = util.display_nick(entry_ref.actor)
  entry_title = entry_ref.title()

  
  # TODO(termie) pretty 'r up
  comment_pretty = comment_ref.extra.get('content', '')

  t = loader.get_template('common/templates/email/email_comment.txt')
  c = template.Context(locals(), autoescape=False)
  message = t.render(c)
  html_template = loader.get_template('common/templates/email/email_comment.html')
  html_message = html_template.render(c)
  subject = 'New comment on %s' % (entry_ref.title())
  return (subject, message, html_message)
コード例 #2
0
ファイル: views.py プロジェクト: CollabQ/CollabQ
def openid_createuser(request):
  person = openidgae.get_current_person(request, http.HttpResponse())
  email = person.get_email()

  res = util_externals.reponse_if_exists(email)
  if res is not None:
    return res

  nick = util_externals.get_nick_from_email(email)
  
  params = {
    'nick': nick,
    'password': util.generate_password(),
    'first_name': person.get_field_value('firstname', 'none'),
    'last_name': person.get_field_value('lastname', 'none'),
    'fromopenid': True,
    'email':email,
  }
  
  actor_ref = util_externals.user_create('google', params, util.display_nick(email), email)
  
  # NOTE: does not provide a flash message
  response = util.RedirectFlash('/', 'Welcome to %s' % util.get_metadata('SITE_NAME'))
  user.set_user_cookie(response, actor_ref)
  return response
コード例 #3
0
ファイル: mail.py プロジェクト: tonny/CollabQ
def email_new_follower(owner_ref, target_ref):
  SITE_NAME = util.get_metadata('SITE_NAME')
  DOMAIN = settings.DOMAIN
  owner_full_name = _full_name(owner_ref)
  target_full_name = _full_name(target_ref)
  email_url = owner_ref.url()
  email_mobile_url = owner_ref.url(mobile=True)

  t = loader.get_template('common/templates/email/email_new_follower.txt')
  c = template.Context(locals(), autoescape=False)
  message = t.render(c)
  c.autoescape = True
  html_template = loader.get_template(
      'common/templates/email/email_new_follower.html')
  html_message = html_template.render(c)
  subject = '%s is now following you on %s!' % (owner_ref.display_nick(), util.get_metadata('SITE_NAME'))
  return (subject, message, html_message)
コード例 #4
0
ファイル: views.py プロジェクト: CollabQ/CollabQ
def install(request):
  try:
    root_user = api.actor_get(api.ROOT, settings.ROOT_NICK)
    if root_user:
      return util.RedirectFlash('/', 'Already Installed')
  except:
    root_user = None

  post_name = util.get_metadata('POST_NAME')
  default_channel = util.get_metadata('DEFAULT_CHANNEL')

  if request.POST:
    site_name = request.POST.get('site_name', None)
    tagline = request.POST.get('tagline', None)
    post_name = request.POST.get('post_name', None)

    root_mail = request.POST.get('root_mail', None)
    password = request.POST.get('password', None)
    confirm =  request.POST.get('confirm', None)
    default_channel = request.POST.get('default_channel', None)

    try:
      logging.info('saving values')
      validate.nonce(request, 'install')
      validate.email(root_mail)
      validate.password(password)
      validate.password_and_confirm(password, confirm)
      channel = clean.channel(default_channel)

      admin_helper.validate_and_save_sitesettings(site_name, tagline, post_name)
      root_user = api.user_create_root(api.ROOT, password=password)
      api.email_associate(api.ROOT, root_user.nick, root_mail)
      channel_ref = api.channel_create(api.ROOT, nick=api.ROOT.nick, channel=channel, tags=[],
                                       type='', description='Support Channel')
      util.set_metadata('DEFAULT_CHANNEL', default_channel)

      logging.info('Installed and Redirecting to front')
      return util.RedirectFlash('/', 'Installed Successfully')
    except:
      exception.handle_exception(request)

  redirect_to = '/'

  c = template.RequestContext(request, locals())
  return render_to_response('administration/templates/install.html', c)
コード例 #5
0
ファイル: mail.py プロジェクト: tonny/CollabQ
def email_invite(from_actor_ref, invite_code):
  SITE_NAME = util.get_metadata('SITE_NAME')
  POST_NAME = util.get_metadata('POST_NAME')
  SITE_DESCRIPTION = util.get_metadata('SITE_DESCRIPTION')
  DOMAIN = settings.DOMAIN
  full_name = _full_name(from_actor_ref)
  nick_name = from_actor_ref.display_nick()
  accept_url = 'http://%s/invite/email/%s' % (settings.DOMAIN, invite_code)
  accept_mobile_url = 'http://m.%s/invite/email/%s' % (settings.DOMAIN,
                                                       invite_code)

  t = loader.get_template('common/templates/email/email_invite.txt')
  c = template.Context(locals(), autoescape=False)
  message = t.render(c)
  c.autoescape = True
  html_template = loader.get_template(
      'common/templates/email/email_invite.html')
  html_message = html_template.render(c)
  subject = '%s welcomes you for a collaborative buzz@innoGems!' % full_name
  return (subject, message, html_message)
コード例 #6
0
ファイル: views.py プロジェクト: CollabQ/CollabQ
def login_logout(request):
  request.user = None
  redirect_to = '/'
  flash = "You have signed out! You are no longer signed in to %s" % util.get_metadata('SITE_NAME')
  c = template.RequestContext(request, locals())
  t = loader.get_template('login/templates/logout.html')

  #response = http.HttpResponseRedirect(redirect_to)
  response = util.RedirectFlash(redirect_to, flash)
  response = user.clear_user_cookie(response)
  return response
コード例 #7
0
ファイル: views.py プロジェクト: CollabQ/CollabQ
def admin_site(request):
  page = 'site'
  title = 'Site Settings'
  
  site_name = util.get_metadata('SITE_NAME')
  tagline = util.get_metadata('TAGLINE')
  post_name = util.get_metadata('POST_NAME')
  
  if request.POST:
    site_name = request.POST.get('site_name', None)
    tagline = request.POST.get('tagline', None)
    post_name = request.POST.get('post_name', None)
    site_description = request.POST.get('site_description', None)
    try:
      validate.nonce(request, 'site')
      admin_helper.validate_and_save_sitesettings(site_name, tagline, post_name, site_description)
    except exception.ValidationError:
      exception.handle_exception(request)

  c = template.RequestContext(request, locals())
  return render_to_response('administration/templates/site.html', c)
コード例 #8
0
ファイル: mail.py プロジェクト: tonny/CollabQ
def email_confirmation_message(actor, activation_code):
  SITE_NAME = util.get_metadata('SITE_NAME')
  DOMAIN = settings.DOMAIN
  name = _greeting_name(actor)
  # TODO(teemu): what is a canonical way to do get URLs in Django?
  activation_url = 'http://%s/confirm/email/%s' % (settings.DOMAIN, activation_code)
  activation_mobile_url = 'http://m.%s/confirm/email/%s' % (settings.DOMAIN,
                                                            activation_code)

  email_first = name
  email_link = activation_url
  email_mobile_link = activation_mobile_url

  t = loader.get_template('common/templates/email/email_confirm.txt')
  c = template.Context(locals(), autoescape=False)
  message = t.render(c)
  c.autoescape = True
  html_template = loader.get_template(
      'common/templates/email/email_confirm.html')
  html_message = html_template.render(c)
  subject = "Welcome to %s Please confirm your email" % util.get_metadata('SITE_NAME')
  return (subject, message, html_message)
コード例 #9
0
ファイル: views.py プロジェクト: CollabQ/CollabQ
def admin_channel(request):
  page = 'channel'
  title = 'Channels Settings'

  enable_channels = util.get_metadata('ENABLE_CHANNELS')
  enable_channel_types = util.get_metadata('ENABLE_CHANNEL_TYPES')
  
  if request.POST:
    enable_channels = request.POST.get('enable_channels', False)
    enable_channel_types = request.POST.get('enable_channel_types', False)
    
    try:
      validate.nonce(request, 'admin_channel')
      validate.bool_checkbox(enable_channels)
      validate.bool_checkbox(enable_channel_types)

      util.set_metadata('ENABLE_CHANNELS', str(enable_channels), 0, {'type':'bool'})
      util.set_metadata('ENABLE_CHANNEL_TYPES', str(enable_channel_types), 0, {'type':'bool'})

    except exception.ValidationError:
      exception.handle_exception(request)
    
  c = template.RequestContext(request, locals())
  return render_to_response('administration/templates/channel.html', c)
コード例 #10
0
ファイル: mail.py プロジェクト: tonny/CollabQ
def email_new_follower_mutual(owner_ref, target_ref):
  SITE_NAME = util.get_metadata('SITE_NAME')
  DOMAIN = settings.DOMAIN
  profile_url = owner_ref.url()
  profile_mobile_url = owner_ref.url(mobile=True)
  full_name = _full_name(owner_ref)

  t = loader.get_template(
      'common/templates/email/email_new_follower_mutual.txt')
  c = template.Context(locals(), autoescape=False)
  message = t.render(c)
  c.autoescape = True
  html_template = loader.get_template(
      'common/templates/email/email_new_follower_mutual.html')
  html_message = html_template.render(c)
  subject = '%s is now following you, too' % full_name
  return (subject, message, html_message)
コード例 #11
0
ファイル: mail.py プロジェクト: tonny/CollabQ
def email_lost_password(actor, email, code):
  SITE_NAME = util.get_metadata('SITE_NAME')
  DOMAIN = settings.DOMAIN
  email_link = ("http://%s/login/reset?email=%s&hash=%s" %
                (settings.DOMAIN, email, code))
  email_mobile_link = ("http://m.%s/login/reset?email=%s&hash=%s" %
                       (settings.DOMAIN, email, code))

  t = loader.get_template('common/templates/email/email_password.txt')
  c = template.Context(locals(), autoescape=False)
  message = t.render(c)
  c.autoescape = True
  html_template = loader.get_template(
      'common/templates/email/email_password.html')
  html_message = html_template.render(c)

  subject = ('Password reset')
  return (subject, message, html_message)
コード例 #12
0
ファイル: mail.py プロジェクト: tonny/CollabQ
def email_dm(actor_ref, owner_ref, direct_message):
  SITE_NAME = util.get_metadata('SITE_NAME')
  DOMAIN = settings.DOMAIN
  actor_fullname = _full_name(actor_ref)
  fullname = _full_name(owner_ref)

  email_link = ("http://%s/inbox?reply=%s" %
                (settings.DOMAIN, actor_ref.display_nick()))
  
  t = loader.get_template('common/templates/email/email_dm.txt')
  c = template.Context(locals(), autoescape=False)
  message = t.render(c)
  c.autoescape = True
  html_template = loader.get_template(
      'common/templates/email/email_dm.html')
  html_message = html_template.render(c)

  subject = ('Direct message from %s' % actor_fullname)
  return (subject, message, html_message)
コード例 #13
0
ファイル: util.py プロジェクト: CollabQ/CollabQ
def user_create(service, params, username="", id="", remote_url=""):
    logging.info("user_create")
    actor_ref = api.user_create(api.ROOT, **params)
    actor_ref.access_level = "delete"

    api.post(actor_ref, nick=actor_ref.nick, message="Joined %s!" % (util.get_metadata("SITE_NAME")))

    email = params.get("email", None)
    if email is not None:
        api.email_associate(api.ROOT, actor_ref.nick, email)
    else:
        key = "emailneeded_%s" % util.display_nick(actor_ref.nick)
        memcache.client.set(key, True, 360)

    key = "firsttime_%s" % util.display_nick(actor_ref.nick)
    memcache.client.set(key, True, 360)

    external_profile_ref = api.create_external_profile(actor_ref.nick, service, username, id, remote_url)

    return actor_ref
コード例 #14
0
ファイル: views.py プロジェクト: CollabQ/CollabQ
def channel_create(request, format='html'):
  if not util.get_metadata('ENABLE_CHANNELS'):
    raise exception.AdminRequiredError
  
  channel = request.REQUEST.get('channel', '')

  handled = common_views.handle_view_action(
      request,
      {'channel_create': '/channel/%s' % channel,
       }
      )
  if handled:
    return handled

  # for template sidebar
  sidebar_green_top = True

  area = 'channel'
  c = template.RequestContext(request, locals())

  if format == 'html':
    t = loader.get_template('channel/templates/create.html')
    return http.HttpResponse(t.render(c))
コード例 #15
0
ファイル: views.py プロジェクト: CollabQ/CollabQ
def channel_browse(request, format='html', tagkey=None):
  per_page = CHANNELS_PER_PAGE
  page = util.paging_get_page(request)
  filter = util.paging_filter(request)
  type = util.paging_type(request)

  if request.user:
    view = request.user
    owner = api.actor_lookup_nick(view, util.get_owner(request))
  else:
    view = api.ROOT
    owner = api.actor_lookup_nick(view, view.nick)

  nick = view.nick

  if filter == 'member':
    actors, size = api.channel_browse_tagkey(view, per_page, page, tagkey, type, nick)
  else:
    actors, size = api.channel_browse_tagkey(view, per_page, page, tagkey, type)

  start, end, next, prev, first, last = util.paging(page, per_page, size)
  
  for c in actors:
    if request.user:
      c.i_am_member = api.actor_is_a_member(request.user, request.user.nick, c.nick)
    else:
      c.i_am_member = False
    c.tags_ref = api.channel_get_tags(view, c.tags)

  if tagkey is not None:
    base_url = '/channel/browse%s?' % tagkey
    breadcrumb = channel_helper.get_breadcrumb(view, tagkey)
  else:
    base_url = '/channel?'
    
  filter_url = util.paging_url(filter, nick, owner.nick)

  type_url = ''
  if type is not None:
    type_url = '&type=%s' % type

  countries = api.tags_get_countries(view, util.get_metadata('DEFAULT_TAG'))

  if request.user:
    country_tag = request.user.extra.get('country_tag', '/tag_geo/North America/United States')
  else:
    country_tag = '/tag_geo/North America/United States'

  channel_nicks, other = api.channel_browse_tagkey(view, 5, 1, country_tag)

  related_tags = api.channel_get_children_tags(view, tagkey)    
  related_tags = api.channel_get_tags(view, related_tags)

  show_tags_url = True
  
  channel_types = util.get_metadata('CHANNEL_TYPES')

  area = 'channel'
  
  c = template.RequestContext(request, locals())
  # TODO(tyler): Other output formats.
  if format == 'html':
    t = loader.get_template('channel/templates/browse_tag.html')
    return http.HttpResponse(t.render(c))
コード例 #16
0
ファイル: sms.py プロジェクト: CollabQ/CollabQ
  def test_sign_in(self):
    nick = 'popular'
    password = self.passwords[clean.nick(nick)]

    r = self.receive('SIGN IN %s %s' % (nick, password))
    self.assertOutboxContains(r, 'Welcome to %s SMS %s' % (util.get_metadata('SITE_NAME'), nick))
コード例 #17
0
ファイル: views.py プロジェクト: CollabQ/CollabQ
def join_join(request):
  if request.user:
    raise exception.AlreadyLoggedInException()

  redirect_to = request.REQUEST.get('redirect_to', '/')

  account_types = api.get_config_values(api.ROOT, 'account_type')

  # get the submitted vars
  nick = request.REQUEST.get('nick', '');
  first_name = request.REQUEST.get('first_name', '');
  last_name = request.REQUEST.get('last_name', '');
  email = request.REQUEST.get('email', '');
  password = request.REQUEST.get('password', '');
  confirm = request.REQUEST.get('confirm', '');
  hide = request.REQUEST.get('hide', '');
  country_tag = request.REQUEST.get('country_tag', '')

  if request.POST:
    try:
      # TODO validate
      params = util.query_dict_to_keywords(request.POST)

      if hide:
        params['privacy'] = 2

      # XXX: Check if the data come from a openid account
      # @author: [email protected]
      fromopenid = request.POST.get('fromopenid', False) and True
      if fromopenid:
        try:
          person = openidgae.get_current_person(request, http.HttpResponse())
        except:
          raise exception.ServiceError
        
        email = person.get_email()
        if email == params['email']:
          params['password'] = util.generate_password()
        else:
          raise exception.ServiceError

      # ENDXXX

      validate.email(email)
      if not mail.is_allowed_to_send_email_to(email):
        raise exception.ValidationError("Cannot send email to that address")

      # TODO start transaction
      if api.actor_lookup_email(api.ROOT, email):
        raise exception.ValidationError(
            'That email address is already associated with a member.')
      
      actor_ref = api.user_create(api.ROOT, **params)
      actor_ref.access_level = "delete"

      api.post(actor_ref, 
               nick=actor_ref.nick, 
               message='Joined %s!' % (util.get_metadata('SITE_NAME')))
      if fromopenid:
        api.email_associate(api.ROOT, actor_ref.nick, email)
      else:
        # send off email confirmation
        api.activation_request_email(actor_ref, actor_ref.nick, email)

      logging.info('setting firsttime_%s from register page' % actor_ref.nick)
      memcache.client.set('firsttime_%s' % nick, True)
      # TODO end transaction
      welcome_url = util.qsa('/', {'redirect_to': redirect_to})

      # NOTE: does not provide a flash message
      response = http.HttpResponseRedirect(welcome_url)
      user.set_user_cookie(response, actor_ref)
      return response
    except:
      exception.handle_exception(request)

  # for legal section
  legal_component = component.include('legal', 'dummy_legal')
  legal_html = legal_component.embed_join()
  
  # for sidebar
  sidebar_green_top = True

  area = "join"
  c = template.RequestContext(request, locals())

  t = loader.get_template('join/templates/join.html')
  return http.HttpResponse(t.render(c))
コード例 #18
0
ファイル: sms.py プロジェクト: CollabQ/CollabQ
import logging
import re

from django.conf import settings

from common import api
from common import clean
from common import exception
from common import patterns
from common import user
from common import util
from common.protocol import base
from common.protocol import sms

HELP_HUH = "Sorry, did not understand \"%s\". Send HELP for commands"
HELP_WELCOME = "Welcome to %s SMS! Questions? Contact support@%s" % (util.get_metadata('SITE_NAME'), settings.HOSTED_DOMAIN)
HELP_WELCOME_NICK = "Welcome to %s SMS %s! Questions? Contact support@%s" % (util.get_metadata('SITE_NAME'), '%s', settings.HOSTED_DOMAIN)
HELP_DOUBLE_OPT_IN = "To confirm you'd like to receive SMS updates, reply YES. You'll only have to do this once."
HELP_SIGNED_OUT = "You have signed out."
HELP_CHARGES = "%s is free. Other charges may apply." % (util.get_metadata('SITE_NAME'))
HELP_HELP_1 = "%s SMS updates. To get alerts text FOLLOW user/channelname. To stop text LEAVE user/channelname. To stop all alerts text STOP. To resume text START" % (util.get_metadata('SITE_NAME'))
HELP_HELP_2 = "Complete list on %s/sms. Other charges may apply. Questions? Contact support@%s" % (settings.DOMAIN, settings.HOSTED_DOMAIN)

HELP_NOT_SIGNED_IN = "You are currently signed out\n"
HELP_SIGNED_IN_AS = "You are signed in as '%s'\n"
HELP_FOLLOW_ONLY = "You are signed in as a follow-only user\n"
HELP_PASSWORD = "******" \
                "Use it to sign in on the web at http://%s/\n" % ('%s', settings.DOMAIN)
HELP_POST = "To post to your stream, just send a message"
HELP_CHANNEL_POST = "To post to a channel, start your message with " \
                    "#channel"
コード例 #19
0
ファイル: im.py プロジェクト: CollabQ/CollabQ
import re

from django.conf import settings

from common import api
from common import clean
from common import exception
from common import patterns
from common import user
from common import util
from common.protocol import base
from common.protocol import xmpp


HELP_HUH = "Sorry, did not understand \"%s\". Send HELP for commands"
HELP_WELCOME = "Welcome to %s IM!\n" % (util.get_metadata('SITE_NAME'))
HELP_WELCOME_NICK = "Welcome to %s IM, %s!\n" % (util.get_metadata('SITE_NAME'), '%s')
HELP_NOT_SIGNED_IN = "You are currently signed out\n"
HELP_SIGNED_IN_AS = "You are signed in as '%s'\n"
HELP_FOLLOW_ONLY = "You are signed in as a follow-only user\n"
HELP_PASSWORD = "******" \
                "Use it to sign in on the web at http://%s/\n" % ('%s', settings.DOMAIN)
HELP_POST = "To post to your stream, just send a message"
HELP_CHANNEL_POST = "To post to a channel, start your message with " \
                    "#channel"
HELP_COMMENT = "To comment the latest update from someone, start " \
               "with @user"
HELP_FOLLOW = "To follow a user or channel, send FOLLOW <user/#channel>"
HELP_FOLLOW_NEW = "Send FOLLOW <user/#channel> to just follow a user or " \
                  "channel without signing up"
HELP_LEAVE = "To stop following a user or channel, send LEAVE <user/#channel>"
コード例 #20
0
ファイル: context_processors.py プロジェクト: CollabQ/CollabQ
def settings(request):

  d = dict([(k, util.get_metadata(k))
            for k in django_settings.get_all_members()])
  return dict(**d)