Example #1
0
def index():
    if login.current_user.is_authenticated():
        return login.redirect('/dashboard')

    # Create the forms
    sign_up_form = forms.SignUpForm()
    sign_in_form = forms.SignInForm()

    if flask.request.method == 'POST' and sign_up_form.validate_on_submit():
        new_user = models.User(
           first_name=sign_up_form.first_name.data,
           last_name=sign_up_form.last_name.data,
           email=sign_up_form.email.data,
           password=bcrypt.generate_password_hash(sign_up_form.password.data),
        )

        db.session.add(new_user)
        db.session.commit()

        return flask.redirect(flask.url_for('dashboard'))

    if flask.request.method == 'POST' and sign_in_form.validate_on_submit():
        user = models.User.query.filter(
            models.User.email == sign_in_form.user_email.data).first()
        login.login_user(user)
        if (bcrypt.check_password_hash(user.password,
                sign_in_form.user_password.data)):
            return flask.redirect(flask.url_for('dashboard'))

    return flask.render_template('home.epy', sign_up_form=sign_up_form,
        sign_in_form=sign_in_form, user=login.current_user)
Example #2
0
def posts(id=None):
    sign_up_form = forms.SignUpForm()
    sign_in_form = forms.SignInForm()

    if sign_up_form.validate_on_submit():
        handle_signup(sign_up_form)

    elif sign_in_form.validate_on_submit():
        handle_signin(sign_in_form)

    if id == None:
        posts = models.Post.select().limit(100)
        return render_template('posts.html', posts=posts)
    else:
        post_id = int(id)
        post = models.Post.get(models.Post.id == post_id)
        comments = post.comments
        form = forms.CommentForm()
        if form.validate_on_submit():
            models.Comment.create(user=g.user._get_current_object(),
                                  commentText=form.commentText.data,
                                  post=post)

            return redirect("/posts/{}".format(post_id))

        return render_template('post.html',
                               post=post,
                               form=form,
                               comments=comments,
                               sign_in_form=sign_in_form,
                               sign_up_form=sign_up_form)
Example #3
0
def user(usuario):  #Index de URL
    formulario = forms.SignInForm(request.form)  #Instanciamos el formulario
    datos = coleccion.find({'email': usuario})
    lista = []  #Creamos una lista para llenar conlos datos del alumno
    for i in datos:  #Llenamos la lista con los datos del alumno
        lista.append(i['username'])
        lista.append(i['nombres'])
        lista.append(i['apellidos'])
        lista.append(i['email'])
        lista.append(i['tipo'])
        lista.append(i['CursosInscritos'])
    listainscritos = [
    ]  #Creamos una lista con los cursos en los que esta inscrito.
    for i in lista[5]:
        cursodb = db.Cursos.find({'id_curso': i})
        for j in cursodb:
            listainscritos.append(
                j['nombre'])  #Agregamos los elementos a la lista
    if lista[4] == 'M':
        return redirect('maestro/' + usuario)
    if request.method == 'POST':  #Si se envian datos
        if request.form[
                'submit_button'] == '+':  #Si se pide que se agregue uno mas
            return redirect('buscar/' + usuario)
        elif request.form[
                'submit_button'] == 'Guardar':  #Si se pide que se agregue el boton Guardar
            User.actualizar(formulario.username.data, formulario.nombres.data,
                            formulario.apellidos.data, formulario.clave.data,
                            usuario)
            return redirect('user/' + usuario)
        elif request.form['submit_button'] == "Loggedout":  #Si se pide salir
            return redirect('')  #Redireccionamos a index
        elif request.form[
                'submit_button'] == "Mis Cursos":  #Si se pide ver Mis Cursos
            return redirect('user/' + usuario)
        elif request.form['submit_button'] == "Perfil":  #Si se pide ver perfil
            return redirect('user/' + usuario)
        for t in listainscritos:
            if request.form['submit_button'] == t:  #Para ver Uusuarios
                return redirect('curso/' + t + '/' + usuario)
    elif request.method == 'GET':
        return render_template('user.html',
                               username=lista[0],
                               nombre=lista[1],
                               apellidos=lista[2],
                               email=lista[3],
                               tipo=lista[4],
                               CursosInscritos=listainscritos,
                               formulario=formulario)
Example #4
0
def signin():
    form = forms.SignInForm(request.form)
    if current_user.is_authenticated:
        logout()
        return render_template('signin.html', title='Sing In', form=form)
    if request.method == 'POST':
        if form.validate():
            user = User.query.filter(
                User.username == form.username.data.lower()).first()
            login_user(user, remember=form.remember.data)
            flash('Hello again, ' + current_user.username)
            return redirect('/')
        else:
            flash('Wrong username or password.')
    return render_template('signin.html', title='Sign In', form=form)
Example #5
0
def index():
    log_in_form = forms.SignInForm()
    sign_up_form = forms.SignUpForm()
    parkings = models.Parking.select()

    if sign_up_form.validate_on_submit():
        handle_signup(sign_up_form)

    elif log_in_form.validate_on_submit():
        handle_login(log_in_form)

    return render_template('auth.html',
                           sign_up_form=sign_up_form,
                           log_in_form=log_in_form,
                           parkings=parkings)
Example #6
0
def login():
    """Link and form for login"""
    form = forms.SignInForm()
    if form.validate_on_submit():
        try:
            user = models.User.get(models.User.email == form.email.data)
            if check_password_hash(user.password, form.password.data):
                login_user(user)
                flash("You're now logged in!")
                return redirect(url_for('index'))
            else:
                flash("No user with that email/password combo")
        except models.DoesNotExist:
            flash("No user with that email/password combo")
    return render_template('login.html', form=form)
Example #7
0
def index():
    neighborhoods = models.Neighbor.select()
    sign_up_form = forms.SignUpForm()
    sign_in_form = forms.SignInForm()

    if sign_up_form.validate_on_submit():
        handle_signup(sign_up_form)

    elif sign_in_form.validate_on_submit():
        handle_signin(sign_in_form)

    return render_template('auth.html',
                           neighborhoods=neighborhoods,
                           sign_up_form=sign_up_form,
                           sign_in_form=sign_in_form)
Example #8
0
def signin():
    form = forms.SignInForm()
    if form.validate_on_submit():
        try:
            user = models.User.get(models.User.email == form.email.data)
        except models.DoesNotExist:
            flash('Error. Password or email is incorrect',
                  'alert alert-danger')
        else:
            if check_password_hash(user.password, form.password.data):
                login_user(user)  #session created
                flash('Sign in success!', 'success')
                return redirect(url_for('profile'))
            else:
                flash('Error, Password or email is incorrect',
                      'alert alert-danger')
    return render_template('signin.html', form=form)
Example #9
0
def neighborpage(neighborid):
    sign_in_form = forms.SignInForm()
    sign_up_form = forms.SignUpForm()
    neighbor_model = models.Neighbor.get_by_id(int(neighborid))
    posts = models.Post.select().where(
        models.Post.neighbor_id == int(neighborid))

    if sign_up_form.validate_on_submit():
        handle_signup(sign_up_form)

    elif sign_in_form.validate_on_submit():
        handle_signin(sign_in_form)

    form = forms.PostForm()
    if form.validate_on_submit():
        models.Post.create(user=g.user._get_current_object(),
                           title=form.title.data,
                           text=form.text.data,
                           address=form.address.data,
                           imgUrl=form.imgUrl.data,
                           category=form.category.data,
                           neighbor=neighbor_model)
        return redirect("/{}".format(neighborid))

    return render_template('posts.html',
                           neighbor=neighbor_model,
                           sign_in_form=sign_in_form,
                           sign_up_form=sign_up_form,
                           posts=posts,
                           form=form,
                           post={
                               "title": "",
                               "text": "",
                               "address": "",
                               "imgUrl": "",
                               "category": ""
                           })
Example #10
0
def index():  #Index de URLS
    formulario = forms.SignInForm(
        request.form)  #Instanciamos los tres formularios
    formlogin = forms.LoginForm(request.form)
    comentario = forms.Contacto(request.form)
    userdb = {}
    if request.method == 'POST' and comentario.submit.data and comentario.validate(
    ):  #Evaluamos si el formulario de comentario tiene datos
        diccionario = {}
        diccionario['email'] = comentario.email.data
        diccionario['nombre'] = comentario.nombre.data
        diccionario['comentario'] = comentario.mensaje.data
        db.Comentarios.insert(diccionario)  #Insertamos los comentarios
    if request.method == 'POST' and formlogin.submit1.data and formlogin.validate(
    ):
        userdb = coleccion.find({'email': formlogin.email.data
                                 })  #Buscamos los datos del usuario
        lista = []
        acceso = False
        try:
            for ir in userdb:
                lista.append(ir['email'])
                lista.append(ir['clave'])
                if lista[1] == formlogin.clave.data:
                    acceso = True
        except:  #Programacion defensiva
            flash('La contraseña no coincide con el Email')
        try:  #buscamos el primer elemento.
            lista[0]
        except:  #Programamos defensivamente
            flash('Este email no ha sido registrado')
        if acceso == True:
            i = lista[0]
            return redirect('user/' + i)
    if request.method == 'POST' and formulario.submit2.data and formulario.validate(
    ):  #Evaluamos si el formulario esta enviando datos
        userdb = coleccion.find({
            'email': formulario.email.data
        })  #Que cuente la cantidad que cumpla con el parametro
        lista = []
        acceso = False
        try:
            for ir in userdb:
                lista.append(ir['email'])
                flash('Este email ya esta registrado')
        except:
            acceso = True
        if len(lista) == 0:
            acceso = True
        if acceso == True:
            if formulario.tipo.data == 'A':  #Si es de tipo alumno
                #Instanciamos a una clase tipo Usuario Alumno
                user = Alumno(formulario.username.data,
                              formulario.nombres.data,
                              formulario.apellidos.data, formulario.email.data,
                              formulario.clave.data, formulario.tipo.data)
            elif formulario.tipo.data == 'M':  #Si es de tipo maestro
                #Instanciamos a una clase tipo Usuario Maestro
                user = Maestro(formulario.username.data,
                               formulario.nombres.data,
                               formulario.apellidos.data,
                               formulario.email.data, formulario.clave.data,
                               formulario.tipo.data)
            flash('Gracias por Registrarte')  #Agradecemos por el registro
            i = formulario.email.data
            return redirect('user/' + i)
    return render_template('Home.html',
                           form=formulario,
                           formLogin=formlogin,
                           comentario=comentario)  #Llamamos nuestro diseño
Example #11
0
def maestro(usuario):  #Index de URL
    formulario = forms.SignInForm(request.form)  #Instanciamos los formularios
    crear = forms.CrearCurso(request.form)
    datos = coleccion.find({'email': usuario})
    lista = []
    for i in datos:  #Recogemos los dato del usuario
        lista.append(i['username'])
        lista.append(i['nombres'])
        lista.append(i['apellidos'])
        lista.append(i['email'])
        lista.append(i['tipo'])
        lista.append(i['CursosInscritos'])
        lista.append(i['CursosAdministrados'])
    listcursos = []  #Recogemos los datos de los cursos
    for i in lista[6]:
        cursodb = db.Cursos.find({'id_curso': i})
        for j in cursodb:
            listcursos.append(j['nombre'])
    listainscritos = []
    for i in lista[5]:
        cursodb = db.Cursos.find({'id_curso': i})
        for j in cursodb:
            listainscritos.append(j['nombre'])
    if request.method == 'POST':
        if request.form['submit_button'] == '+':  #Interactuamos con el usuario
            return redirect('buscar/' + usuario)
        elif request.form['submit_button'] == 'Crear':
            return redirect('nuevocurso/' + crear.palabra.data + '/' + usuario)
        elif request.form['submit_button'] == 'Guardar':
            User.actualizar(formulario.username.data, formulario.nombres.data,
                            formulario.apellidos.data, formulario.clave.data,
                            usuario)
            return redirect('maestro/' + usuario)
        elif request.form['submit_button'] == "Loggedout":
            return redirect('')
        elif request.form['submit_button'] == "Mis Cursos":
            return redirect('user/' + usuario)
        elif request.form['submit_button'] == "Perfil":
            return redirect('user/' + usuario)
        for t in listcursos:
            if request.form['submit_button'] == t:
                return redirect('curso/' + t + '/' + usuario)
    elif request.method == 'GET':
        return render_template('maestro.html',
                               username=lista[0],
                               nombre=lista[1],
                               apellidos=lista[2],
                               email=lista[3],
                               tipo=lista[4],
                               CursosInscritos=listainscritos,
                               CursosAdministrados=listcursos,
                               crear=crear,
                               formulario=formulario)
    return render_template('maestro.html',
                           username=lista[0],
                           nombre=lista[1],
                           apellidos=lista[2],
                           email=lista[3],
                           tipo=lista[4],
                           CursosInscritos=listainscritos,
                           CursosAdministrados=listcursos,
                           crear=crear,
                           formulario=formulario)