Ejemplo n.º 1
0
def iniciarSessao(request):

    data = {}

    if request.method == 'POST':

        form = LoginForm(request.POST)

        if form.is_valid():
            email = request.POST.get('email')
            password = request.POST.get('password')
            user = authenticate(email=email, password=password)

            if user is not None:
                if user.is_active:
                    login(request, user)
                    return HttpResponseRedirect("/userAccount/")
                else:
                    data['failedLogin'] = form.validation_errors[
                        'LOGIN_ERROR_2']
                    form = LoginForm(label_suffix='')
            else:
                data['failedLogin'] = form.validation_errors['LOGIN_ERROR_1']
                form = LoginForm(label_suffix='')

    else:
        form = LoginForm(label_suffix='')

    data['menu0Se1ect1'] = 'class=menuOpcSelected'
    data['form'] = form

    return render(request, 'login.tpl', data)
Ejemplo n.º 2
0
    def post(self, request):
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']

            response_data, user = authenticate_ldap(username, password, False)

            if user is not None and user.is_authenticated():
                designations = user.designations.all()
                have_active_designation = any([designation.is_active() for designation in designations])
                if have_active_designation:
                    login(request, user)
                    next_ = request.GET.get('next')
                    if next_ is not None:
                        return redirect(next_)
                else:
                    form.add_error(None,
                                   "You don't have content creation access. "
                                   "If you wish to get permissions, please contact Aman Gour")
                    return render(request, self.template_name, {'form': form})
                return redirect('content_home')
            else:
                form.add_error(None, "Unable to authenticate. Please check username/password")
        return render(request, self.template_name, {'form': form})
Ejemplo n.º 3
0
    def post(self, request):
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']

            response_data, user = authenticate_ldap(username, password, False)

            if user is not None and user.is_authenticated():
                designations = user.designations.all()
                have_active_designation = any(
                    [designation.is_active() for designation in designations])
                if have_active_designation:
                    login(request, user)
                    next_ = request.GET.get('next')
                    if next_ is not None:
                        return redirect(next_)
                else:
                    form.add_error(
                        None, "You don't have content creation access. "
                        "If you wish to get permissions, please contact Aman Gour"
                    )
                    return render(request, self.template_name, {'form': form})
                return redirect('content_home')
            else:
                form.add_error(
                    None,
                    "Unable to authenticate. Please check username/password")
        return render(request, self.template_name, {'form': form})
Ejemplo n.º 4
0
def iniciarSessao(request):
    
    data = {}
    
    if request.method == 'POST':
        
        form = LoginForm(request.POST)
        
        if form.is_valid():
            email=request.POST.get('email')
            password=request.POST.get('password')
            user = authenticate(email=email, password=password)
        
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return HttpResponseRedirect("/userAccount/")
                else:
                    data['failedLogin']=form.validation_errors['LOGIN_ERROR_2']
                    form = LoginForm(label_suffix='')
            else:    
                data['failedLogin']=form.validation_errors['LOGIN_ERROR_1']
                form = LoginForm(label_suffix='')
    
    else:
        form = LoginForm(label_suffix='')
    
    data['menu0Se1ect1'] = 'class=menuOpcSelected'
    data['form'] = form
    
    return render(request, 'login.tpl', data)