Пример #1
0
Файл: user.py Проект: kberg/dviz
  def post(self):
    secret = self.request.get('secret')
    nickname = self.request.get('nickname')
    user = users.get_current_user()
    uid = user.user_id()
    try:
      data.get_user_by_id(uid)
      data.update_user(uid, secret, nickname)
    except data.UserException:
	    data.add_user(uid, user.email(), secret, nickname)
    self.redirect('/list')
Пример #2
0
Файл: user.py Проект: kberg/dviz
  def get(self):
    template_values = { }
    try:
      current_user = users.get_current_user()
      user = data.get_user_by_id(current_user.user_id())
      template_values['nickname'] = user.nickname
      template_values['secret'] = user.secret

    except Exception as e:
      sys.stderr.write(e)
    
    self.render('user.html', template_values)
Пример #3
0
Файл: base.py Проект: kberg/dviz
  def render(self, name, template_values):
    path = os.path.join(os.path.dirname(__file__), '../templates/%s' % name)
    navbar = { }
    user = { }
    current_user = users.get_current_user()

    # load from the users table to see if the user is registered, and to
    # get user's nickname.
    nickname = ''
    registered = False
    if current_user:
      try:
        nickname = data.get_user_by_id(current_user.user_id()).nickname
        registered = True
      except Exception as e: # Come up with better exception.
        sys.stderr.write(e)
        pass

    if current_user:
      navbar = {
        'email' : current_user.email(),
        'nickname' : nickname
      }
      user = {
        'uid' : current_user.user_id(),
        'email' : current_user.email(),
        'nickname' : nickname,
        'registered' : registered
      }
    else:
      navbar = {
        'email' : '',
        'nickname' : ''
      }
      user = {
        'uid' : '',
        'email' : '',
        'nickname' : '',
        'registered' : False
      }

    template_values['user'] = user

    if current_user and current_user.email():
      navbar['logout_url'] = users.create_logout_url('/')
    else:
      navbar['login_url'] = users.create_login_url('/')

    template_values['navbar'] = navbar
    self.response.out.write(template.render(path, template_values))
Пример #4
0
def verify_password(_login, password):
    """
       User verification
       :param _login: (str)
       :param password: (str)
       :return bool:
    """
    user_id = User.verify_auth_token(_login)
    if user_id:
        user = get_user_by_id(user_id)
        if not user.verify_password(password):
            return False
    else:
        return False
    g.user = user
    return True