Пример #1
0
def index(request):
    """Index Page of CDR-Stats

    **Attributes**:

        * ``template`` - frontend/index.html
        * ``form`` - loginForm
    """
    errorlogin = ''
    loginform = LoginForm()

    if request.GET.get('acc_code_error'):
        if request.GET['acc_code_error'] == 'true':
            errorlogin = _('account code is not assigned!')

    if request.GET.get('voip_plan_error'):
        if request.GET['voip_plan_error'] == 'true':
            errorlogin = _('voip plan is not attached to user!')

    data = {
        'loginform': loginform,
        'errorlogin': errorlogin,
        'news': get_news(settings.NEWS_URL),
    }
    return render_to_response('frontend/index.html', data, context_instance=RequestContext(request))
Пример #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.
    """
    errorlogin = ''
    loginform = LoginForm(request.POST or None)
    if request.method == '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.')

    data = {
        'loginform': loginform,
        'errorlogin': errorlogin,
        'news': get_news(news_url),
        'is_authenticated': request.user.is_authenticated(),
    }
    return render_to_response('frontend/index.html',
                              data,
                              context_instance=RequestContext(request))
Пример #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.
    """
    errorlogin = ''
    loginform = LoginForm(request.POST or None)
    if request.method == '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.')

    data = {
        'loginform': loginform,
        'errorlogin': errorlogin,
        'news': get_news(news_url),
        'is_authenticated': request.user.is_authenticated(),
    }
    return render_to_response('frontend/index.html', data, context_instance=RequestContext(request))