Ejemplo n.º 1
0
def user_forgot(token=None):
  if not config.CONFIG_DB.has_email_authentication:
    flask.abort(418)

  form = auth.form_with_recaptcha(UserForgotForm(obj=auth.current_user_db()))
  if form.validate_on_submit():
    cache.bump_auth_attempt()
    email = form.email.data
    user_dbs, cursors = util.get_dbs(
        model.User.query(), email=email, active=True, limit=2,
      )
    count = len(user_dbs)
    if count == 1:
      task.reset_password_notification(user_dbs[0])
      return flask.redirect(flask.url_for('welcome'))
    elif count == 0:
      form.email.errors.append('This email was not found')
    elif count == 2:
      task.email_conflict_notification(email)
      form.email.errors.append(
          '''We are sorry but it looks like there is a conflict with your
          account. Our support team is already informed and we will get back to
          you as soon as possible.'''
        )

  if form.errors:
    cache.bump_auth_attempt()

  return flask.render_template(
      'user/user_forgot.html',
      title=_('Forgot Password?'),
      html_class='user-forgot',
      form=form,
    )
Ejemplo n.º 2
0
 def get_dbs(cls, query=None, ancestor=None, order=None, limit=None, cursor=None, **kwargs):
   return util.get_dbs(
       query or cls.query(ancestor=ancestor),
       limit=limit or util.param('limit', int),
       cursor=cursor or util.param('cursor'),
       order=order or util.param('order') or '-created',
       **kwargs
     )
Ejemplo n.º 3
0
 def get_dbs(cls, query=None, ancestor=None, order=None, limit=None, cursor=None, **kwargs):
   return util.get_dbs(
       query or cls.query(ancestor=ancestor),
       limit=limit or util.param('limit', int),
       cursor=cursor or util.param('cursor'),
       order=order or util.param('order'),
       **kwargs
     )
Ejemplo n.º 4
0
def admin_pay_upgrade_service():
  pay_dbs, pay_cursor = util.get_dbs(
      model.Pay.query(),
      limit=util.param('limit', int),
      cursor=util.param('cursor'),
      order=util.param('order'),
    )
  ndb.put_multi(pay_dbs)
  return util.jsonify_model_dbs(pay_dbs, pay_cursor)
Ejemplo n.º 5
0
def admin_tournament_update():
  tournament_dbs, tournament_cursor = util.get_dbs(
      model.Tournament.query(),
      limit=util.param('limit', int) or config.DEFAULT_DB_LIMIT,
      order=util.param('order'),
      cursor=util.param('cursor'),
    )

  ndb.put_multi(tournament_dbs)
  return util.jsonify_model_dbs(tournament_dbs, tournament_cursor)
Ejemplo n.º 6
0
def move_resources_task(user_key, deprecated_key, next_cursor=None):
  resource_dbs, next_cursor = util.get_dbs(
      model.Resource.query(),
      user_key=deprecated_key,
      cursor=next_cursor,
    )
  for resource_db in resource_dbs:
    resource_db.user_key = user_key
  ndb.put_multi(resource_dbs)
  if next_cursor:
    deferred.defer(move_resources_task, user_key, deprecated_key, next_cursor)
Ejemplo n.º 7
0
def move_resources_task(user_key, deprecated_key, next_cursor=None):
  resource_dbs, next_cursor = util.get_dbs(
      model.Resource.query(),
      user_key=deprecated_key,
      cursor=next_cursor,
    )
  for resource_db in resource_dbs:
    resource_db.user_key = user_key
  ndb.put_multi(resource_dbs)
  if next_cursor:
    deferred.defer(move_resources_task, user_key, deprecated_key, next_cursor)
Ejemplo n.º 8
0
def move_events_task(user_key, deprecated_key, next_cursor=None):
  event_dbs, next_cursor = util.get_dbs(
      model.Event.query(),
      user_key=deprecated_key,
      cursor=next_cursor,
    )
  for event_db in event_dbs:
    event_db.user_key = user_key
  ndb.put_multi(event_dbs)
  if next_cursor:
    deferred.defer(move_events_task, user_key, deprecated_key, next_cursor)
Ejemplo n.º 9
0
 def get_dbs(cls,
             query=None,
             ancestor=None,
             order=None,
             limit=None,
             cursor=None,
             **kwargs):
     return util.get_dbs(query or cls.query(ancestor=ancestor),
                         limit=limit,
                         cursor=cursor,
                         order=order,
                         **kwargs)
Ejemplo n.º 10
0
def account_cleanup(stars, cursor=None):
    account_qry = model.Account.query().filter(model.Account.stars < stars)
    account_keys, account_cursors = util.get_dbs(
        account_qry,
        order='stars',
        keys_only=True,
        cursor=cursor,
    )

    ndb.delete_multi(account_keys)
    if account_cursors['next']:
        deferred.defer(account_cleanup, days, account_cursors['next'])
Ejemplo n.º 11
0
def delete_user_task(user_key, next_cursor=None):
  event_dbs, next_cursor = util.get_dbs(
      model.Event.query(),
      user_key=user_key,
      cursor=next_cursor,
    )
  if event_dbs:
    ndb.delete_multi([event_db.key for event_db in event_dbs])

  if next_cursor:
    deferred.defer(delete_user_task, user_key, next_cursor)
  else:
    user_key.delete()
Ejemplo n.º 12
0
def repo_cleanup(days, cursor=None):
  before_date = datetime.utcnow() - timedelta(days=days)
  repo_qry = model.Repo.query().filter(model.Repo.modified < before_date)
  repo_keys, repo_cursors = util.get_dbs(
      repo_qry,
      order='modified',
      keys_only=True,
      cursor=cursor,
    )

  ndb.delete_multi(repo_keys)
  if repo_cursors['next']:
    deferred.defer(repo_cleanup, days, repo_cursors['next'])
Ejemplo n.º 13
0
 def get_dbs(cls, query=None, ancestor=None, order=None, limit=None, cursor=None, **kwargs):
   args = parser.parse({
     'cursor': wf.Str(missing=None),
     'limit': wf.Int(missing=None, validate=validate.Range(min=-1)),
     'order': wf.Str(missing=None),
   })
   return util.get_dbs(
     query or cls.query(ancestor=ancestor),
     limit=limit or args['limit'],
     cursor=cursor or args['cursor'],
     order=order or args['order'],
     **kwargs
   )
Ejemplo n.º 14
0
def repo_cleanup(days, cursor=None):
    before_date = datetime.utcnow() - timedelta(days=days)
    repo_qry = model.Repo.query().filter(model.Repo.modified < before_date)
    repo_keys, repo_cursors = util.get_dbs(
        repo_qry,
        order='modified',
        keys_only=True,
        cursor=cursor,
    )

    ndb.delete_multi(repo_keys)
    if repo_cursors['next']:
        deferred.defer(repo_cleanup, days, repo_cursors['next'])
Ejemplo n.º 15
0
def update_user_tutor():
    event_dbs, event_cursor = util.get_dbs(
        model.Event.query(),
        limit=util.param("limit", int) or config.MAX_DB_LIMIT,
        order=util.param("order"),
        cursor=util.param("cursor"),
    )

    for event_db in event_dbs:
        event_db.accuracy = "day"

    ndb.put_multi(event_dbs)
    return util.jsonify_model_dbs(event_dbs, event_cursor)
Ejemplo n.º 16
0
 def get_dbs(cls, query=None, ancestor=None, order=None, limit=None, cursor=None, **kwargs):
     args = parser.parse({
         'cursor': wf.Str(missing=None),
         'limit': wf.Int(missing=None, validate=validate.Range(min=-1)),
         'order': wf.Str(missing=None),
     })
     return util.get_dbs(
         query or cls.query(ancestor=ancestor),
         limit=limit or args['limit'],
         cursor=cursor or args['cursor'],
         order=order or args['order'],
         **kwargs
     )
Ejemplo n.º 17
0
def account_rank(organization):
    account_qry = model.Account.query().filter(
        model.Account.organization == organization)
    account_dbs, account_cursors = util.get_dbs(
        account_qry,
        order='-stars',
        limit=-1,
    )
    updated_dbs = []
    for index, account_db in enumerate(account_dbs, start=1):
        if index < config.MAX_DB_LIMIT:
            account_db.rank = index
        else:
            account_db.rank = 0
        updated_dbs.append(account_db)

    ndb.put_multi(updated_dbs)
Ejemplo n.º 18
0
def admin_event_list():
  event_dbs, next_cursor = util.get_dbs(
      model.Event.query(),
      limit=util.param('limit', int),
      cursor=util.param('cursor'),
      order=util.param('order') or 'user_key,-timestamp,accuracy,-created',
    )

  if flask.request.path.startswith('/_s/'):
    return util.jsonify_model_dbs(event_dbs, next_cursor)

  return flask.render_template(
      'admin/event_list.html',
      html_class='admin-event-list',
      title='Event List',
      event_dbs=event_dbs,
      next_url=util.generate_next_url(next_cursor),
    )
Ejemplo n.º 19
0
def admin_event_list():
    event_dbs, next_cursor = util.get_dbs(
        model.Event.query(),
        limit=util.param("limit", int),
        cursor=util.param("cursor"),
        order=util.param("order") or "user_key,-timestamp,accuracy,-created",
    )

    if flask.request.path.startswith("/_s/"):
        return util.jsonify_model_dbs(event_dbs, next_cursor)

    return flask.render_template(
        "admin/event_list.html",
        html_class="admin-event-list",
        title="Event List",
        event_dbs=event_dbs,
        next_url=util.generate_next_url(next_cursor),
    )
Ejemplo n.º 20
0
def admin_user_update():
  user_dbs, user_cursor = util.get_dbs(
      model.User.query(),
      limit=util.param('limit', int) or config.DEFAULT_DB_LIMIT,
      order=util.param('order'),
      cursor=util.param('cursor'),
    )

  updated_dbs = []
  for user_db in user_dbs:
    if not user_db.birthdate:
      user_db.birthdate = None
      updated_dbs.append(user_db)

  if updated_dbs:
    ndb.put_multi(updated_dbs)

  return util.jsonify_model_dbs(updated_dbs, user_cursor)
Ejemplo n.º 21
0
def delete_user_task(user_key, next_cursor=None):
  resource_dbs, next_cursor = util.get_dbs(
      model.Resource.query(),
      user_key=user_key,
      cursor=next_cursor,
    )
  if resource_dbs:
    for resource_db in resource_dbs:
      try:
        blobstore.BlobInfo.get(resource_db.blob_key).delete()
      except AttributeError:
        logging.error('Blob %s not found during delete (resource_key: %s)' % (
            resource_db.blob_key, resource_db.key().urlsafe(),
          ))

    ndb.delete_multi([resource_db.key for resource_db in resource_dbs])

  if next_cursor:
    deferred.defer(delete_user_task, user_key, next_cursor)
  else:
    user_key.delete()
Ejemplo n.º 22
0
def delete_user_task(user_key, next_cursor=None):
    resource_dbs, next_cursor = util.get_dbs(
        model.Resource.query(),
        user_key=user_key,
        cursor=next_cursor,
    )
    if resource_dbs:
        for resource_db in resource_dbs:
            try:
                blobstore.BlobInfo.get(resource_db.blob_key).delete()
            except AttributeError:
                logging.error(
                    'Blob %s not found during delete (resource_key: %s)' % (
                        resource_db.blob_key,
                        resource_db.key().urlsafe(),
                    ))

        ndb.delete_multi([resource_db.key for resource_db in resource_dbs])

    if next_cursor:
        deferred.defer(delete_user_task, user_key, next_cursor)
    else:
        user_key.delete()
Ejemplo n.º 23
0
def user_forgot(token=None):
    if not config.CONFIG_DB.has_email_authentication:
        flask.abort(418)

    form = auth.form_with_recaptcha(UserForgotForm(obj=auth.current_user_db()))
    if form.validate_on_submit():
        cache.bump_auth_attempt()
        email = form.email.data
        user_dbs, _ = util.get_dbs(
            model.User.query(),
            email=email,
            active=True,
            limit=2,
        )
        count = len(user_dbs)
        if count == 1:
            task.reset_password_notification(user_dbs[0])
            return flask.redirect(flask.url_for('welcome'))
        elif count == 0:
            form.email.errors.append(u'Имэйл хаяг олдсонгүй')
        elif count == 2:
            task.email_conflict_notification(email)
            form.email.errors.append(
                u'''Уучлаарай таны дансанд давхардал үүссэн байна. Бид нэн даруй хариуцсан
                ажилтанд мэдэгдсэн болно. Тусламжийн ажилтан тантай аль болох хурдан
                холбогдох болно.''')

    if form.errors:
        cache.bump_auth_attempt()

    return flask.render_template(
        'user/user_forgot.html',
        title=u'Нууц үгээ мартсан уу?',
        html_class='user-forgot',
        form=form,
    )
Ejemplo n.º 24
0
 def is_username_available(cls, username, self_db=None):
   if self_db is None:
     return cls.get_by('username', username) is None
   user_dbs, _ = util.get_dbs(cls.query(), username=username, limit=2)
   c = len(user_dbs)
   return not (c == 2 or c == 1 and self_db.key != user_dbs[0].key)
Ejemplo n.º 25
0
 def is_username_available(cls, username, self_db=None):
   if self_db is None:
     return cls.get_by('username', username) is None
   user_dbs, _ = util.get_dbs(cls.query(), username=username, limit=2)
   c = len(user_dbs)
   return not (c == 2 or c == 1 and self_db.key != user_dbs[0].key)