Commits

ronald martinez committed 5cf083a

hasslib passwd

Comments (0)

Files changed (2)

controllers/tv.py

+import hashlib
+import logging
+
 from tornado.web import asynchronous
 from tornado.auth import TwitterMixin
 
 from controllers import BaseHandler
 
 
+class Auth(BaseHandler):
+
+    def get(self):
+        nick = self.get_argument('nick', None)
+        password = self.get_argument('password', None)
+        send_data = {}
+
+        if not nick or not password:
+            send_data['status_code'] = 1
+            send_data['message'] = 'twitter auth failed'
+            send_data['token'] = ''
+            self.finish(send_data)
+
+        try:
+            password = hashlib.sha1(
+                password.encode('utf-8')).hexdigest()
+        except Exception as exc:
+            logging.error(exc)
+            password = ''
+
+        user = User.objects(
+            nick=nick,
+            password=password
+        ).first()
+
+        self.set_header("Access-Control-Allow-Origin", "*")
+
+        if not user:
+            send_data['status_code'] = 1
+            send_data['message'] = 'twitter auth failed'
+            send_data['token'] = ''
+            self.finish(send_data)
+        else:
+            send_data['status_code'] = 0
+            send_data['message'] = 'ok'
+            send_data['token'] = user.access_token
+            self.finish(send_data)
+
+
 class Favorite(BaseHandler, TwitterMixin):
 
     @asynchronous
         if not nick or not password:
             self.finish(dict(status_code=1))
 
+        try:
+            password = hashlib.sha1(
+                password.encode('utf-8')).hexdigest()
+        except Exception as exc:
+            logging.error(exc)
+            password = ''
+
         user = User.objects(
             nick=nick,
             password=password
         nick = self.get_argument('nick', None)
         password = self.get_argument('password', None)
 
+        try:
+            password = hashlib.sha1(
+                password.encode('utf-8')).hexdigest()
+        except Exception as exc:
+            logging.error(exc)
+            password = ''
+
         user = User.objects(
             nick=nick,
             password=password
             send_data['message'] = 'invalid parameters'
             self.finish(send_data)
 
+        try:
+            password = hashlib.sha1(
+                password.encode('utf-8')).hexdigest()
+        except Exception as exc:
+            logging.error(exc)
+            password = ''
+
         user = User.objects(nick=nick, password=password).first()
         self.set_header("Access-Control-Allow-Origin", "*")
 
         nick = self.get_argument('nick', None)
         password = self.get_argument('password', None)
 
+        try:
+            password = hashlib.sha1(
+                password.encode('utf-8')).hexdigest()
+        except Exception as exc:
+            logging.error(exc)
+            password = ''
+
         user = User.objects(
             nick=nick,
             password=password
             send_data['message'] = 'invalid parameters'
             self.finish(send_data)
 
+        try:
+            password = hashlib.sha1(
+                password.encode('utf-8')).hexdigest()
+        except Exception as exc:
+            logging.error(exc)
+            password = ''
+
         user = User.objects(nick=nick, password=password).first()
         self.set_header("Access-Control-Allow-Origin", "*")
 
         send_data['status_code'] = 0
         send_data['message'] = 'send post'
         self.finish(send_data)
-
-
-class Auth(BaseHandler):
-
-    def get(self):
-        nick = self.get_argument('nick', None)
-        password = self.get_argument('password', None)
-        send_data = {}
-
-        if not nick or not password:
-            send_data['status_code'] = 1
-            send_data['message'] = 'twitter auth failed'
-            send_data['token'] = ''
-            self.finish(send_data)
-
-        user = User.objects(
-            nick=nick,
-            password=password
-        ).first()
-
-        self.set_header("Access-Control-Allow-Origin", "*")
-
-        if not user:
-            send_data['status_code'] = 1
-            send_data['message'] = 'twitter auth failed'
-            send_data['token'] = ''
-            self.finish(send_data)
-        else:
-            send_data['status_code'] = 0
-            send_data['message'] = 'ok'
-            send_data['token'] = user.access_token
-            self.finish(send_data)
 
 routers = (
     #tv
+    url('/auth', Auth),
     url('/twit', Twit),
     url('/retwit', Retwit),
     url('/direct_message', DirectMesaage),
-    url('/auth', Auth),
     url('/timeline', Timeline),
     url('/favorite', Favorite),