예제 #1
0
def index(request):
    register_form = RegisterForm(request.POST)
    if register_form.is_valid():
        register_form.save()

    ruta = str(pathlib.Path().absolute()) + '/log.txt'
    archivo = open(ruta, "a+")
    now = datetime.now()
    datosdb = CreateRss.objects.filter(public=True)
    respuestadata = {}
    for i in range(len(datosdb)):
        con = 0
        while True:
            try:
                respuesta = feedparser.parse(datosdb[i].url)
                print(respuesta['feed']['title'])
                datosdb[i].respuesta = respuesta.entries
                datosdb[i].isError = False
                error = ""
                break
            except Exception as e:
                archivo.write("** A ocurrido un error: " + type(e).__name__ +
                              " " + str(now) + "\n")
                con = con + 1
                error = "A ocurrido un error al cargrar el feed"
                datosdb[i].isError = True
                datosdb[i].error = error
                if con >= 3:
                    break

    return render(request, 'index.html', {
        'register_form': register_form,
        'datos': datosdb,
        'error': error
    })
예제 #2
0
def edituser(request, id):
    edituser = User.objects.get(id=id)
    editprofile = Profile.objects.get(user=edituser)
    if request.method == 'POST':
        editform = RegisterForm(request.POST)
        if editform.is_valid():
            edituser.email = editform.cleaned_data['email']
            edituser.password = editform.cleaned_data['password']
            edituser.firstname = editform.cleaned_data['firstname']
            edituser.lastname = editform.cleaned_data['lastname']
            edituser.save()

            editprofile.gender = editform.cleaned_data['gender']
            editprofile.address = editform.cleaned_data['address']
            editprofile.phone = editform.cleaned_data['phone']
            editprofile.save()
            return HttpResponseRedirect('/listuser')
    else:
        editform = RegisterForm(
            initial={
                'email': edituser.email,
                'password': edituser.password,
                'firstname': edituser.firstname,
                'lastname': edituser.lastname,
                'gender': editprofile.gender,
                'address': editprofile.address,
                'phone': editprofile.phone
            })
    return render(request, 'edituser.html', {'editform': editform})
예제 #3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegisterForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data)
        user = User(username=form.username.data, email=form.email.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        login_user(user, remember=form.remember.data)
        next_page = request.args.get('next')
        #flash(f'Logged In', 'success')
        return redirect(next_page) if next_page else redirect(url_for('home'))
        flash(f'Account Created for {form.username.data}!', 'success')
        return redirect(url_for('home'))
    return render_template('register.html', title='register', form=form)
예제 #4
0
def register_page(request):

    # validacion de la pagina de registro
    if request.user.is_authenticated:
        return redirect('inicio')

    else:

        # formulario original django
        #----register_form = UserCreationForm()
        # desabilitado el formulario original para utilizar
        # un nuevo formulario personalizado
        register_form = RegisterForm()

        if request.method == 'POST':
            register_form = RegisterForm(request.POST)

            if register_form.is_valid():
                register_form.save()
                messages.success(request, 'Registrado con éxito')

                return redirect('inicio')

        return render(request, 'users/register.html', {
            'title': 'Registro',
            'register_form': register_form
        })
예제 #5
0
def adduser(request):
    if request.method == 'POST':
        regisform = RegisterForm(request.POST)
        if regisform.is_valid():
            user, status = User.objects.get_or_create(
                email=regisform.cleaned_data['email'],
                password=regisform.cleaned_data['password'],
                firstname=regisform.cleaned_data['firstname'],
                lastname=regisform.cleaned_data['lastname'],
            )
            profile, status = Profile.objects.get_or_create(
                user=user,
                gender=regisform.cleaned_data['gender'],
                address=regisform.cleaned_data['address'],
                phone=regisform.cleaned_data['phone'])
            return HttpResponseRedirect('/listuser')
    else:
        regisform = RegisterForm()
    return render(request, 'register.html', {'regisform': regisform})
예제 #6
0
def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('/')
    else:
        form = RegisterForm()
    return render(request, 'registration/register.html', {'form': form})
예제 #7
0
def register_page(request):
    register_form = RegisterForm()

    if request.method == 'POST':
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            register_form.save()
            messages.success(request, 'Te has registrado correctamente!')
            return redirect('index')
    return render(request, 'users/register.html', {
        'title': 'Registro',
        'register_form': register_form
    })
예제 #8
0
def register_user(request):

    if request.user.is_authenticated:
        return redirect('index')
    else:
        register_form = RegisterForm()

        if request.method == 'POST':
            register_form = RegisterForm(request.POST)

            if register_form.is_valid():
                register_form.save()
                messages.success(request, 'Registro completo')
                return redirect('index')

        values = {'title': 'registro', 'register_form': register_form}
        return render(request, 'users/register.html', values)
예제 #9
0
파일: views.py 프로젝트: jonanv/blog_django
def register_page(request):
    if request.user.is_authenticated:
        return redirect('home')
    else:
        register_form = RegisterForm()

        if request.method == 'POST':
            register_form = RegisterForm(request.POST)

            if register_form.is_valid:
                register_form.save()
                messages.success(request,
                                 'Te has registrado satisfactoriamente')
                return redirect('home')
            else:
                register_form = RegisterForm()

        return render(request, 'users/register.html', {
            'title': 'Registro',
            'register_form': register_form
        })
예제 #10
0
def register_user(request):

    if request.user.is_authenticated:
        return redirect('inicio')
    else:
        register_form = RegisterForm()

        if request.method == 'POST':
            register_form = RegisterForm(request.POST)

            if register_form.is_valid():
                register_form.save()
                messages.success(request, 'Te has registrado correctamente')

                return redirect('articles')

        return render(request, 'mainapp/register.html',
                      {'register_form': register_form})
예제 #11
0
def register_page(request):

    register_form = RegisterForm()

    if request.method == "POST":
        register_form = RegisterForm(request.POST)

        if register_form.is_valid():
            register_form.save()
            messages.success(
                request,
                "Te has registrado correctamente",
            )

            return redirect("inicio")

    return render(request, "users/register.html", {
        "title": "Registro",
        "register_form": register_form
    })
예제 #12
0
파일: views.py 프로젝트: colidom/cursos
def register_page(request):

    if request.user.is_authenticated:
        return redirect('/inicio')
    else:
        register_form = RegisterForm()

        if request.method == 'POST':
            register_form = RegisterForm(request.POST)

            if register_form.is_valid():
                register_form.save()
                messages.success(request, 'Te has registrado correctamente😋')

                return redirect('/inicio')

        return render(request, 'users/register.html', {
            'title': 'Registro',
            'register_form': register_form
        })
예제 #13
0
def register_page(request):
    # Si queremos usar el formulario de registro que trae django por defecto
    #register_form = UserCreationForm()

    if request.user.is_authenticated:
        return redirect('index')
    else:
        register_form = RegisterForm()
        
        #miramos si nos llega el metodo post
        if request.method == 'POST':
            #si llega post el formulario se esta enviado correctamente, en caso de que el formulario no sea valido, el formulario se rellena automaticamente
            #register_form = UserCreationForm(request.POST)

            register_form = RegisterForm(request.POST)

            #si el formulario es valido, guardamos el formulario
            if register_form.is_valid():
                register_form.save()

                #Si todo va bien mostramos mensaje 
                messages.success(request, 'Te has registrado correctamente')

                #si todo va bien redirec a inicio
                # para la password hay que tener en cuenta que:
                # Su contraseña no puede asemejarse tanto a su otra información personal.
                # Su contraseña debe contener al menos 8 caracteres.
                # Su contraseña no puede ser una clave utilizada comúnmente.
                # Su contraseña no puede ser completamente numérica.
                #si no, no da error pero tampoco guarda al usuario
                return redirect('index')


    return render(request, 'users/register.html', 
    {
        'title': 'Registro',
        'register_form': register_form,
    })
예제 #14
0
def register_page(request):
    if request.user.is_authenticated: #si esta autenticado no debe mostrar el registro redirecciona a inicio

        return redirect("inicio")

    else:
        #register_form = UserCreationForm() #instanciar la clase de creacion de formulario por defecto de django
        register_form = RegisterForm() #intanciar formulario prsonalzado (forms.py)

        if request.method == 'POST':
            #register_form = UserCreationForm(request.POST) #si se ha enviado algo se guardara 
            register_form = RegisterForm(request.POST)

            if register_form.is_valid():
                register_form.save()
                messages.success(request, 'Te has registrado correctamente') #crear mensaje flash

                return redirect('inicio')

        return render(request, 'users/register.html', {
            'title': 'Registro',
            'register_form': register_form
        })