Ejemplo n.º 1
0
def login_view(request):
    """
        Funktion des Login-View. 

            Wenn HTTP Methode gleich GET
                Leeres Login Formular anzeigen
            Wenn HTTP Methode gleich POST
                Mit den Benutzerdaten wird eine Authentifizierung gemacht. 
                Wenn valid zum Home-Screen weiterleiten
        """
    if request.user.is_authenticated:
        return redirect("/home/")

    if request.POST:
        form = AccountAuthenticationForm(request.POST)

        if form.is_valid():
            request.user = authenticate(email=request.POST['email'].lower(),
                                        password=request.POST['password'])
            if request.user:
                login(request, request.user)
                return redirect("/home/")
        else:
            return render(request, 'account/login.html', {"form": form})
    else:
        return render(request, 'account/login.html',
                      {"form": AccountAuthenticationForm()})
Ejemplo n.º 2
0
def login_view(request, *args, **kwargs):
    context = {}

    user = request.user
    if user.is_authenticated:
        return redirect('home')

    destination = get_redirect_if_exists(request)

    if request.POST:
        form = AccountAuthenticationForm(request.POST)
        if form.is_valid():
            phone = request.POST['phone']
            password = request.POST['password']
            user = authenticate(phone=phone, password=password)

            if user:
                login(request, user)
                if destination:
                    return redirect(destination)
                return redirect('home')

    else:
        form = AccountAuthenticationForm()

    context['login_form'] = form

    return render(request, 'account/login.html', context)
Ejemplo n.º 3
0
def login_view(request):
    context = {}
    context['page_title'] = "Login"

    user = request.user

    if user.is_authenticated:
        return redirect("/")

    if request.POST:
        form = AccountAuthenticationForm(request.POST)

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

            if user:
                login(request, user)

                if user.is_authenticated:
                    return redirect('/sessions/welcome/')
                else:
                    print("Not authenticated")

        else:
            context['errors'] = form.errors

    else:
        form = AccountAuthenticationForm()

    context['form'] = form

    return render(request, "account/login.html", context)
Ejemplo n.º 4
0
def login_view(request, *args, **kwargs):
    context = {}

    user = request.user
    if user.is_authenticated:
        return redirect("home")

    destination = get_redirect_if_exists(request)
    print("destination: " + str(destination))

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

            if user:
                login(request, user)
                if destination:
                    return redirect(destination)
                return redirect("home")

    else:
        form = AccountAuthenticationForm()

    context['login_form'] = form

    return render(request, "account/login.html", context)
Ejemplo n.º 5
0
def login_view(request):

    context = {}

    user = request.user
    if user.is_authenticated:
        return redirect("app:home")

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

            if user:
                login(request, user)
                messages.success(request, ("Welcome back!"))
                return redirect("app:home")
            else:
                messages.success(request, (
                    "Ooops! We're sorry but that didn't work. Please try again!"
                ))
                return redirect('account:login')

    else:
        form = AccountAuthenticationForm()

    context['login_form'] = form
    return render(request, 'account/login.html', context)
def login_view(request):

	context = {}

	user = request.user
	if user.is_authenticated:
		return redirect("index")

	if request.POST:
		form = AccountAuthenticationForm(request.POST)
		if form.is_valid():
			mobilenumber = request.POST['mobilenumber']
			password = request.POST['password']
			user = authenticate(mobilenumber=mobilenumber, password=password)

			if user:
				login(request, user)
				return redirect("index")

	else:
		form = AccountAuthenticationForm()

	context['login_form'] = form

	print(form)
	return render(request, "account/login.html", context)
Ejemplo n.º 7
0
def userlogin(request):
    msg = ""
    user = request.user
    if user.is_authenticated:
        return redirect("../")
    else:
        if request.POST:
            form = AccountAuthenticationForm(request.POST)
            if form.is_valid():
                email = form.cleaned_data['email']
                password = form.cleaned_data['password']
                user = authenticate(email=email, password=password)
                global usernamee
                usernamee = email
                if user:
                    login(request, user)
                    request.user = user
                    next = request.POST.get('next', '../')
                    if next == "":
                        next = "../"
                    return redirect(next)
                    # return redirect('../')
                else:
                    msg = "invalid Email or password"
        else:
            form = AccountAuthenticationForm()
        return render(request, 'account/login.html', {
            "form": form,
            "msg": msg
        })
    # username=BaseUserManager.normalize_email(username)

    context['login form'] = form
    print("context :", context)
    return render(request, 'account/register.html', context)
Ejemplo n.º 8
0
def login_view(request):

    context = {}

    user = request.user
    if user.is_authenticated:
        return redirect("home")

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

            if user:
                login(request, user)
                return redirect("home")

    else:
        form = AccountAuthenticationForm()

    context['login_form'] = form

    return render(request, "account/login.html", context)
Ejemplo n.º 9
0
def login_view(request):

	context={}
	user=request.user
	if user.is_authenticated:
		return redirect('home')

	if request.POST:
		form=AccountAuthenticationForm(request.POST)

		if form.is_valid():
			email=form.cleaned_data.get("email")
			password=form.cleaned_data.get("password")
			user=authenticate(email=email,password=password)

			if user:
				login(request,user)
				return redirect('home')

	else:
		form=AccountAuthenticationForm();

	context['login_form']=form
	
	return render(request,'account/login.html',context)
Ejemplo n.º 10
0
def recipes_view(request, dish=None):
    context = {}
    if dish is None:
        resepti_lista = Ohje.objects.all()
    else:
        resepti_lista = Ohje.objects.filter(dish=dish)

    myFilter = OhjeFilter(request.GET, queryset=resepti_lista)
    resepti_lista = myFilter.qs

    resepti_lista = sorted(resepti_lista,
                           key=attrgetter("date_published"),
                           reverse=True)

    if request.POST:
        form = RegistrationForm(request.POST)
        login_form = AccountAuthenticationForm(request.POST)  #
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get("username")
            raw_password = form.cleaned_data.get("password1")
            account = authenticate(username=username, password=raw_password)
            login(request, account)
            return redirect("recipe:recipes")

        elif login_form.is_valid():
            username = request.POST["username"]
            password = request.POST["password"]
            user = authenticate(username=username, password=password)

            if user:
                login(request, user)
                return redirect("recipe:recipes")

        else:
            context["registration_form"] = form

    else:
        user = request.user
        kommentti_lista = Comment.objects.filter(
            recipe_commented__author__username=user.username)
        kommentti_lista = sorted(kommentti_lista,
                                 key=attrgetter("create_date"),
                                 reverse=True)
        context["kommentti_lista"] = kommentti_lista

        login_form = AccountAuthenticationForm()  #
        form = RegistrationForm()
        context["registration_form"] = form
        context["login_form"] = login_form
        context["resepti_lista"] = resepti_lista
        context["myFilter"] = myFilter

        return render(request, "recipe/recipes.html", context)
Ejemplo n.º 11
0
 def post(self, request):
     if request.user.is_authenticated:
         return redirect('landing')
     context = {}
     form = AccountAuthenticationForm(request.POST)
     if form.is_valid():
         email = request.POST['email']
         password = request.POST['password']
         user = authenticate(email=email, password=password)
         if user:
             login(request, user)
             return redirect('landing')
     context['signin_form'] = form
     return render(request, 'signin.html', context)
Ejemplo n.º 12
0
def token_view(request):
    context = {}
    form = AccountAuthenticationForm()
    user = request.user
    if not user.is_authenticated:
        return redirect('login')

    context['token_form'] = form
    return render(request, 'account/gettoken.html', context)
Ejemplo n.º 13
0
def loginView(request):
    context = {}

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

            if user:
                login(request, user)
                return redirect('dashboard')
    else:
        form = AccountAuthenticationForm()

    context['login_form'] = form
    return render(request, 'account/login.html', context)
Ejemplo n.º 14
0
def login_view(request):
    context = {}
    user = request.user
    if user.is_authenticated:
        return redirect('/profile')  #('user_profile/profile.html')
    if request.POST:
        form = AccountAuthenticationForm(request.POST)
        if form.is_valid():
            password = request.POST['password']
            email = request.POST['email']
            user = authenticate(email=email, password=password)
            if user:
                login(request, user)
                return redirect('/profile')  #('user_profile/profile.html')
    else:
        form = AccountAuthenticationForm()
    context['login_form'] = form
    return render(request, 'account/login.html', context)
Ejemplo n.º 15
0
def index(request):
    template = 'index.html'
    if request.POST:
        if 'login' in request.POST:
            form = AccountAuthenticationForm(request.POST)
            if form.is_valid():
                username = request.POST['username']
                password = request.POST['password']
                try:
                    user = authenticate(
                        username=Account.objects.get(email=username),
                        password=password)
                except:
                    user = authenticate(username=username, password=password)
                if user:
                    login(request, user)
                    return redirect('core:home')
    else:
        form = AccountAuthenticationForm()
    context = {'form': form}
    return render(request, template, context)
Ejemplo n.º 16
0
def login_view(request):
    context = {}
    user = request.user
    if user.is_authenticated:
        return redirect('news_home')
    if request.POST:
        form = AccountAuthenticationForm(request.POST)
        if form.is_valid:
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user:
                login(request, user)
                return redirect('news_home')
    else:
        form = AccountAuthenticationForm()

    context['login_form'] = form
    context['title'] = 'Login'

    return render(request, 'account/login.html', context)
Ejemplo n.º 17
0
def login_view(request):
    context = {}

    user = request.user
    if user.is_authenticated:
        return redirect('home')
    if request.POST:
        form = AccountAuthenticationForm(request.POST)
        if form.is_valid():
            username = request.POST.get('username')
            password = request.POST.get('password')
            user = authenticate(username=username, password=password)

            if user:
                login(request, user)
                return redirect('home')

    else:
        form = AccountAuthenticationForm()
    context['login_form'] = form
    return render(request, 'account/login.html', context)
Ejemplo n.º 18
0
def login_view(request):
    if request.GET:
        next_page = request.GET['next']
    else:
        next_page = "home"
    context = {}
    user = request.user
    if user.is_authenticated:
        return redirect('home')

    if request.POST:
        form = AccountAuthenticationForm(request.POST)
        if form.is_valid():
            email = request.POST['email']
            password = request.POST['password']
            print('authenticating')
            user = authenticate(email=email, password=password)
            if user:
                if not user.is_approved:
                    context['inactive'] = 'Your account is still pending approval.'
                else:
                    login(request, user)
                    return redirect(next_page)
        else:
            context['errors'] = form.non_field_errors()

    else:
        form = AccountAuthenticationForm()

    context['login_form'] = form
    return render(request, 'account/login.html', context)
Ejemplo n.º 19
0
def home_view(request):
    context = {}
    if request.POST:
        form = RegistrationForm(request.POST)
        login_form = AccountAuthenticationForm(request.POST)  #
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get("username")
            raw_password = form.cleaned_data.get("password1")
            account = authenticate(username=username, password=raw_password)
            login(request, account)
            return redirect("home")
        #elif toinen on validi
        elif login_form.is_valid():
            username = request.POST["username"]
            password = request.POST["password"]
            user = authenticate(username=username, password=password)

            if user:
                login(request, user)
                return redirect("home")

        else:
            context["registration_form"] = form

    else:
        user = request.user
        kommentti_lista = Comment.objects.filter(
            recipe_commented__author__username=user.username)
        kommentti_lista = sorted(kommentti_lista,
                                 key=attrgetter("create_date"),
                                 reverse=True)
        kommentti_lista = kommentti_lista[0:5]
        context["kommentti_lista"] = kommentti_lista
        login_form = AccountAuthenticationForm()  #
        form = RegistrationForm()
        context["registration_form"] = form
        context["login_form"] = login_form

    return render(request, "index.html", context)
Ejemplo n.º 20
0
def login_view(request):
    context = {}

    user=request.user
    if user.is_authenticated:
        return redirect("home")

    if request.POST:
        form=AccountAuthenticationForm(request.POST)
        if form.is_valid():
            username=request.POST["username"]
            password=request.POST["password"]
            user=authenticate(username=username, password=password)

            if user:
                login(request, user)
                return redirect("home")
    else:
        form = AccountAuthenticationForm()

    context["login_form"]=form
    return render(request, "account/login.html", context)
Ejemplo n.º 21
0
def login_view(request):
    context = {}

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

            login(request, user)
            if user.is_authenticated:
                return redirect('core_articles')
        else:
            context['login_form'] = form

    else:
        form = AccountAuthenticationForm()
        context['login_form'] = form

    return render(request, 'login.html', context)
Ejemplo n.º 22
0
def login_view(request):
    '''
    View used to login users.
    '''
    user = request.user
    if request.POST:
        login_form = AccountAuthenticationForm(request.POST)
        if login_form.is_valid():
            email = request.POST['email']
            password = request.POST['password']
            user = authenticate(email=email, password=password)

            if user:
                login(request, user)
                messages.success(request, "You have successfully logged in")
                #Functions to check leave allowance, ah submission and leave submissions placed here.
                return redirect("home_page")

    else:
        login_form = AccountAuthenticationForm()

    args = {'login_form': login_form}
    return render(request, "login_page.html", args)
Ejemplo n.º 23
0
def login_view(request):
    #General Login screen
    context = {}
    user = request.user
    #Redirect logged in users to home
    if user.is_authenticated:
        return redirect('home')

    #POST request recieved and logging the user in    
    if request.POST:
        form = AccountAuthenticationForm(request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)

            if user:
                login(request, user)
                return redirect('home')
    else:
        form = AccountAuthenticationForm()
    context['login_form'] = form
    return render(request, 'accounts/login.html', context)
Ejemplo n.º 24
0
def login_view(request):
    context = {}

    user = request.user
    if user.is_authenticated:
        return redirect('core:home')
    if request.POST:
        form = AccountAuthenticationForm(request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            try:
                user = authenticate(
                    username=Account.objects.get(email=username),
                    password=password)
            except:
                user = authenticate(username=username, password=password)
            if user:
                login(request, user)
                return redirect('core:home')
    else:
        form = AccountAuthenticationForm()
    context['login_form'] = form
    return render(request, 'login.html', context)
Ejemplo n.º 25
0
def login_student(request):

    context = {}
    # user = request.user
    # if user.is_authenticated:
    # return redirect('index')

    if request.POST:
        form = StudentForm(request.POST)
        if form.is_valid():
            email = request.POST['email']
            # is_student = request.POST['is_student']
            password = request.POST['password']
            user = authenticate(email=email, password=password)

            if user:
                login(request, user)
                return redirect('index')
    else:
        form = AccountAuthenticationForm()

    context['login_form'] = form
    # form.add_error(None, 'you dont have student ID')
    return render(request, 'account/login.html', context)
Ejemplo n.º 26
0
 def test_form_validation_for_blank_items(self):
     form = AccountAuthenticationForm(data={'password': ''})
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['password'], ["no debe estar vacio"])
Ejemplo n.º 27
0
 def get(self, request):
     context = {}
     context['signin_form'] = AccountAuthenticationForm()
     return render(request, 'signin.html', context)