def user_login(request):
    next = request.GET.get('next')
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            user = authenticate(request,
                                email=cd['email'],
                                password=cd['password'])
            if user is not None:
                if user.is_active:
                    login(request, user)
                    if next:
                        return redirect(next)
                    return redirect('core:home')

            else:
                messages.info(request,
                              "Podany login lub hasło jest niepoprawne")

        # return render(request, 'core/login.html', {'form': form})

    else:
        form = LoginForm()
    return render(request, 'core/login.html', {'form': form})
 def post(self, request, *args, **kwargs):
     """
     Post method that will enable users to login
     if the details provided are correct. Will then
     redirect to correct view.
     """
     form = LoginForm(request.POST)
     next_url = request.GET.get('next', None)
     # check that the form is valid
     if form.is_valid():
         # clean the user's information
         username = form.cleaned_data['username']
         password = form.cleaned_data['password']
         auth = authenticate(username=username, password=password)
         if auth is not None:
             # login user and route
             login(request, auth)
             request.session['username'] = username
             request.session['user_pk'] = auth.id
             if next_url:
                 return HttpResponseRedirect(next_url)
             return redirect('dashboard')
         else:
             # details incorrect
             messages.add_message(request, messages.ERROR,
                                  'Invalid login details')
             return redirect('login')
     # invalid form
     messages.add_message(request, messages.ERROR, 'Invalid login details')
     return redirect('login')
Exemple #3
0
def signin(request):

    if request.method == "POST":
        signin_form = LoginForm(data=request.POST)
        if signin_form.is_valid():
            name = signin_form.cleaned_data['username']
            password = signin_form.cleaned_data['password']

            user = authenticate(request,
                                username=name,
                                password=password,
                                is_staff=0)

            if user is not None and user.is_staff:

                login(request, user)
                messages.success(request, 'Login successful')
                return redirect('core:view_user')

            signin_form = LoginForm(data=request.POST)
            context = {'signin_form': signin_form}
            messages.error(request, 'Wrong username or password')
            return render(request, 'login.html', context)

    signin_form = LoginForm()
    context = {'signin_form': signin_form}
    return render(request, 'login.html', context)
Exemple #4
0
def login(request):
    form = LoginForm(request.POST)

    message = {}

    if request.method == 'POST':
        if form.is_valid():
            # Autentica o usuário
            usuario = authenticate(username=form.cleaned_data.get('username'),
                                   password=form.cleaned_data.get('password'))

            # Verifica se o usuário existe
            if usuario is not None:
                # Verifica se o usuário está ativo
                if usuario.is_active:
                    login_(request, usuario)
                    message = {'message': 'Login realizado com sucesso !', 'level': 'success'}
                else:
                    message = {'message': u'Seu usuário foi desativo !', 'level': 'danger'}
            else:
                message = {'message': u'Seu usuário ou senha estão incorretos !', 'level': 'danger'}
        else:
            response = JsonResponse(form.errors)
            response.status_code = 500
            return response

        return JsonResponse(message)
Exemple #5
0
def user_login(request):
    if (request.method == 'POST'):
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            # First get the username and password supplied
            username = login_form.cleaned_data["username"]
            password = login_form.cleaned_data["password"]
            # Django's built-in authentication function:
            user = authenticate(username=username, password=password)
            # If we have a user
            if user:
                # Check it the account is active
                if user.is_active:
                    # Log the user in.
                    login(request, user)
                    # Send the user back to homepage
                    return redirect("/")
                else:
                    # If account is not active:
                    return HttpResponse("Your account is not active.")
            else:
                print("Someone tried to login and failed.")
                print("They used username: {} and password: {}".format(username, password))
                return render(request, 'core/login.html', {"login_form": LoginForm})
    else:
        # Nothing has been provided for username or password.
        return render(request, 'core/login.html', {"login_form": LoginForm})
Exemple #6
0
def rps_login(request):
    if request.method == "POST":
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            username = login_form.cleaned_data['username']
            password = login_form.cleaned_data['password']
            user = authenticate(username=username, password=password)
            if (user):
                if (user.is_active):
                    login(request, user)
                    return redirect("/")
                else:
                    return HttpResponse(
                        "Your account is not currently active.")
            else:  #User not found. They'll have to sign up.
                print(
                    "Login failed. User \"{0}\" does not exist in the system, or you used the wrong password."
                    .format(username))
                return render(request, 'core/login.html', {
                    "title": "User login",
                    "login_form": LoginForm
                })
    else:
        return render(request, "core/login.html", {
            "title": "User login",
            "login_form": LoginForm
        })
Exemple #7
0
    def post(self, request):
        """
        Procces access data
        :param request: HttpRequest object
        :return: HttpResponse object with rendered login form
        """

        form = LoginForm(request.POST)

        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')

            # Check if credential access are ok
            user = authenticate(username=username, password=password)

            if user is None:
                # Show error message
                messages.error(request, "Ops! Incorrect credentials!")
            else:
                # Start authenticate user session
                django_login(request, user)

                # Get next url parameter
                url = request.GET.get('next', 'blogs')

                # Redirect user
                return redirect(url)

        context = {'form': form}
        return render(request, 'core/login.html', context)
Exemple #8
0
 def test_form_correct(self):
     form_data = {
         'username': '******',
         'password': '******',
     }
     form = LoginForm(data=form_data)
     # Data that was entered is correct
     self.assertTrue(form.is_valid())
 def post(self, request):
     form = LoginForm(request.POST)
     if form.is_valid():
         user = authenticate(username=User.objects.get(username= request.POST['username']), password=request.POST['password'])
         login(request, user)
         return redirect('materias_de_docente')
     else:
         return render(request, 'login.html', {'form': form})
 def test_invalid_login_form(self):
     """
     Test to check that form will perform as
     expect when given invalid inforamtion into form
     """
     form = LoginForm({})
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['username'], ['This field is required.'])
Exemple #11
0
 def post(self, request):
     form = LoginForm(request.POST)
     self.context['form'] = form
     if form.is_valid():
         u = authenticate(username=form.cleaned_data['usuario'],
                          password=form.cleaned_data['senha'])
         login(request, u)
     return render_to_response(self.template_name,
                               self.context,
                               RequestContext(request))
Exemple #12
0
 def post(self, request):
     form = LoginForm(request.POST)
     if form.is_valid():
         user = authenticate(
             username=User.objects.get(username=request.POST['username']),
             password=request.POST['password'])
         login(request, user)
         return redirect('materias_de_docente')
     else:
         return render(request, 'login.html', {'form': form})
Exemple #13
0
def core_login(request):
    form = LoginForm(request.POST or None)

    if form.is_valid():
        username = form.cleaned_data.get('username')
        password = form.cleaned_data.get('password')
        user = authenticate(username=username, password=password)
        if user is not None:
            login(request=request, user=user)
            return redirect(reverse('core_home', args=['login_success']))
    return render(request, 'core/login.html', locals())
Exemple #14
0
def home(request):
    if request.method == 'POST':
        #import pdb;pdb.set_trace()
        form = LoginForm(request.POST)
        if form.is_valid():
            user = form.cleaned_data['user']
            login(request, user)
            return redirect('profile')
    else:
        form = LoginForm()
    return render(request, 'core/home.html', {'form': form})
    def test_valid_login_form(self):
        """
        Test to check that given valid inforamtion
        the form will work correctly.
        """
        form = LoginForm({'username': '******', 'password': '******'})

        # check everything is correct
        self.assertTrue(form.is_valid())
        self.assertEquals(form.cleaned_data['username'], 'admin')
        self.assertEquals(form.cleaned_data['password'], 'password')
Exemple #16
0
    def test_form_username_missing(self):
        form_data = {
            'password': '******',
        }
        form = LoginForm(data=form_data)

        # Data that was entered is incorrect
        self.assertFalse(form.is_valid())

        # Ensure that only one error was given
        self.assertTrue(form.has_error('username'))
        self.assertEqual(len(form.errors.as_data()), 1)
Exemple #17
0
    def post(self, request, *args, **kwargs):
        form = LoginForm(request.POST)

        if not form.is_valid():
            return redirect(settings.LOGIN_URL)

        user = authenticate(username=form.cleaned_data.get('username'),
                            password=form.cleaned_data.get('password'))

        if user is not None and user.is_active:
            login(request, user)
            return redirect(settings.LOGIN_REDIRECT_URL)

        return redirect(settings.LOGIN_URL)
Exemple #18
0
def index(request):
    if request.method == "POST":
        form = LoginForm(request.POST)

        if form.is_valid():
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('profile')
    else:
        form = LoginForm()

    return render(request, 'index.html', {'form': form})
Exemple #19
0
    def test_form_incorrect(self):
        form_data = {
            'username': '******',
            'password': '******',
        }
        form = LoginForm(data=form_data)

        # Data that was entered is incorrect
        self.assertFalse(form.is_valid())

        # Ensure that only one (general) error was given
        self.assertEqual(len(form.errors.as_data()), 1)
        self.assertEqual(len(form.non_field_errors().as_data()), 1)
        self.assertEqual(form.non_field_errors().as_data()[0].code,
                         'ERROR_INVALID_LOGIN')
Exemple #20
0
def login(request):
    login_form = LoginForm()

    redirect_url = reverse('homepage', args=[])
    redirect_url = request.GET.get('next') or redirect_url

    if request.method == 'POST' and 'login_form' in request.POST:
        login_form = LoginForm(request.POST)

        if login_form.is_valid():
            return login_form.login(request, redirect_url=redirect_url)

    return render(request, "login.html", {
        "login_form": login_form,
    })
def login_user(request):
    """
    Login request handler
    """
    response = reply_object()
    form = LoginForm(request.POST, request=request)

    if form.is_valid():
        response["code"] = settings.APP_CODE["LOGIN"]
        response["next_view"] = reverse('home')
    else:
        response["code"] = settings.APP_CODE["FORM ERROR"]
        response["errors"] = form.errors

    return HttpResponse(simplejson.dumps(response))
Exemple #22
0
def login(request):
    Ticket = "not submitted"

    if request.method == "POST":
        # Get the posted form
        MyLoginForm = LoginForm(request.POST)

        if MyLoginForm.is_valid():
            Ticket = MyLoginForm.cleaned_data['ClientTicketID']
            Summary = MyLoginForm.cleaned_data['Summary']
            Description = MyLoginForm.cleaned_data['Description']
    else:
        MyLoginForm = LoginForm()

    return render(request, 'core/loggedin.html', {"ClientTicketID": Ticket, "Summary": Summary, "Description": Description})
Exemple #23
0
    def post(self, request, *args, **kwargs):
        form = LoginForm(request.POST)

        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']

            user = authenticate(username=username, password=password)

            if user is not None:
                login(request, user)

                return redirect(reverse('core:chat_get'))

        return render(request, 'form.html', {'form': form, 'form_action': reverse('core:login')})
Exemple #24
0
def login(request):
    login_form = LoginForm()

    redirect_url = reverse('homepage', args=[])
    redirect_url = request.GET.get('next') or redirect_url

    if request.method == 'POST' and 'login_form' in request.POST:
        login_form = LoginForm(request.POST)

        if login_form.is_valid():
            return login_form.login(request, redirect_url=redirect_url)

    return render(request, "login.html", {
        "login_form": login_form,
    })
Exemple #25
0
def login(request):
    next_redirect = request.GET.get('next')

    if request.user.is_authenticated():
        if not next_redirect:
            return HttpResponseRedirect(
                reverse('profile', kwargs={'user_id': request.user.id}))
        else:
            return HttpResponseRedirect(next_redirect)

    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = LoginForm(request.POST)
        # check whether it's valid:
        if form.is_valid():

            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')

            if '@' in username and '.' in username:
                uqs = User.objects.filter(email=username)
                username = uqs.first().username

            user = djauth.authenticate(username=username, password=password)

            if user is None:
                errors = form._errors.setdefault(NON_FIELD_ERRORS, ErrorList())
                errors.append(u"Could not authenticate you.")

            else:
                djauth.login(request, user)
                next_redirect = request.POST.get('next')
                if not next_redirect:
                    return HttpResponseRedirect(
                        reverse('profile', kwargs={'user_id':
                                                   request.user.id}))
                else:
                    return HttpResponseRedirect(next_redirect)

    # if a GET (or any other method) we'll create a blank form
    else:
        form = LoginForm()

    return render(request, 'auth/login.html', {
        'form': form,
        'next': next_redirect
    })
Exemple #26
0
def login_user(request, template='index.html', redirect_url=None):
    def handle_login_error(login_error):
        form = LoginForm()
        return render_to_response(template, {
            'login_error': login_error,
            'login_form': form,
        },
                                  context_instance=RequestContext(request))

    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            redirect_url = redirect_url or form.cleaned_data.get(
                'redirect_url')
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    # Redirect to a success page.
                    login(request, user)
                    if redirect_url:
                        return HttpResponseRedirect(redirect_url)
                    else:
                        return render_to_response(
                            template, {'login_succeeded': True},
                            context_instance=RequestContext(request))
                else:
                    # Return a 'disabled account' error message
                    error = u'Account disabled'
            else:
                # Return an 'invalid login' error message.
                error = u'Invalid login'
        else:
            error = u'Login form is invalid'

        return handle_login_error(error)

    else:
        form = LoginForm()  # An unbound form
        form.fields['redirect_url'].initial = request.GET.get('next', '/')
        return render_to_response(template, {
            'login_error': "You must first login",
            'form': form
        },
                                  context_instance=RequestContext(request))
def do_login(request):
    error_message = u""
    if request.method == 'POST':
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
                    
                    return HttpResponseRedirect(
                        reverse('core_home')
                        )

                else:
                    error_message = "This account is disabled."
            
        error_message = "Invalid login details provided."

    else: # GET

        # HACK: Suitable for NFC demo only.
        # Check if the NFC token has been supplied as a URL parameter. If it 
        # has, authenticate using this.
        nfc_token = request.GET.get('nfc_token')
        if nfc_token is not None:
            user = authenticate(nfc_token=nfc_token)
            login(request, user)

            return HttpResponseRedirect(
                reverse('core_home')
                )

        else:
            login_form = LoginForm()

    return render_to_response(
        'login.html',
        context_instance=RequestContext(
            request,
            {'login_form': login_form, 'error_message': error_message}
            )
        )
Exemple #28
0
def do_login(request):
    form = LoginForm(request.POST)

    if form.is_valid():
        username = form.cleaned_data['username']
        password = form.cleaned_data['password']

        print(username, password)
        user = authenticate(request, username=username, password=password)

        if user is not None:
            login(request, user)
            request.session['success'] = "You are now logged in."
            messages.success(request, 'You are now logged in.')
            return HttpResponseRedirect('/')

    messages.error(request, "The username and password were incorrect.")
    return HttpResponseRedirect(reverse('login'))
Exemple #29
0
def login_view(request):
    form = LoginForm(data=request.POST or None)
    context = {
        'form': form,
    }

    if request.method == 'POST' and form.is_valid():
        user = form.get_user()
        login(request, user)

        chat, created = Chat.objects.get_or_create(name='chat')
        chat.user.add(user.id)

        logger.info('User %s log in', user)

        return redirect(settings.LOGIN_REDIRECT_URL)

    return render(request, 'registration/login.html', context)
Exemple #30
0
def login_user(request, template='index.html', redirect_url=None):

    def handle_login_error(login_error):
        form = LoginForm()
        return render_to_response(template, {
            'login_error' : login_error,
            'login_form' : form,
        }, context_instance=RequestContext(request))

    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            redirect_url = redirect_url or form.cleaned_data.get('redirect_url')
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    # Redirect to a success page.
                    login(request, user)
                    if redirect_url:
                        return HttpResponseRedirect(redirect_url)
                    else:
                        return render_to_response(template, {
                            'login_succeeded': True
                        }, context_instance=RequestContext(request))
                else:
                    # Return a 'disabled account' error message
                    error = u'Account disabled'
            else:
                # Return an 'invalid login' error message.
                error = u'Invalid login'
        else: 
            error = u'Login form is invalid'

        return handle_login_error(error)

    else:
        form = LoginForm() # An unbound form
        form.fields['redirect_url'].initial = request.GET.get('next', '/')
        return render_to_response(template, {
            'login_error': "You must first login",
            'form': form
        }, context_instance=RequestContext(request))
Exemple #31
0
def log_in(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            try:
                print(form.cleaned_data.get('contact'))
                user = User.objects.get(
                    contact=form.cleaned_data.get('contact'))
            except:
                return HttpResponse("Enter Registered Contact Number!")
            else:
                sms = authy_api.users.request_sms(user.authy_id)
                print(sms)
                if sms.ok():
                    return redirect('verify_otp', user.authy_id)
                else:
                    return render(request, "500.html")
    else:
        form = LoginForm()
        return render(request, 'login.html', {'form': form})
Exemple #32
0
def login_view(request):
    if request.method == 'POST':
        form = LoginForm(data=request.POST)
        if form.is_valid():
            email = form.cleaned_data.get('email')
            password = form.cleaned_data.get('password')

            try:
                user = User.objects.get(email=email)
            except:
                return HttpResponse("User doesn't exist")
            if user.password != password:
                return HttpResponse("Incorrect password")
            user.is_active = True
            user.save()
            login(request, user)
            return redirect('home')
    else:
        form = LoginForm()
    return render(request, 'login.html', {'form': form})
Exemple #33
0
def submit_req(request):
    with open('rfc.txt') as json_file:
        data = json.load(json_file)

    if request.method == "POST":
        # Get the posted form
        MyLoginForm = LoginForm(request.POST)

        if MyLoginForm.is_valid():
            data["ns0:Process"]["ns2:Ticket"]["ClientTicketID"] = MyLoginForm.cleaned_data['ClientTicketID']
            data["ns0:Process"]["ns2:Ticket"]["Summary"] = MyLoginForm.cleaned_data['Summary']
            data["ns0:Process"]["ns2:Ticket"]["Description"] = MyLoginForm.cleaned_data['Description']
    else:
        MyLoginForm = LoginForm()

    json_pretty = json.dumps(data)
    context = {
        "json_pretty": json_pretty,
    }
    return render(request, 'core/hello.html', context)
Exemple #34
0
def login(request):
    if request.session.has_key("user_id") and request.session["user_id"] is not "":
        return HttpResponseRedirect("/")
    
    form = LoginForm(initial = {'username':''})
    context = { 'name': 'ruby',  'form': form}
    flag = -1
    if request.POST:
        form = LoginForm(request.POST)
        if form.is_valid():
            flag = form.login(request)
        else:
            flag = 3
            messages.info(request, "Form is invalid")
    if flag == 1:
        messages.info(request, "username or password is wrong")
    if flag == 2 or flag == 0:
        return HttpResponseRedirect("/")
    else:
        return render(request,"login.html", context)
def login(request):
    next_redirect = request.GET.get('next')

    if request.user.is_authenticated():
        if not next_redirect:
            return HttpResponseRedirect(reverse('profile', kwargs={'user_id': request.user.id}))
        else:
            return HttpResponseRedirect(next_redirect)

    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = LoginForm(request.POST)
        # check whether it's valid:
        if form.is_valid():

            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')

            if '@' in username and '.' in username:
                uqs = User.objects.filter(email=username)
                username = uqs.first().username

            user = djauth.authenticate(username=username, password=password)

            if user is None:
                errors = form._errors.setdefault(NON_FIELD_ERRORS, ErrorList())
                errors.append(u"Could not authenticate you.")

            else:
                djauth.login(request, user)
                next_redirect = request.POST.get('next')
                if not next_redirect:
                    return HttpResponseRedirect(reverse('organization-overview'))
                else:
                    return HttpResponseRedirect(next_redirect)

    # if a GET (or any other method) we'll create a blank form
    else:
        form = LoginForm()

    return render(request, 'auth/login.html', {'form': form, 'next': next_redirect})
Exemple #36
0
def sign_up(request):
    if request.method == "POST":

        form = LoginForm(request.POST)
        if form.is_valid():
            first_pass = form.cleaned_data["password"]
            conf_pass = request.POST.get("confpass", "")

            if not conf_pass:
                return HttpResponse("Please Enter Confirm password")

            if first_pass != conf_pass:
                return HttpResponse("Your passwords do not match")
            else:
                print first_pass
                print conf_pass
                form.save()
    else:
        form = LoginForm()

    return render(request, "core/login.html", {"form": form})
Exemple #37
0
def auth(request):
    if request.method == "POST":
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            username = login_form.cleaned_data.get('username')
            password = login_form.cleaned_data.get('password')
            user = authenticate(username=username, password=password)
            if user is not None:
                login(request, user)
                nxt = request.GET.get('next')
                if nxt:
                    return redirect(nxt)
                else:
                    return redirect(index)
            else:
                return render(request, 'login.html', {'login_form': login_form, 'error': True})
        else:
            return render(request, 'login.html', {'login_form': login_form})
    else:
        login_form = LoginForm()
        return render(request, 'login.html', {'login_form': login_form})
Exemple #38
0
def login_view(request):
    if request.method == 'POST':
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            username = login_form.cleaned_data['username']
            password = login_form.cleaned_data['password']
            user = authenticate(request, username=username, password=password)

            if user is not None:
                login(request, user)
                return redirect('/')

        error_message = ('Invalid login. Please complete the form '
                         'with your username and password')
        return render(request, 'core/login.html', {
            'error_message': error_message,
            'login_form': login_form,
        })

    else:
        login_form = LoginForm()
        return render(request, 'core/login.html', {'login_form': login_form})
Exemple #39
0
    def post(self, request):
        form = LoginForm(request.POST)
        next_page = request.GET.get('next')
        print(next_page)

        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            user = authenticate(username=username, password=password)

            if user is not None:
                if user.is_active:
                    login(request, user)
                if next_page:
                    return redirect(next_page)
                return redirect('/')
            else:
                return render(request, 'login.html', {
                    'form': form,
                    'message': 'Nie ma takiego uzytkownika'
                })
        else:
            return render(request, 'login.html', {'form': form})
Exemple #40
0
def login_page(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            login = form.cleaned_data['login']
            password = form.cleaned_data['password']
            user = auth.authenticate(username=login, password=password)
            if user is not None and user.is_active:
                auth.login(request, user)
                if request.is_ajax():
                    return HttpResponse(content=json.dumps({'success': 'accueil'}))
                # return redirect('accueil')  # Redirect after POST
            else:
                if request.is_ajax():
                    return HttpResponse(content=json.dumps({'error': '/'}))
                    # return HttpResponse(content=json.dump({'success': 'login_page','errors': form.errors}))
        elif request.is_ajax():
            errors = json.dumps(form.errors)
            return HttpResponse(errors)

    else:
        form = LoginForm()
    return render(request, 'login.html', {'form': form})
Exemple #41
0
def login_user(request):
    next = None
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(username=request.POST['username'],
                                password=request.POST['password'])
            if user is not None:
                login(request, user)
                try:
                    next = request.POST['next']
                    return redirect(next)
                except:
                    next = 'dashboard'
                    return redirect(next)

            else:
                messages.add_message(request, messages.ERROR,
                                     'Failed to authenticate.')
                return redirect('login')
        else:
            messages.add_message(request, messages.ERROR,
                                 'Failed to authenticate.')
            return redirect('login')
    else:
        form = LoginForm()
        try:
            next = request.GET['next']
        except:
            next = None
        return render(request,
                      'core/login.html',
                      context={
                          'form': form,
                          'next': next
                      })