def recover(request, uidb64=None, token=None):
 UserModel = get_user_model()
 try:
  uid = force_text(urlsafe_base64_decode(uidb64))
  user = UserModel._default_manager.get(pk=uid)
 except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist):
  user = None
 if (user and default_token_generator.check_token(user, token)):
  temp_pwd = uuid.uuid4().hex
  user.set_password(temp_pwd)
  user.save()
  user = authenticate(username=user.username, password=temp_pwd)
  user.set_unusable_password()
  user.save()
  login(request, user)
  return redirect('users.recover_done')
 return render(request, 'users/recover_failed.html')

def recover ( request , uidb64 = None , token = None ) : UserModel = get_user_model ( ) try : uid = force_text ( urlsafe_base64_decode ( uidb64 ) ) user = UserModel . _default_manager . get ( pk = uid ) except ( TypeError , ValueError , OverflowError , UserModel . DoesNotExist ) : user = None if ( user and default_token_generator . check_token ( user , token ) ) : temp_pwd = uuid . uuid4 ( ) . hex user . set_password ( temp_pwd ) user . save ( ) user = authenticate ( username = user . username , password = temp_pwd ) user . set_unusable_password ( ) user . save ( ) login ( request , user ) return redirect ( 'users.recover_done' ) return render ( request , 'users/recover_failed.html' )
login via an account recovery link .