fix auth error and simplify url and email checks
authorBoris Bobrov <breton@cynicmansion.ru>
Wed, 11 Jul 2018 15:30:09 +0000 (17:30 +0200)
committerBoris Bobrov <breton@cynicmansion.ru>
Wed, 11 Jul 2018 15:30:09 +0000 (17:30 +0200)
mediagoblin/auth/views.py
mediagoblin/tools/validator.py

index fb8e72652786f58f168a8f267bc50747ae350383..593d588d6e4d573e139cf2fe9a6d8d79baeddfa8 100644 (file)
@@ -109,7 +109,8 @@ def login(request):
                     return redirect(request, "index")
 
             login_failed = True
-            remote_addr = request.access_route[-1] or request.remote_addr
+            remote_addr = (request.access_route and request.access_route[-1]
+                           or request.remote_addr)
             _log.warn("Failed login attempt from %r", remote_addr)
 
     return render_to_response(
index 03598f9c4b60635379030ccad071bba8e473547d..e8031a440a822286d809069bd3d4366953cbe770 100644 (file)
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-from wtforms.validators import Email, URL
+import six
 
 def validate_email(email):
-    """ 
-        Validates an email 
-    
-        Returns True if valid and False if invalid
     """
+        Validates an email
 
-    email_re = Email().regex
-    result = email_re.match(email)
-    if result is None:
-        return False
-    else:
-        return result.string
+        Returns True if valid and False if invalid
+    """
+    return '@' in email
 
 def validate_url(url):
     """
@@ -36,11 +30,9 @@ def validate_url(url):
 
         Returns True if valid and False if invalid
     """
-
-    url_re = URL().regex
-    result = url_re.match(url)
-    if result is None:
+    try:
+        six.moves.urlparse(url)
+        return True
+    except Except as e:
         return False
-    else:
-        return result.string