Google App Engine で使用している User モデルのパスワード リセット トークンを生成したいと考えています。どうやら GAE で Django を簡単に使用することは許可されていないため、トークンを生成するための Django メソッドの生のコードは次のとおりです。
def _make_token_with_timestamp(self, user, timestamp):
# timestamp is number of days since 2001-1-1. Converted to
# base 36, this gives us a 3 digit string until about 2121
ts_b36 = int_to_base36(timestamp)
# By hashing on the internal state of the user and using state
# that is sure to change (the password salt will change as soon as
# the password is set, at least for current Django auth, and
# last_login will also change), we produce a hash that will be
# invalid as soon as it is used.
# We limit the hash to 20 chars to keep URL short
key_salt = "django.contrib.auth.tokens.PasswordResetTokenGenerator"
# Ensure results are consistent across DB backends
login_timestamp = user.last_login.replace(microsecond=0, tzinfo=None)
value = (unicode(user.id) + user.password +
unicode(login_timestamp) + unicode(timestamp))
hash = salted_hmac(key_salt, value).hexdigest()[::2]
return "%s-%s" % (ts_b36, hash)
Python は私の専門言語ではないので、上記のようなカスタム メソッドを作成するのに助けが必要です。いくつか質問があります。まず、タイムスタンプの目的は何ですか? また、Django には独自の User システムがありますが、私は独自の単純なカスタム User モデルを使用しています。上記のコードのどの部分を保持する必要がありますか? また、どの部分を削除できますか?