Exemplo n.º 1
0
def create_user_db(auth_id, name, username, email='', verified=False, **props):
    email = email.lower() if email else ''
    if verified and email:
        user_dbs, cursors = model.User.get_dbs(email=email,
                                               verified=True,
                                               limit=2)
        if len(user_dbs) == 1:
            user_db = user_dbs[0]
            user_db.auth_ids.append(auth_id)
            user_db.put()
            task.new_user_notification(user_db)
            return user_db

    if isinstance(username, str):
        username = username.decode('utf-8')
    username = unidecode.unidecode(username.split('@')[0].lower()).strip()
    username = re.sub(r'[\W_]+', '.', username)
    new_username = username
    n = 1
    while not model.User.is_username_available(new_username):
        new_username = '******' % (username, n)
        n += 1

    user_db = model.User(name=name,
                         email=email,
                         username=new_username,
                         auth_ids=[auth_id] if auth_id else [],
                         verified=verified,
                         token=util.uuid(),
                         **props)
    user_db.put()
    task.new_user_notification(user_db)
    return user_db
Exemplo n.º 2
0
def create_user_db(auth_id, name, username, email='', verified=False, **props):
  email = email.lower() if email else ''
  if verified and email:
    user_dbs, _ = model.User.get_dbs(email=email, verified=True, limit=2)
    if len(user_dbs) == 1:
      user_db = user_dbs[0]
      user_db.auth_ids.append(auth_id)
      user_db.put()
      task.new_user_notification(user_db)
      return user_db

  if isinstance(username, str):
    username = username.decode('utf-8')
  username = unidecode.unidecode(username.split('@')[0].lower()).strip()
  username = re.sub(r'[\W_]+', '.', username)
  new_username = username
  n = 1
  while not model.User.is_username_available(new_username):
    new_username = '******' % (username, n)
    n += 1

  user_db = model.User(
      name=name,
      email=email,
      username=new_username,
      auth_ids=[auth_id],
      verified=verified,
      token=util.uuid(),
      **props
    )
  user_db.put()
  task.new_user_notification(user_db)
  return user_db
Exemplo n.º 3
0
def create_user_db(auth_id,
                   name,
                   username,
                   email='',
                   verified=False,
                   password='',
                   avatar_url=None,
                   **props):
    """Saves new user into datastore"""
    if password:
        password = util.password_hash(password)

    email = email.lower()
    if not avatar_url:
        avatar_url = '//gravatar.com/avatar/%(hash)s?d=identicon&r=x' % {
            'hash': hashlib.md5(
                (email or username).encode('utf-8')).hexdigest()
        }

    user_db = model.User(name=name,
                         email=email,
                         username=username,
                         auth_ids=[auth_id] if auth_id else [],
                         verified=verified,
                         token=util.uuid(),
                         password_hash=password,
                         avatar_url=avatar_url,
                         **props)
    user_db.put()
    task.new_user_notification(user_db)
    return user_db
Exemplo n.º 4
0
def create_user_db(auth_id, username, email, verified, password, **props):
    """Saves new user into datastore

    Args:
        auth_id:
        username:
        email:
        verified:
        password:
        **props:
    """
    if password:
        password = util.password_hash(password)

    email = email.lower()
    username = username.lower()

    user_db = model.User(email=email,
                         username=username,
                         auth_ids=[auth_id] if auth_id else [],
                         verified=verified,
                         token=util.uuid(),
                         password_hash=password,
                         **props)
    user_db.put()
    task.new_user_notification(user_db)
    return user_db
Exemplo n.º 5
0
def create_user_db(auth_id, name, username, email="", **params):
    username = re.sub(r"_+|-+|\s+", ".", username.split("@")[0].lower().strip())
    new_username = username
    n = 1
    while model.User.retrieve_one_by("username", new_username) is not None:
        new_username = "******" % (username, n)
        n += 1

    user_db = model.User(name=name, email=email.lower(), username=new_username, auth_ids=[auth_id], **params)
    user_db.put()
    task.new_user_notification(user_db)
    return user_db
Exemplo n.º 6
0
def create_user_db(auth_id, name, username, email='', **params):
    username = re.sub(r'_+|-+|\s+', '.',
                      username.split('@')[0].lower().strip())
    new_username = username
    n = 1
    while model.User.retrieve_one_by('username', new_username) is not None:
        new_username = '******' % (username, n)
        n += 1

    user_db = model.User(name=name,
                         email=email.lower(),
                         username=new_username,
                         auth_ids=[auth_id],
                         **params)
    user_db.put()
    task.new_user_notification(user_db)
    return user_db
Exemplo n.º 7
0
def create_user_db(auth_id, name, username, email='', **params):
    username = unidecode.unidecode(username.split('@')[0].lower()).strip()
    username = re.sub(r'[\W_]+', '.', username)
    new_username = username
    n = 1
    while not model.User.is_username_available(new_username):
        new_username = '******' % (username, n)
        n += 1

    user_db = model.User(name=name,
                         email=email.lower(),
                         username=new_username,
                         auth_ids=[auth_id],
                         **params)
    user_db.put()
    task.new_user_notification(user_db)
    return user_db
Exemplo n.º 8
0
def create_user_db(auth_id, name, username, email='', **params):
  username = re.sub(r'_+|-+|\s+', '.', username.split('@')[0].lower().strip())
  new_username = username
  n = 1
  while not model.User.is_username_available(new_username):
    new_username = '******' % (username, n)
    n += 1

  user_db = model.User(
      name=name,
      email=email.lower(),
      username=new_username,
      auth_ids=[auth_id],
      **params
    )
  user_db.put()
  task.new_user_notification(user_db)
  return user_db
Exemplo n.º 9
0
def create_user_db(auth_id, name, username, email='', **params):
  username = re.sub(r'_+|-+|\s+', '.', username.split('@')[0].lower().strip())
  new_username = username
  n = 1
  while model.User.retrieve_one_by('username', new_username) is not None:
    new_username = '******' % (username, n)
    n += 1

  user_db = model.User(
      name=name,
      email=email.lower(),
      username=new_username,
      auth_ids=[auth_id],
      **params
    )
  user_db.put()
  task.new_user_notification(user_db)
  return user_db
Exemplo n.º 10
0
def create_user_db(auth_id, name, username, email='', verified=False, password='', **props):
    """Saves new user into datastore"""
    if password:
        password = util.password_hash(password)

    email = email.lower()
    user_db = model.User(
        name=name,
        email=email,
        username=username,
        auth_ids=[auth_id] if auth_id else [],
        verified=verified,
        token=util.uuid(),
        password_hash=password,
        **props
    )
    user_db.put()
    task.new_user_notification(user_db)
    return user_db
Exemplo n.º 11
0
def create_user_db(auth_id, name, username, email='', verified=False, **params):
  username = unidecode.unidecode(username.split('@')[0].lower()).strip()
  username = re.sub(r'[\W_]+', '.', username)
  new_username = username
  n = 1
  while not model.User.is_username_available(new_username):
    new_username = '******' % (username, n)
    n += 1

  user_db = model.User(
      name=name,
      email=email.lower(),
      username=new_username,
      auth_ids=[auth_id],
      verified=verified,
      token=util.uuid(),
      **params
    )
  user_db.put()
  task.new_user_notification(user_db)
  return user_db
Exemplo n.º 12
0
def create_user_db(auth_id, name, username, email='', verified=False, **props):
    # block signup based on configuration
  if not config.CONFIG_DB.signup_enabled:
      flask.flash("Signing up is disabled", category="info")
      return None
  email = email.lower() if email else ''
  if verified and email:
    user_dbs, cursors = model.User.get_dbs(email=email, verified=True, limit=2)
    if len(user_dbs) == 1:
      user_db = user_dbs[0]
      user_db.auth_ids.append(auth_id)
      user_db.put()
      task.new_user_notification(user_db)
      return user_db

  if isinstance(username, str):
    username = username.decode('utf-8')
  username = unidecode.unidecode(username.split('@')[0].lower()).strip()
  username = re.sub(r'[\W_]+', '.', username)
  new_username = username
  n = 1
  while not model.User.is_username_available(new_username):
    new_username = '******' % (username, n)
    n += 1

  user_db = model.User(
      name=name,
      email=email,
      username=new_username,
      auth_ids=[auth_id] if auth_id else [],
      verified=verified,
      token=util.uuid(),
      **props
    )
  user_db.put()
  task.new_user_notification(user_db)
  return user_db