prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  'AnonymousUser' object has no attribute 'has_usable_password'
  Visiting http://localhost:8000/admin/account/ as not logged in user gives the AttributeError above...
  
  Traceback;
  
  ``` Environment:
  
  
  Request Method: GET
  Request URL: http://localhost:8000/admin/account/
  
  Django Version: 1.6.2
  Python Version: 2.7.6
  Installed Applications:
  ('django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
   'south',
   'compressor',
   'taggit',
   'modelcluster',
   'django.contrib.admin',
   'wagtail.wagtailcore',
   'wagtail.wagtailadmin',
   'wagtail.wagtaildocs',
   'wagtail.wagtailsnippets',
   'wagtail.wagtailusers',
   'wagtail.wagtailimages',
   'wagtail.wagtailembeds',
   'wagtail.wagtailsearch',
   'wagtail.wagtailredirects')
  Installed Middleware:
  ('django.contrib.sessions.middleware.SessionMiddleware',
   'django.middleware.common.CommonMiddleware',
   'django.middleware.csrf.CsrfViewMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   'django.contrib.messages.middleware.MessageMiddleware',
   'django.middleware.clickjacking.XFrameOptionsMiddleware',
   'wagtail.wagtailcore.middleware.SiteMiddleware',
   'wagtail.wagtailredirects.middleware.RedirectMiddleware')
  
  
  Traceback:
  File "C:\Users\drager\developing\django-env\lib\site-packages\django\core\handlers\base.py" in get_response
    114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "c:\users\drager\developing\django-env\src\wagtail\wagtail\wagtailadmin\views\account.py" in account
    9.         'show_change_password': getattr(settings, 'WAGTAIL_PASSWORD_MANAGEMENT_ENABLED', True) and request.user.has_usable_password(),
  File "C:\Users\drager\developing\django-env\lib\site-packages\django\utils\functional.py" in inner
    214.         return func(self._wrapped, *args)
  
  Exception Type: AttributeError at /admin/account/
  Exception Value: 'AnonymousUser' object has no attribute 'has_usable_password'
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `wagtail/wagtailadmin/views/account.py`
  Content:
  ```
  1 from django.conf import settings
  2 from django.shortcuts import render, redirect
  3 from django.contrib import messages
  4 from django.contrib.auth.forms import SetPasswordForm
  5 from django.utils.translation import ugettext as _ 
  6 
  7 def account(request):
  8     return render(request, 'wagtailadmin/account/account.html', {
  9         'show_change_password': getattr(settings, 'WAGTAIL_PASSWORD_MANAGEMENT_ENABLED', True) and request.user.has_usable_password(),
  10     })
  11 
  12 
  13 def change_password(request):
  14     can_change_password = request.user.has_usable_password()
  15 
  16     if can_change_password:
  17         if request.POST:
  18             form = SetPasswordForm(request.user, request.POST)
  19 
  20             if form.is_valid():
  21                 form.save()
  22 
  23                 messages.success(request, _("Your password has been changed successfully!"))
  24                 return redirect('wagtailadmin_account')
  25         else:
  26             form = SetPasswordForm(request.user)
  27     else:
  28         form = None
  29 
  30     return render(request, 'wagtailadmin/account/change_password.html', {
  31         'form': form,
  32         'can_change_password': can_change_password,
  33     })
  34
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/wagtail/wagtailadmin/views/account.py b/wagtail/wagtailadmin/views/account.py
  --- a/wagtail/wagtailadmin/views/account.py
  +++ b/wagtail/wagtailadmin/views/account.py
  @@ -2,14 +2,17 @@
   from django.shortcuts import render, redirect
   from django.contrib import messages
   from django.contrib.auth.forms import SetPasswordForm
  +from django.contrib.auth.decorators import permission_required
   from django.utils.translation import ugettext as _ 
   
  +@permission_required('wagtailadmin.access_admin')
   def account(request):
       return render(request, 'wagtailadmin/account/account.html', {
           'show_change_password': getattr(settings, 'WAGTAIL_PASSWORD_MANAGEMENT_ENABLED', True) and request.user.has_usable_password(),
       })
   
   
  +@permission_required('wagtailadmin.access_admin')
   def change_password(request):
       can_change_password = request.user.has_usable_password()
  
verification_info: {"golden_diff": "diff --git a/wagtail/wagtailadmin/views/account.py b/wagtail/wagtailadmin/views/account.py\n--- a/wagtail/wagtailadmin/views/account.py\n+++ b/wagtail/wagtailadmin/views/account.py\n@@ -2,14 +2,17 @@\n from django.shortcuts import render, redirect\n from django.contrib import messages\n from django.contrib.auth.forms import SetPasswordForm\n+from django.contrib.auth.decorators import permission_required\n from django.utils.translation import ugettext as _ \n \n+@permission_required('wagtailadmin.access_admin')\n def account(request):\n     return render(request, 'wagtailadmin/account/account.html', {\n         'show_change_password': getattr(settings, 'WAGTAIL_PASSWORD_MANAGEMENT_ENABLED', True) and request.user.has_usable_password(),\n     })\n \n \n+@permission_required('wagtailadmin.access_admin')\n def change_password(request):\n     can_change_password = request.user.has_usable_password()\n", "issue": "'AnonymousUser' object has no attribute 'has_usable_password'\nVisiting http://localhost:8000/admin/account/ as not logged in user gives the AttributeError above...\n\nTraceback;\n\n``` Environment:\n\n\nRequest Method: GET\nRequest URL: http://localhost:8000/admin/account/\n\nDjango Version: 1.6.2\nPython Version: 2.7.6\nInstalled Applications:\n('django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n 'south',\n 'compressor',\n 'taggit',\n 'modelcluster',\n 'django.contrib.admin',\n 'wagtail.wagtailcore',\n 'wagtail.wagtailadmin',\n 'wagtail.wagtaildocs',\n 'wagtail.wagtailsnippets',\n 'wagtail.wagtailusers',\n 'wagtail.wagtailimages',\n 'wagtail.wagtailembeds',\n 'wagtail.wagtailsearch',\n 'wagtail.wagtailredirects')\nInstalled Middleware:\n('django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n 'wagtail.wagtailcore.middleware.SiteMiddleware',\n 'wagtail.wagtailredirects.middleware.RedirectMiddleware')\n\n\nTraceback:\nFile \"C:\\Users\\drager\\developing\\django-env\\lib\\site-packages\\django\\core\\handlers\\base.py\" in get_response\n  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)\nFile \"c:\\users\\drager\\developing\\django-env\\src\\wagtail\\wagtail\\wagtailadmin\\views\\account.py\" in account\n  9.         'show_change_password': getattr(settings, 'WAGTAIL_PASSWORD_MANAGEMENT_ENABLED', True) and request.user.has_usable_password(),\nFile \"C:\\Users\\drager\\developing\\django-env\\lib\\site-packages\\django\\utils\\functional.py\" in inner\n  214.         return func(self._wrapped, *args)\n\nException Type: AttributeError at /admin/account/\nException Value: 'AnonymousUser' object has no attribute 'has_usable_password'\n```\n\n", "before_files": [{"content": "from django.conf import settings\nfrom django.shortcuts import render, redirect\nfrom django.contrib import messages\nfrom django.contrib.auth.forms import SetPasswordForm\nfrom django.utils.translation import ugettext as _ \n\ndef account(request):\n    return render(request, 'wagtailadmin/account/account.html', {\n        'show_change_password': getattr(settings, 'WAGTAIL_PASSWORD_MANAGEMENT_ENABLED', True) and request.user.has_usable_password(),\n    })\n\n\ndef change_password(request):\n    can_change_password = request.user.has_usable_password()\n\n    if can_change_password:\n        if request.POST:\n            form = SetPasswordForm(request.user, request.POST)\n\n            if form.is_valid():\n                form.save()\n\n                messages.success(request, _(\"Your password has been changed successfully!\"))\n                return redirect('wagtailadmin_account')\n        else:\n            form = SetPasswordForm(request.user)\n    else:\n        form = None\n\n    return render(request, 'wagtailadmin/account/change_password.html', {\n        'form': form,\n        'can_change_password': can_change_password,\n    })\n", "path": "wagtail/wagtailadmin/views/account.py"}], "after_files": [{"content": "from django.conf import settings\nfrom django.shortcuts import render, redirect\nfrom django.contrib import messages\nfrom django.contrib.auth.forms import SetPasswordForm\nfrom django.contrib.auth.decorators import permission_required\nfrom django.utils.translation import ugettext as _ \n\n@permission_required('wagtailadmin.access_admin')\ndef account(request):\n    return render(request, 'wagtailadmin/account/account.html', {\n        'show_change_password': getattr(settings, 'WAGTAIL_PASSWORD_MANAGEMENT_ENABLED', True) and request.user.has_usable_password(),\n    })\n\n\n@permission_required('wagtailadmin.access_admin')\ndef change_password(request):\n    can_change_password = request.user.has_usable_password()\n\n    if can_change_password:\n        if request.POST:\n            form = SetPasswordForm(request.user, request.POST)\n\n            if form.is_valid():\n                form.save()\n\n                messages.success(request, _(\"Your password has been changed successfully!\"))\n                return redirect('wagtailadmin_account')\n        else:\n            form = SetPasswordForm(request.user)\n    else:\n        form = None\n\n    return render(request, 'wagtailadmin/account/change_password.html', {\n        'form': form,\n        'can_change_password': can_change_password,\n    })\n", "path": "wagtail/wagtailadmin/views/account.py"}]}