def load_file(self, filepath, realpath):
        self.filepath = filepath
        self.filepath_hash = sha1(filepath.encode('utf-8')).hexdigest()
        self.realpath = realpath
        self.filename = os.path.basename(realpath)
        print_info(
            '【{filename}】正在校检文件中,耗时与文件大小有关'.format(filename=self.filename))
        self.hash = common.get_hash(self.realpath)
        self.filesize = os.path.getsize(self.realpath)

        self.part_info_list = []
        for i in range(0, math.ceil(self.filesize / self.chunk_size)):
            self.part_info_list.append({'part_number': i + 1})

        message = '''=================================================
        文件名:{filename}
        hash:{hash}
        文件大小:{filesize}
        文件路径:{filepath}
=================================================
'''.format(filename=self.filename,
           hash=self.hash,
           filesize=self.filesize,
           filepath=self.realpath)
        print_info(message)
Ejemplo n.º 2
0
  def post(self):
    self.login()
    if self.request.get('action') == 'Delete Account':
      if self.request.get('delete_account'):
        from utils import delete_user
        from urllib import urlencode
        delete_user(self.user_key.id_or_name())
        self.session.terminate()
        self.redirect('/?%s' % urlencode({'notify' : 'Account deleted'}))
        return
      else:
        self.action_feedback.append({'class' : 'error', 'message' : 'Please verify that you want to delete this account by ticking the checkbox'})
    elif self.request.get('action') == 'Unlink Account':
      from google.appengine.api.users import User
      accounts = self.request.get_all('linked_account')
      todel = []
      for acc in accounts:
        todel.append(db.Query(models.GoogleLogin, keys_only=True).filter('user ='******'google_user ='******'class' : 'notify', 'message' : 'Unlinked %s' % acc})
      db.delete(todel)
    elif self.request.get('action') == 'Change Password':
      from common import get_hash
      current_password_hash = get_hash(self.request.get('current_password', ''))
      new_password_hash = get_hash(self.request.get('new_password', ''))
      verify_new_password_hash = get_hash(self.request.get('verify_new_password', ''))

      login = db.Query(models.Login).filter('username ='******'password_hash =', current_password_hash).get()
      if login is None:
        self.action_feedback.append({'class' : 'error', 'message' : 'Wrong password'})
      elif new_password_hash != verify_new_password_hash:
        self.action_feedback.append({'class' : 'error', 'message' : 'Provided passwords don\' match'})
      else:
        login.password_hash = new_password_hash
        login.put()
        self.action_feedback.append({'class' : 'notify', 'message' : 'Password changed'})

    linked_accounts = db.Query(models.GoogleLogin).filter('user ='******'linked_accounts'] = [a.google_user.email() for a in linked_accounts]
    self.render_page('SettingsPage.html')
Ejemplo n.º 3
0
  def post(self):
    username = self.request.get("username", None)
    password_hash = common.get_hash(self.request.get("password", ""))

    m = db.Query(models.Login).filter('username ='******'password_hash =', password_hash).get()
    if m is None:
      self.login()
      self.template_values["login_username"] = username
      self.template_values["message"] = "Invalid username or password."
      self.render_page('LoginPage.html')
      return

    self.login_user(common.get_ref_key(m, 'user'), True if self.request.get('rememberme') else False)
    self.redirect("/")
    return
Ejemplo n.º 4
0
    def load_file(self, filepath, realpath):
        self.start_time = time.time()
        self.filepath = filepath
        self.realpath = realpath
        self.filename = os.path.basename(realpath)
        print_info('【{filename}】正在校检文件中,耗时与文件大小有关'.format(filename=self.filename))
        self.hash = get_hash(self.realpath)
        self.filesize = os.path.getsize(self.realpath)
        message = '''=================================================
        文件名:{filename}
        hash:{hash}
        文件大小:{filesize}
        文件路径:{filepath}
=================================================
'''.format(filename=self.filename, hash=self.hash, filesize=self.filesize, filepath=self.realpath)
        print_info(message)
Ejemplo n.º 5
0
    def post(self):
        username = self.request.get("username", None)
        password_hash = common.get_hash(self.request.get("password", ""))

        m = db.Query(models.Login).filter('username ='******'password_hash =', password_hash).get()
        if m is None:
            self.login()
            self.template_values["login_username"] = username
            self.template_values["message"] = "Invalid username or password."
            self.render_page('LoginPage.html')
            return

        self.login_user(common.get_ref_key(m, 'user'),
                        True if self.request.get('rememberme') else False)
        self.redirect("/")
        return
Ejemplo n.º 6
0
def register_tourist():
    req = request.get_json(True)
    
    seed_token = req.get('seed_token')
    if seed_token is None:
        current_app.logger.debug('invalid seed token')
        return jsonify(code=common.ERROR_INVALID_SEED_TOKEN, message='')
    
    new_token = common.get_hash(seed_token)
    
    is_new_user = False
    global_id = common.make_tourist_id(new_token)
    user = User.query.filter_by(global_id=global_id).first()
    if user is None:
        user = User(global_id=global_id,register_time=int(time.time()))
        db.session.add(user)
        db.session.commit()
        is_new_user = True

    uid = user.uid
    key_token = common.create_wrapper_token(third_login.CHANNEL_TOURIST, global_id, uid)

    current_app.logger.debug('new tourist <%s>, new user<%s>' % (global_id, str(is_new_user)))
    return jsonify(code=0, uid=uid, key_token=key_token)
Ejemplo n.º 7
0
  def post(self):
    username = self.request.get("username", None)
    password = self.request.get("password", None)
    verify_password = self.request.get("verify_password", None)
    link_type = self.request.get("link_type", None)
    email = self.request.get("email", None)

    google_user = None
    if link_type == "google":
      google_user = users.get_current_user()
      if google_user is None:
        self.redirect(users.create_login_url("/register?link_type=google"))
        return

    error_message = None

    m = db.Query(models.Login).filter('username ='******'rememberme') else False)

    self.redirect("/")
Ejemplo n.º 8
0
    def post(self):
        username = self.request.get("username", None)
        password = self.request.get("password", None)
        verify_password = self.request.get("verify_password", None)
        link_type = self.request.get("link_type", None)
        email = self.request.get("email", None)

        google_user = None
        if link_type == "google":
            google_user = users.get_current_user()
            if google_user is None:
                self.redirect(
                    users.create_login_url("/register?link_type=google"))
                return

        error_message = None

        m = db.Query(models.Login).filter('username ='******'rememberme') else False)

        self.redirect("/")
Ejemplo n.º 9
0
def get_login_hash():
    import random
    random.seed()
    return common.get_hash(str(random.random()))
Ejemplo n.º 10
0
def get_login_hash():
  import random
  random.seed()
  return common.get_hash(str(random.random()))