Ejemplo n.º 1
0
def user_registration(request):
    form_personal_info = registration_form.UserRegistrar(request.POST or None)

    context = {
        'form_user_personal_information': form_personal_info,
        'registration_page': True
    }

    if form_personal_info.is_valid():
        user = user_model.User()

        user.email = form_personal_info.cleaned_data['email']
        user.first_name = form_personal_info.cleaned_data['first_name']
        user.last_name = form_personal_info.cleaned_data['last_name']
        user.password = form_personal_info.cleaned_data['password']

        registered = user_model.User.objects.filter(email=user.email)

        # check if there is an existent user with the email entered by the user trying to register
        if len(registered) > 0:
            error = 'User already registered.'
            context['error'] = error

        else:
            # store the user in the db
            user.save()

            return __login_open_session(request, user.email)

    return render(request, 'registration.html', context)
Ejemplo n.º 2
0
def user_login(request):
    form = login_form.UserLogger(request.POST or None)

    context = {
        'login_form': form,
        'login_page': True,

    }

    if form.is_valid():
        # verify if user with the entered email and password exists
        user = models.User.objects.filter(email=form.cleaned_data['email'], password=form.cleaned_data['password'])


        if not user:
            # if not, store the error message in the context
            error = 'Invalid email or password. Please try again.'
            context['error'] = error

        else:
            return __login_open_session(request, form.cleaned_data['email'])

    return render(request, 'home.html', context)


# end user_login


# end __is_session_open