Esempio n. 1
0
def login_view(request):
    """Check User credentials

    **Attributes**:

        * ``form`` - LoginForm
        * ``template`` - frontend/index.html

    **Logic Description**:

        * Submitted user credentials need to be checked. If it is not valid
          then the system will redirect to the login page.
        * If submitted user credentials are valid then system will redirect to
          the dashboard.
    """
    template = 'frontend/index.html'
    errorlogin = ''

    if request.method == 'POST':
        loginform = LoginForm(request.POST)
        if loginform.is_valid():
            cd = loginform.cleaned_data
            user = authenticate(username=cd['user'], password=cd['password'])
            if user is not None:
                if user.is_active:
                    login(request, user)
                    request.session['has_notified'] = False
                    # Redirect to a success page (dashboard).
                    return HttpResponseRedirect('/dashboard/')
                else:
                    # Return a 'disabled account' error message
                    errorlogin = _('Disabled Account')
            else:
                # Return an 'invalid login' error message.
                errorlogin = _('Invalid Login.')
        else:
            # Return an 'Valid User Credentials' error message.
            errorlogin = _('Enter Valid User Credentials.')
    else:
        loginform = LoginForm()

    data = {
        'module': current_view(request),
        'loginform': loginform,
        'errorlogin': errorlogin,
        'news': get_news(news_url),
        'is_authenticated': request.user.is_authenticated(),
    }

    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
Esempio n. 2
0
def login_view(request):
    """Check User credentials

    **Attributes**:

        * ``form`` - LoginForm
        * ``template`` - frontend/index.html

    **Logic Description**:

        * Submitted user credentials need to be checked. If it is not valid
          then the system will redirect to the login page.
        * If submitted user credentials are valid then system will redirect to
          the dashboard.
    """
    template = 'frontend/index.html'
    errorlogin = ''

    if request.method == 'POST':
        loginform = LoginForm(request.POST)
        if loginform.is_valid():
            cd = loginform.cleaned_data
            user = authenticate(username=cd['user'],
                                password=cd['password'])
            if user is not None:
                if user.is_active:
                    login(request, user)
                    request.session['has_notified'] = False
                    # Redirect to a success page (dashboard).
                    return HttpResponseRedirect('/dashboard/')
                else:
                    # Return a 'disabled account' error message
                    errorlogin = _('Disabled Account')
            else:
                # Return an 'invalid login' error message.
                errorlogin = _('Invalid Login.')
        else:
            # Return an 'Valid User Credentials' error message.
            errorlogin = _('Enter Valid User Credentials.')
    else:
        loginform = LoginForm()

    data = {
        'module': current_view(request),
        'loginform': loginform,
        'errorlogin': errorlogin,
        'news': get_news(news_url),
        'is_authenticated': request.user.is_authenticated(),
    }

    return render_to_response(template, data,
           context_instance=RequestContext(request))
Esempio n. 3
0
def login_view(request):
    """Check User credentials

    **Attributes**:

        * ``form`` - LoginForm
        * ``template`` - frontend/index.html

    **Logic Description**:

        * Submitted user credentials need to be checked. If it is not valid
          then the system will redirect to the login page.
        * If submitted user credentials are valid then system will redirect to
          the dashboard.
    """
    template = "frontend/index.html"
    errorlogin = ""

    if request.method == "POST":
        loginform = LoginForm(request.POST)
        if loginform.is_valid():
            cd = loginform.cleaned_data
            user = authenticate(username=cd["user"], password=cd["password"])
            if user is not None:
                if user.is_active:
                    login(request, user)
                    request.session["has_notified"] = False
                    # Redirect to a success page (dashboard).
                    return HttpResponseRedirect("/dashboard/")
                else:
                    # Return a 'disabled account' error message
                    errorlogin = _("Disabled Account")
            else:
                # Return an 'invalid login' error message.
                errorlogin = _("Invalid Login.")
        else:
            # Return an 'Valid User Credentials' error message.
            errorlogin = _("Enter Valid User Credentials.")
    else:
        loginform = LoginForm()

    data = {
        "module": current_view(request),
        "loginform": loginform,
        "errorlogin": errorlogin,
        "news": get_news(news_url),
        "is_authenticated": request.user.is_authenticated(),
    }

    return render_to_response(template, data, context_instance=RequestContext(request))
Esempio n. 4
0
def login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = custom_backend.authenticate(email=form.cleaned_data['email'], password=form.cleaned_data['password'])
            if user is not None:
                auth.login(request, user)

                return redirect('index')
            else:
                return render(request, 'frontend/login.html', {'message_error': 'Email or password is incorrect!!'})
        else:
            return render(request, 'frontend/login.html', {'form': form})
    else:
        if request.user.is_authenticated:
            return redirect('index')

        return render(request, 'frontend/login.html')
Esempio n. 5
0
def login_user(request):
    arg = dict()
    arg['form'] = LoginForm
    if request.method == 'POST':
        login_form = LoginForm(data=request.POST or None)
        if login_form.is_valid():
            user = authenticate(request,
                                username=login_form.data.get('username'),
                                password=login_form.data.get('password'))
            if user is not None:
                login(request, user)
                return redirect('frontend:dashboard')
            messages.add_message(request, messages.ERROR,
                                 'Wrong username or password')
            return redirect('frontend:login')
        messages.add_message(request, messages.ERROR,
                             'Wrong username or password')
        return redirect('frontend:login')
    return render(request, 'login.html', arg)
Esempio n. 6
0
def login(request):
    """
    shows login form and authenticates a user

    to create a user log in into shell
    from django.contrib.auth.models import User
    User.objects.create_user('*****@*****.**', '*****@*****.**', 'password')

    :param request:
    :return:
    """
    if request.method == 'POST':
        email = request.POST['email']
        password = request.POST['password']
        redirect_url = request.GET.get('next', '/')

        form = LoginForm(request.POST)
        if form.is_valid():
            try:
                username = User.objects.get(email=email).username
                user = auth.authenticate(username=username, password=password)
            except User.DoesNotExist:
                user = None

            if user is not None:
                if user.is_active:
                    auth.login(request, user)
                    return redirect(redirect_url)
                else:
                    messages.error(request, _('your account is suspended'))
            else:
                messages.error(request, _('invalid login or password'))
    else:
        form = LoginForm()
        reg_email = request.session.get('reg_email', None)
        if reg_email is not None:
            form.fields['email'].initial = reg_email

    context = {
        'form': form
    }
    return render(request, 'login.html', context)
Esempio n. 7
0
 def test_login(self):
     form = LoginForm(data=self.credentials)
     self.assertTrue(form.is_valid())