Permalink
Browse files

Fixed a problem in iForgot.

  • Loading branch information...
1 parent cecc185 commit eaf83a15919047647628a8657677cb5f8786b699 @livid committed Aug 14, 2011
Showing with 42 additions and 5 deletions.
  1. +3 −1 config.py.example
  2. +5 −0 index.yaml
  3. +3 −3 main.py
  4. +31 −1 sso.py
View
@@ -20,4 +20,6 @@ fts_password = ''
recaptcha_public_key = 'your recaptcha_public_key'
recaptcha_private_key = 'your recaptcha_private_key'
-daydream_secret = ''
+daydream_secret = ''
+
+site_key = ''
View
@@ -104,6 +104,11 @@ indexes:
- name: minisite
- name: weight
+- kind: PasswordResetToken
+ properties:
+ - name: email
+ - name: timestamp
+
- kind: PlaceMessage
properties:
- name: place
View
@@ -613,7 +613,7 @@ def post(self):
q = db.GqlQuery("SELECT * FROM Member WHERE username_lower = :1 AND email = :2", username, email)
if q.count() == 1:
one = q[0]
- q2 = db.GqlQuery("SELECT * FROM PasswordResetToken WHERE timestamp > :1", (int(time.time()) - 86400))
+ q2 = db.GqlQuery("SELECT * FROM PasswordResetToken WHERE timestamp > :1 AND email = :2", (int(time.time()) - 86400), email)
if q2.count() > 2:
error_message = '你不能在 24 小时内进行超过 2 次的密码重设操作。'
template_values['errors'] = 1
@@ -638,8 +638,8 @@ def post(self):
mail_template_values['ip'] = self.request.remote_addr
path = os.path.join(os.path.dirname(__file__), 'tpl', 'mail', 'reset_password.txt')
output = template.render(path, mail_template_values)
- result = mail.send_mail(sender="V2EX <v2ex.livid@gmail.com>",
- to= one.email,
+ result = mail.send_mail(sender="v2ex.livid@me.com",
+ to=one.email,
subject="=?UTF-8?B?" + base64.b64encode((u"[" + site.title + u"] 重新设置密码").encode('utf-8')) + "?=",
body=output)
path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop', 'forgot_sent.html')
View
32 sso.py
@@ -9,6 +9,8 @@
import string
import random
+import config
+
from google.appengine.ext import webapp
from google.appengine.api import memcache
from google.appengine.ext import db
@@ -59,9 +61,37 @@ def get(self):
else:
self.response.out.write(failed)
+class SSOX0Handler(webapp.RequestHandler):
+ def get(self):
+ self.response.headers['Content-type'] = 'application/json'
+ x = self.request.get('x').strip()
+ n = self.request.get('n').strip().lower()
+ failed = '{"ok" : 0}'
+ if x == config.ssox:
+ q = db.GqlQuery("SELECT * FROM Member WHERE username_lower = :1", n)
+ if q.count() > 0:
+ member = q[0]
+ if member.avatar_mini_url:
+ site = GetSite()
+ if (member.avatar_mini_url[0:1] == '/'):
+ member.avatar_mini_url = 'http://' + site.domain + member.avatar_mini_url
+ member.avatar_normal_url = 'http://' + site.domain + member.avatar_normal_url
+ member.avatar_large_url = 'http://' + site.domain + member.avatar_large_url
+ else:
+ member.avatar_mini_url = 'http://' + site.domain + '/static/img/avatar_mini.png'
+ member.avatar_normal_url = 'http://' + site.domain + '/static/img/avatar_normal.png'
+ member.avatar_large_url = 'http://' + site.domain + '/static/img/avatar_large.png'
+ self.response.out.write('{"ok" : 1, "num" : ' + str(member.num) + ', "username" : "' + member.username + '", "username_lower" : "' + member.username_lower + '", "email" : "' + member.email + '", "password" : "' + member.password + '", "avatar_mini_url" : "' + member.avatar_mini_url + '", "avatar_normal_url" : "' + member.avatar_normal_url + '", "avatar_large_url" : "' + member.avatar_large_url + '", "created" : ' + str(time.mktime(member.created.timetuple())) + ', "last_modified" : ' + str(time.mktime(member.last_modified.timetuple())) + '}')
+ else:
+ self.response.out.write(failed)
+ else:
+ self.response.out.write(failed)
+
+
def main():
application = webapp.WSGIApplication([
- ('/sso/v0', SSOV0Handler)
+ ('/sso/v0', SSOV0Handler),
+ ('/sso/x0', SSOX0Handler)
],
debug=True)
util.run_wsgi_app(application)

0 comments on commit eaf83a1

Please sign in to comment.