コード例 #1
0
    def promote_user(self, from_jid, nick):
        ji_ref = api.actor_lookup_im(api.ROOT, from_jid.base())
        if jid_ref:
            # TODO(tyler): Should we tell the user who they are?
            raise exception.ValidationError(
                "You already have an account and are signed in.")

        if not NICK_RE.match(nick):
            raise exception.ValidationError(
                "Invalid screen name, can only use letters or numbers, 3 to 16 "
                "characters")

        # Create the user.  (user_create will check to see if the account has
        # already been created.)
        password = util.generate_uuid()[:8]

        # TODO(termie): Must have a first/last name. :(
        actor = api.user_create(api.ROOT,
                                nick=nick,
                                password=password,
                                given_name=nick,
                                family_name=nick)

        # link this im account to the user's account (equivalent of SIGN IN)
        self.sign_in(from_jid, nick, password)

        # Inform the user of their new password
        welcome = '\n'.join([
            HELP_WELCOME_NICK % nick, HELP_PASSWORD % password, HELP_POST,
            HELP_CHANNEL_POST, HELP_COMMENT, HELP_FOLLOW, HELP_STOP, HELP_MORE,
            HELP_FOOTER
        ])

        self.send_message([from_jid], welcome)
コード例 #2
0
ファイル: im.py プロジェクト: Git-Host/jaikuengine
  def promote_user(self, from_jid, nick):
    ji_ref = api.actor_lookup_im(api.ROOT, from_jid.base())
    if jid_ref:
      # TODO(tyler): Should we tell the user who they are?
      raise exception.ValidationError(
          "You already have an account and are signed in.")

    if not NICK_RE.match(nick):
      raise exception.ValidationError(
          "Invalid screen name, can only use letters or numbers, 3 to 16 "
          "characters")

    # Create the user.  (user_create will check to see if the account has
    # already been created.)
    password = util.generate_uuid()[:8]

    # TODO(termie): Must have a first/last name. :(
    actor = api.user_create(api.ROOT, nick=nick, password=password,
                            given_name=nick, family_name=nick)

    # link this im account to the user's account (equivalent of SIGN IN)
    self.sign_in(from_jid, nick, password)

    # Inform the user of their new password
    welcome = '\n'.join([HELP_WELCOME_NICK % nick,
                         HELP_PASSWORD % password,
                         HELP_POST,
                         HELP_CHANNEL_POST,
                         HELP_COMMENT,
                         HELP_FOLLOW,
                         HELP_STOP,
                         HELP_MORE,
                         HELP_FOOTER])

    self.send_message([from_jid], welcome)
コード例 #3
0
ファイル: user.py プロジェクト: frankk00/realtor
def generate_user_auth_token(nick,
                             password,
                             timeout=(14 * 24 * 60 * 60)):
  """ Generates a user authentication token and stores it in the
  database for later retrieval.

  Why store tokens in the database? Because GAE flushes memcache quite
  aggressively and this was causing users to be logged out much more
  frequently than was acceptable.

  """
  # Clear cache of expired tokens
  purge_expired_user_auth_token_keys()

  token = util.hash_generic(util.generate_uuid())
  key = generate_user_auth_token_key(nick, token)
  # Set an expiration date to enable us to purge old, inactive
  # sessions from the database. Cookie expiration dates are what
  # actually govern how long sessions last.
  expire_date = (api.utcnow() +
                 datetime.timedelta(seconds=timeout))
  session = Session(key_name=key,
                    session_data=db.Blob(password.encode("utf-8")),
                    expire_date=expire_date)
  session.put()
  return token
コード例 #4
0
ファイル: forms.py プロジェクト: zerofuxor/ContentQ-CMS
 def save(self, commit=True):
   self.cleaned_data["username"] = self.cleaned_data["username"].lower()
   user = super(RegisterForm, self).save(commit=False)
   user.code = util.generate_uuid()
   user.set_password(self.cleaned_data["password1"])
   if commit:
     user.save()
   return user
コード例 #5
0
ファイル: models.py プロジェクト: josezambrana/ContentQ-CMS
 def __init__(self, *args, **kw):
   if not 'uuid' in kw or not kw['uuid']:
     kw['uuid'] = util.generate_uuid()
     
   if not 'key_name' in kw and 'key' not in kw:
     kw['key_name'] = self.key_from(**kw)
     
   super(BaseModel, self).__init__(*args, **kw)
   self.app_label = self.applabel()
コード例 #6
0
ファイル: views.py プロジェクト: zhoujh/jaikuengine
def login_login(request):
    redirect_to = request.REQUEST.get('redirect_to', '/')
    redirect_to = clean.redirect_to(redirect_to)

    if request.POST:
        try:
            login = request.POST.get('log', None)
            password = request.POST.get('pwd', None)
            rememberme = request.POST.get('rememberme', None)

            # TODO validate

            current_user = user.lookup_user_by_login(login, password)
            if current_user:
                if redirect_to == '/':
                    redirect_to = current_user.url('/overview')

                # Attempt to do some cleanup on the user if necessary
                api.user_cleanup(api.ROOT, current_user.nick)

                # if we aren't hosted or aren't ssl just set the cookie and go home
                if (not settings.HOSTED_DOMAIN_ENABLED
                        or not settings.SSL_LOGIN_ENABLED):
                    response = http.HttpResponseRedirect(redirect_to)
                    response = user.set_user_cookie(response, current_user,
                                                    rememberme)
                    return response

                # otherwise, we're going to have to redirect to set the cookie on
                # the proper domain
                sso_token = util.generate_uuid()

                cache.set('sso/%s' % sso_token,
                          (current_user.nick, rememberme),
                          timeout=10)
                sso_url = 'http://%s/login/noreally' % (settings.DOMAIN)
                sso_url = util.qsa(sso_url, {
                    'redirect_to': redirect_to,
                    'sso_token': sso_token
                })
                return http.HttpResponseRedirect(sso_url)
            else:
                raise exception.ValidationError("Invalid username or password")
        except:
            exception.handle_exception(request)

    if request.user:
        if redirect_to == '/':
            redirect_to = request.user.url('/overview')
        return http.HttpResponseRedirect(redirect_to)

    c = template.RequestContext(request, locals())
    t = loader.get_template('login/templates/login.html')
    return http.HttpResponse(t.render(c))
コード例 #7
0
ファイル: models.py プロジェクト: zerofuxor/ContentQ-CMS
 def create_blob(cls, name='', content=None, content_type=None, user=None):
   params = {
     'name':name,
     'slug':unicode(slugify(name)),
     'uuid':util.generate_uuid(),
     'user':user.username,
     'content':content,
     'content_type': content_type,
     #'privacy': user.privacy
   }
   blob_ref = cls(**params)
   blob_ref.put()
   return blob_ref
コード例 #8
0
ファイル: views.py プロジェクト: CollabQ/CollabQ
def login_login(request):
  redirect_to = request.REQUEST.get('redirect_to', '/')
  redirect_to = clean.redirect_to(redirect_to)
  
  if request.POST:
    try:
      login = request.POST.get('log', None)
      password = request.POST.get('pwd', None)
      rememberme = request.POST.get('rememberme', None)

      # TODO validate

      current_user = user.lookup_user_by_login(login, password)
      if current_user:
        if redirect_to == '/':
          redirect_to = current_user.url('/overview')

        # Attempt to do some cleanup on the user if necessary
        api.user_cleanup(api.ROOT, current_user.nick)

        
        # if we aren't hosted or aren't ssl just set the cookie and go home
        if (not settings.HOSTED_DOMAIN_ENABLED 
            or not settings.SSL_LOGIN_ENABLED):
          response = http.HttpResponseRedirect(redirect_to)
          response = user.set_user_cookie(response, current_user, rememberme)
          return response
        
        # otherwise, we're going to have to redirect to set the cookie on
        # the proper domain
        sso_token = util.generate_uuid()

        cache.set('sso/%s' % sso_token, (current_user.nick, rememberme), timeout=10)
        sso_url = 'http://%s/login/noreally' % (settings.DOMAIN)
        sso_url = util.qsa(
            sso_url, {'redirect_to': redirect_to, 'sso_token': sso_token})
        return http.HttpResponseRedirect(sso_url)
      else:
        raise exception.ValidationError("Invalid username or password")
    except:
      exception.handle_exception(request)
  view =user.get_user_from_cookie_or_legacy_auth(request)
  area="login"
  if view:
    if redirect_to == '/':
      redirect_to = request.user.url('/overview')
    return http.HttpResponseRedirect(redirect_to)
  
  c = template.RequestContext(request, locals())    
  t = loader.get_template('login/templates/login.html')
  return http.HttpResponse(t.render(c))
コード例 #9
0
ファイル: forms.py プロジェクト: zerofuxor/ContentQ-CMS
 def save(self):
   super(InstallForm, self).save()
   params = {"username":self.cleaned_data["username"].lower(),
             "first_name":self.cleaned_data["first_name"],
             "last_name":self.cleaned_data["last_name"],
             "email":self.cleaned_data["email"],
             "active":True,
             "superuser":True,
             "roles":['authenticated', 'administrator']}
   user = User(**params)
   user.code = util.generate_uuid()
   user.set_password(self.cleaned_data["password1"])
   user.save()
   ConfigData.set_configdata('ADMIN_USERNAME', user.username)
   return user
コード例 #10
0
ファイル: clean.py プロジェクト: frankk00/realtor
class CleanImageTest(CleanTest):
  good_data = [
    '%s/bg_%s.jpg' % ('*****@*****.**', '012340'),
    '%s/bg_%s.jpg' % ('*****@*****.**', '0123af'),

    # How about a deterministic test:
    '%s/bg_%s.jpg' % ('*****@*****.**', util.generate_uuid()),
    None
  ]

  bad_data = [
    '%s/bg_%s.jpg' % ('popu@[email protected]', '012340'),
    '%s/bg_%s.jpg' % ('*****@*****.**', '0123afx'),
  ]

  normalize_data = [(x, x) for x in good_data]
  cleaner = staticmethod(clean.bg_image)
コード例 #11
0
ファイル: models.py プロジェクト: josezambrana/ContentQ-CMS
  def create_thumbails(cls, name, content, content_type, username='******', sizes={}):
    _name = _name = util.generate_uuid()[:6] + name
    blob_ref = cls.create_blob(_name, content, content_type, username)
    
    thumbails = {}

    for size, dimensions in sizes.iteritems(): 
      image = images.Image(blob_ref.content)

      original_width, original_height = float(image.width), float(image.height)
      width, height = dimensions
      f_width, f_height = float(width), float(height)

      if original_width > original_height:
        right_x = (f_width * original_height)/(f_height * original_width)
        bottom_y = 1.0
        if right_x > 1.0:
          bottom_y = 1.0 / right_x
          right_x = 1.0
      else:
        right_x = 1.0
        bottom_y = (f_height * original_width)/(f_width * original_height)
        if bottom_y > 1.0:
          right_x = 1.0 / bottom_y
          bottom_y = 1.0
      
      image.crop(0.0, 0.0, right_x, bottom_y)

      image.resize(width, height)

      img_content = image.execute_transforms(images.JPEG)

      thumbail_name = "thumbail_%s_%s" % (blob_ref.name, size)
      cls.create_blob(name=thumbail_name,
                      content=img_content,
                      content_type=content_type,
                      username=username)
      thumbails[size] = reverse('blob_serve', args=[thumbail_name])
    return thumbails
コード例 #12
0
ファイル: forms.py プロジェクト: zerofuxor/ContentQ-CMS
 def save(self):
   if self.instance is None:
     params = {'uuid':util.generate_uuid()}
     self.cleaned_data.update(params)
     
   return super(BaseForm, self).save()
コード例 #13
0
def generate_user_auth_token(nick, password, timeout=(14 * 24 * 60 * 60)):
    token = util.hash_generic(util.generate_uuid())
    cache.set("user_auth_token/%s/%s" % (nick, token), password, timeout)
    return token
コード例 #14
0
ファイル: models.py プロジェクト: zerofuxor/ContentQ-CMS
 def create_blob_from_file(cls, file, user, **kwargs):
   _name = util.generate_uuid()[:6] + kwargs.pop('filename', file.name)
   return cls.create_blob(name=_name,
                      content=file.read(),
                      content_type=file.content_type,
                      user=user)
コード例 #15
0
ファイル: forms.py プロジェクト: zerofuxor/ContentQ-CMS
 def save(self):
   self.user.set_password(self.cleaned_data["password1"])
   self.user.code = util.generate_uuid()
   self.user.put()
コード例 #16
0
ファイル: forms.py プロジェクト: zerofuxor/ContentQ-CMS
 def send_instructions(self):
   self.user.code = util.generate_uuid()
   self.user.put()
   mail_password_instructions(self.user, self.user.code)
コード例 #17
0
ファイル: user.py プロジェクト: AloneRoad/Inforlearn
def generate_user_auth_token(nick, password, timeout=(14 * 24 * 60 * 60)):
    token = util.hash_generic(util.generate_uuid())
    cache.set("user_auth_token/%s/%s" % (nick, token), password, timeout)
    return token
コード例 #18
0
ファイル: forms.py プロジェクト: josezambrana/ContentQ-CMS
 def save(self):
   logging.info("***** Form save")
   self.user.set_password(self.cleaned_data["password1"])
   self.user.code = util.generate_uuid()
   logging.info("    * code: %s" % self.user.code)
   self.user.put()