Merge branch 'pre-auth' into basic_auth
authorRodney Ewing <ewing.rj@gmail.com>
Mon, 27 May 2013 16:04:53 +0000 (09:04 -0700)
committerRodney Ewing <ewing.rj@gmail.com>
Mon, 27 May 2013 16:04:53 +0000 (09:04 -0700)
Conflicts:
mediagoblin/auth/tools.py
mediagoblin/auth/views.py
mediagoblin/plugins/basic_auth/tools.py

1  2 
mediagoblin/auth/tools.py
mediagoblin/templates/mediagoblin/base.html

index 484c30302e4ea5a611890ee08177109b2e19df01,b6c7d5c510b454d1cb33fec877e8425310cbdb4b..94f2399340c5a633018eff1c89606b25a877d58b
@@@ -22,15 -24,12 +22,17 @@@ from mediagoblin import mg_global
  from mediagoblin.db.models import User
  from mediagoblin.tools.mail import (normalize_email, send_email,
                                      email_debug_message)
 -from mediagoblin.tools.template import render_template
  from mediagoblin.tools.translate import lazy_pass_to_ugettext as _
 +from mediagoblin.tools.template import render_template
 +from mediagoblin.tools.pluginapi import hook_handle
 +from mediagoblin import auth
 +
 +_log = logging.getLogger(__name__)
 +
 +_log = logging.getLogger(__name__)
  
+ _log = logging.getLogger(__name__)
  
  def normalize_user_or_email_field(allow_email=True, allow_user=True):
      """
@@@ -126,11 -96,41 +128,41 @@@ def send_verification_email(user, reque
          rendered_email)
  
  
+ EMAIL_FP_VERIFICATION_TEMPLATE = (
+     u"http://{host}{uri}?"
+     u"userid={userid}&token={fp_verification_key}")
+ def send_fp_verification_email(user, request):
+     """
+     Send the verification email to users to change their password.
+     Args:
+     - user: a user object
+     - request: the request
+     """
+     rendered_email = render_template(
+         request, 'mediagoblin/auth/fp_verification_email.txt',
+         {'username': user.username,
+          'verification_url': EMAIL_FP_VERIFICATION_TEMPLATE.format(
+                 host=request.host,
+                 uri=request.urlgen('mediagoblin.auth.verify_forgot_password'),
+                 userid=unicode(user.id),
+                 fp_verification_key=user.fp_verification_key)})
+     # TODO: There is no error handling in place
+     send_email(
+         mg_globals.app_config['email_sender_address'],
+         [user.email],
+         'GNU MediaGoblin - Change forgotten password!',
+         rendered_email)
  def basic_extra_validation(register_form, *args):
      users_with_username = User.query.filter_by(
 -        username=register_form.data['username']).count()
 +        username=register_form.username.data).count()
      users_with_email = User.query.filter_by(
 -        email=register_form.data['email']).count()
 +        email=register_form.email.data).count()
  
      extra_validation_passes = True
  
@@@ -166,43 -173,16 +198,13 @@@ def register_user(request, register_for
      return None
  
  
- EMAIL_FP_VERIFICATION_TEMPLATE = (
-     u"http://{host}{uri}?"
-     u"userid={userid}&token={fp_verification_key}")
- def send_fp_verification_email(user, request):
-     """
-     Send the verification email to users to change their password.
-     Args:
-     - user: a user object
-     - request: the request
-     """
-     rendered_email = render_template(
-         request, 'mediagoblin/auth/fp_verification_email.txt',
-         {'username': user.username,
-          'verification_url': EMAIL_FP_VERIFICATION_TEMPLATE.format(
-                 host=request.host,
-                 uri=request.urlgen('mediagoblin.auth.verify_forgot_password'),
-                 userid=unicode(user.id),
-                 fp_verification_key=user.fp_verification_key)})
-     # TODO: There is no error handling in place
-     send_email(
-         mg_globals.app_config['email_sender_address'],
-         [user.email],
-         'GNU MediaGoblin - Change forgotten password!',
-         rendered_email)
  def check_login_simple(username, password, username_might_be_email=False):
 -    search = (User.username == username)
 -    if username_might_be_email and ('@' in username):
 -        search = or_(search, User.email == username)
 -    user = User.query.filter(search).first()
 +    user = auth.get_user(username)
      if not user:
          _log.info("User %r not found", username)
 -        auth_lib.fake_login_attempt()
 +        auth.fake_login_attempt()
          return None
 -    if not auth_lib.bcrypt_check_password(password, user.pw_hash):
 +    if not auth.check_password(password, user.pw_hash):
          _log.warn("Wrong password for %r", username)
          return None
      _log.info("Logging %r in", username)