Tightend up the reddit user validation process to avoid issues.

This commit is contained in:
2010-04-20 22:23:17 +01:00
parent b8eaf202d7
commit f8280b8bd7
2 changed files with 34 additions and 28 deletions

View File

@@ -7,33 +7,33 @@ from reddit.models import RedditAccount
from reddit.api import Inbox from reddit.api import Inbox
class UpdateAPIs(): class UpdateAPIs():
""" """
Updates all Reddit API elements in the database Updates all Reddit API elements in the database
""" """
@property @property
def _logger(self): def _logger(self):
if not hasattr(self, '__logger'): if not hasattr(self, '__logger'):
self.__logger = logging.getLogger(__name__) self.__logger = logging.getLogger(__name__)
return self.__logger return self.__logger
last_update_delay = 604800 last_update_delay = 604800
def job(self): def job(self):
delta = datetime.timedelta(seconds=self.last_update_delay) delta = datetime.timedelta(seconds=self.last_update_delay)
print delta print delta
self._logger.debug("Updating accounts older than %s" % (datetime.datetime.now() - delta)) self._logger.debug("Updating accounts older than %s" % (datetime.datetime.now() - delta))
for acc in RedditAccount.objects.filter(last_update__lt=(datetime.datetime.now() - delta)): for acc in RedditAccount.objects.filter(last_update__lt=(datetime.datetime.now() - delta)):
self._logger.info("Updating %s" % acc.username) self._logger.info("Updating %s" % acc.username)
try: try:
acc.api_update() acc.api_update()
except RedditAccount.DoesNotExist: except RedditAccount.DoesNotExist:
acc.delete() acc.delete()
else: else:
acc.save() acc.save()
time.sleep(.5) time.sleep(.5)
class APIKeyParser: class APIKeyParser:
@@ -58,14 +58,21 @@ class ProcessValidations():
Grabs all Reddit Mail and processes validations Grabs all Reddit Mail and processes validations
""" """
@property
def _logger(self):
if not hasattr(self, '__logger'):
self.__logger = logging.getLogger(__name__)
return self.__logger
def job(self): def job(self):
inbox = Inbox(settings.REDDIT_USER, settings.REDDIT_PASSWD) inbox = Inbox(settings.REDDIT_USER, settings.REDDIT_PASSWD)
for msg in inbox: for msg in inbox:
if not msg.was_comment and msg.new: if not msg.was_comment:
try: try:
acc = RedditAccount.objects.get(username__iexact=msg.author) acc = RedditAccount.objects.get(username__iexact=msg.author)
if not acc.validated and msg.body == acc.user.username: if not acc.validated and msg.subject == "Validation: %s" % acc.user.username:
self._logger.info("Validated %s" % acc.user.username)
acc.validated = True acc.validated = True
acc.save() acc.save()
except RedditAccount.DoesNotExist: except RedditAccount.DoesNotExist:

View File

@@ -83,8 +83,7 @@ setup.</p>
<h2>Reddit Accounts</h2> <h2>Reddit Accounts</h2>
<p>This is a list of all your current linked Reddit accounts</p> <p>This is a list of all your current linked Reddit accounts</p>
{% if redditaccounts %} {% if redditaccounts %}
<p>To verify your Reddit account, login on Reddit then click <p>To validate your Reddit account, login on Reddit then click the link next to the account, fill in some text in the message and click send.</p>
<a href="http://www.reddit.com/message/compose/?to=DredditVerification&subject=Verification">this link</a> and put your Auth username in the message.</p>
<table> <table>
<thead> <thead>
<tr><th>Username</th><th>Created Date</th><th>Validated</th></tr> <tr><th>Username</th><th>Created Date</th><th>Validated</th></tr>
@@ -93,7 +92,7 @@ setup.</p>
{% for acc in redditaccounts %} {% for acc in redditaccounts %}
<tr><td>{{ acc.username }}</td> <tr><td>{{ acc.username }}</td>
<td>{{ acc.date_created }}</td> <td>{{ acc.date_created }}</td>
<td>{% if acc.validated %}Yes{% else %}No{% endif %}</td> <td>{% if acc.validated %}Yes{% else %}No (<a href="http://www.reddit.com/message/compose/?to=DredditVerification&subject=Validation%3a%20{{user.username}}">Validate</a>){% endif %}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>