Esempio n. 1
0
def guest_user(request):
    context = dict()
    context['welcome_header'] = settings.WELCOME_HEADER
    context['main_page'] = settings.MAIN_PAGE
    context['page_title'] = _(u"Guest User Page")
    form = GuestUserForm()
    if request.method == "POST":
        form = GuestUserForm(request.POST)
        if form.is_valid():
            name = request.POST['name']
            middle_name = request.POST['middle_name']
            surname = request.POST['surname']
            guest_user_email = request.POST['guest_user_email']
            email = request.POST['email']
            guest_user_phone = request.POST['guest_user_phone']
            surname = upper_function(surname)
            name = upper_function(name)
            middle_name = upper_function(middle_name)
            type = request.POST['type']
            time_duration = request.POST['time_duration']
            citizen_no = request.POST['citizen_no']
            ldap_handler = LdapHandler()
            bind_status = False
            if ldap_handler.connect():
                bind_status = ldap_handler.bind()
            if bind_status:
                if ldap_handler.search(
                        guest_user_email
                ) == 1:  # eger kayıt olmak isteyen misafir zaten ldap'ta kayıtllıysa
                    ldap_handler.unbind()
                    context['form'] = form
                    context['web'] = "guest_user"
                    context['page_title'] = _(u"Guest User Application")
                    context['info'] = "guest_user_already_exist"
                    context['email'] = guest_user_email
                    return render_to_response("main/info.html",
                                              context_instance=RequestContext(
                                                  request, context))
                url = generate_url_id()
                url_obj = Url.objects.create(url_id=url)
                guest_user_obj = GuestUser.objects.create(
                    name=name,
                    middle_name=middle_name,
                    surname=surname,
                    email=email,
                    guest_user_email=guest_user_email,
                    url=url_obj,
                    guest_user_phone=guest_user_phone,
                    type=type,
                    time_duration=time_duration,
                    citizen_no=citizen_no)
                # kullanıcının son geçerlilik süresi yazılıyor
                now = datetime.datetime.now()
                guest_user_obj.application_time = now
                application_time = guest_user_obj.application_time
                time_duration = int(guest_user_obj.time_duration)
                deadline_time = now
                if int(guest_user_obj.type) == 1:  # SAAT
                    deadline_time = application_time + datetime.timedelta(
                        hours=time_duration)
                if int(guest_user_obj.type) == 2:  # GUN
                    deadline_time = application_time + datetime.timedelta(
                        days=time_duration)
                if int(guest_user_obj.type) == 3:  # HAFTA
                    deadline_time = application_time + datetime.timedelta(
                        weeks=time_duration)

                guest_user_obj.deadline_time = deadline_time
                guest_user_obj.save()

                send_guest_user_confirm(
                    guest_user_obj
                )  # misafir kullanıcıya ev sahibi kullanıcıya mail atıldıgının bildirilmesi
                context['form'] = form
                context['web'] = "guest_user"
                context['info'] = 'guest_mail_confirm'
                context['host_email'] = email
                context['email'] = guest_user_email
                return render_to_response("main/info.html",
                                          context_instance=RequestContext(
                                              request, context))
        else:
            context['form'] = form
            context['web'] = "guest_user"
            return render_to_response("guest_user/guest_user.html",
                                      context_instance=RequestContext(
                                          request, context))
    else:
        context['form'] = form
        context['web'] = "guest_user"
        return render_to_response("guest_user/guest_user.html",
                                  context_instance=RequestContext(
                                      request, context))