

@handle_response_format
def user_login(request, response_format='html'):
    'User login'
    if request.user.username:
        return HttpResponseRedirect(reverse('user_denied'))
    next = request.GET.get('next', '/')
    form = LoginForm(request.POST)
    if request.POST:
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        if (user and getattr(settings, 'HARDTREE_DISABLE_EVERGREEN_USERS', False) and ('evergreen_' in user.username[:10])):
            user = None
        if form.is_valid():
            if (user is not None):
                try:
                    profile = user.profile
                except:
                    profile = None
                if (not profile):
                    return render_to_response('core/user_login', {
                        'error_message': 'Username or password you entered is not valid',
                        'form': Markup(form),
                    }, context_instance=RequestContext(request), response_format=response_format)
                if profile.disabled:
                    return render_to_response('core/user_login', {
                        'error_message': 'Your account is disabled.',
                        'form': Markup(form),
                    }, context_instance=RequestContext(request), response_format=response_format)
                if (user.is_active and profile):
                    if getattr(settings, 'HARDTREE_SUBSCRIPTION_BLOCKED', False):
                        return render_to_response('core/user_login', {
                            'error_message': 'We are sorry to inform you but your account has been deactivated. Please login to your <a href="https://www.tree.io/login/">control panel</a> to see details.',
                            'form': Markup(form),
                        }, context_instance=RequestContext(request), response_format=response_format)
                    login(request, user)
                    if getattr(settings, 'HARDTREE_MULTIPLE_LOGINS_DISABLED', False):
                        for ses in Session.objects.all():
                            if (ses != request.session):
                                try:
                                    data = ses.get_decoded()
                                    if (('_auth_user_id' in data) and (data['_auth_user_id'] == request.user.id)):
                                        ses.delete()
                                except Exception:
                                    pass
                    if ('next' in request.POST):
                        return HttpResponseRedirect(request.POST['next'])
                    else:
                        return HttpResponseRedirect(next)
                else:
                    return render_to_response('core/user_login_disabled', context_instance=RequestContext(request), response_format=response_format)
            else:
                return render_to_response('core/user_login', {
                    'error_message': 'Username or password you entered is not valid',
                    'form': Markup(form),
                }, context_instance=RequestContext(request), response_format=response_format)
        elif ((not form.is_valid()) and (user is None)):
            return render_to_response('core/user_login', {
                'error_message': 'Username or password you entered is not valid',
                'form': Markup(form),
            }, context_instance=RequestContext(request), response_format=response_format)
        else:
            return render_to_response('core/user_login', {
                'error_message': 'Please re-enter the text from the image',
                'form': Markup(form),
            }, context_instance=RequestContext(request), response_format=response_format)
    else:
        return render_to_response('core/user_login', {
            'form': Markup(form),
        }, context_instance=RequestContext(request), response_format=response_format)

dataset/ETHPy150Open treeio/treeio/treeio/core/views.py user_login/original