mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Tightend up the reddit user validation process to avoid issues.
This commit is contained in:
@@ -7,33 +7,33 @@ from reddit.models import RedditAccount
|
||||
from reddit.api import Inbox
|
||||
|
||||
class UpdateAPIs():
|
||||
"""
|
||||
Updates all Reddit API elements in the database
|
||||
"""
|
||||
@property
|
||||
def _logger(self):
|
||||
if not hasattr(self, '__logger'):
|
||||
self.__logger = logging.getLogger(__name__)
|
||||
return self.__logger
|
||||
"""
|
||||
Updates all Reddit API elements in the database
|
||||
"""
|
||||
@property
|
||||
def _logger(self):
|
||||
if not hasattr(self, '__logger'):
|
||||
self.__logger = logging.getLogger(__name__)
|
||||
return self.__logger
|
||||
|
||||
last_update_delay = 604800
|
||||
last_update_delay = 604800
|
||||
|
||||
def job(self):
|
||||
delta = datetime.timedelta(seconds=self.last_update_delay)
|
||||
def job(self):
|
||||
delta = datetime.timedelta(seconds=self.last_update_delay)
|
||||
|
||||
print delta
|
||||
self._logger.debug("Updating accounts older than %s" % (datetime.datetime.now() - delta))
|
||||
print 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)):
|
||||
self._logger.info("Updating %s" % acc.username)
|
||||
for acc in RedditAccount.objects.filter(last_update__lt=(datetime.datetime.now() - delta)):
|
||||
self._logger.info("Updating %s" % acc.username)
|
||||
|
||||
try:
|
||||
acc.api_update()
|
||||
except RedditAccount.DoesNotExist:
|
||||
acc.delete()
|
||||
else:
|
||||
acc.save()
|
||||
time.sleep(.5)
|
||||
try:
|
||||
acc.api_update()
|
||||
except RedditAccount.DoesNotExist:
|
||||
acc.delete()
|
||||
else:
|
||||
acc.save()
|
||||
time.sleep(.5)
|
||||
|
||||
|
||||
class APIKeyParser:
|
||||
@@ -58,14 +58,21 @@ class ProcessValidations():
|
||||
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):
|
||||
inbox = Inbox(settings.REDDIT_USER, settings.REDDIT_PASSWD)
|
||||
|
||||
for msg in inbox:
|
||||
if not msg.was_comment and msg.new:
|
||||
if not msg.was_comment:
|
||||
try:
|
||||
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.save()
|
||||
except RedditAccount.DoesNotExist:
|
||||
|
||||
@@ -83,8 +83,7 @@ setup.</p>
|
||||
<h2>Reddit Accounts</h2>
|
||||
<p>This is a list of all your current linked Reddit accounts</p>
|
||||
{% if redditaccounts %}
|
||||
<p>To verify your Reddit account, login on Reddit then click
|
||||
<a href="http://www.reddit.com/message/compose/?to=DredditVerification&subject=Verification">this link</a> and put your Auth username in the message.</p>
|
||||
<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>
|
||||
<table>
|
||||
<thead>
|
||||
<tr><th>Username</th><th>Created Date</th><th>Validated</th></tr>
|
||||
@@ -93,7 +92,7 @@ setup.</p>
|
||||
{% for acc in redditaccounts %}
|
||||
<tr><td>{{ acc.username }}</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>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user