Exemplo n.º 1
0
def login_page():
    """User login page."""
    # Bypass Login screen if user is logged in
    if current_user.is_authenticated:
        return redirect(url_for('main_bp.chat'))
    login_form = LoginForm(request.form)
    # POST: Create user and redirect them to the app
    if request.method == 'POST':
        if login_form.validate():
            # Get Form Fields
            email = request.form.get('email')
            password = request.form.get('password')
            # Validate Login Attempt
            user = User.query.filter_by(email=email).first()
            if user:
                if user.check_password(password=password):
                    login_user(user)
                    next = request.args.get('next')
                    return redirect(next or url_for('main_bp.chat'))
        flash('Invalid username/password combination')
        return redirect(url_for('auth_bp.login_page'))
    # GET: Serve Log-in page
    return render_template('login.html',
                           form=LoginForm(),
                           title='NinerChat | Log in',
                           template='login-page',
                           body="Log in with your User account.")
Exemplo n.º 2
0
def login():

    form = LoginForm(request.form)

    # POST
    if request.method == 'POST':

        if not form.validate():
            return render_template('login.html',
                                   form=form,
                                   message='Введены некорректные данные')

        login = form.login.data
        password = form.password.data
        remember_me = form.remember_me.data

        result = get_user_info(login, password)

        if result is not False and result is not None:
            session.permanent = remember_me
            session['login'] = login
            session['password'] = password
            return redirect('/')
        return render_template(
            'login.html',
            title="Вход",
            form=form,
            message='Вход не удался. Возможно введены неверные данные')

    # GET
    if auth():
        return redirect('/')
    return render_template('login.html', title="Вход", form=form)
Exemplo n.º 3
0
def login():

    form = LoginForm(request.form)

    # POST
    if request.method == "POST":

        if not form.validate():
            return render_template("login.html", form=form, message="Введены некорректные данные")

        login = form.login.data
        password = form.password.data
        remember_me = form.remember_me.data

        result = get_user_info(login, password)

        if result is not False and result is not None:
            session.permanent = remember_me
            session["login"] = login
            session["password"] = password
            return redirect("/")
        return render_template(
            "login.html", title="Вход", form=form, message="Вход не удался. Возможно введены неверные данные"
        )

    # GET
    if auth():
        return redirect("/")
    return render_template("login.html", title="Вход", form=form)
Exemplo n.º 4
0
def entrar():
    form = LoginForm(request.form)
    if request.method == "POST" and form.validate():
        print("passou")
        try:
            prevrows = User.query.filter_by(email=form.email.data).one()
            rows = Auth.query.filter_by(user_id=prevrows.id).one()
        except:
            try:
                rows = Auth.query.filter_by(username=form.email.data).one()
            except:
                return render_template("entrar.html",
                                       message="email/usuário inexistente",
                                       dest=request.args.get("dest"))
        # ensure username exists and password is correct
        if not pwd_context.verify(form.senha.data, rows.passwordhsh):
            return render_template("entrar.html",
                                   message="email/usuário ou senha incorretos",
                                   dest=request.args.get("dest"))
        session["user_id"] = rows.user_id
        session["user_name"] = rows.username.upper()
        session["tempeduc"] = []
        session["tempcert"] = []
        session["tempexp"] = []
        db.session.commit()
        try:
            return redirect(url_for(request.args.get("dest")))
        except:
            return redirect(url_for('index'))

    else:
        state = ''.join(
            random.choice(string.ascii_uppercase + string.digits)
            for x in range(32))
        session['state'] = state
        try:
            teste = session["user_id"]
            return redirect(url_for('encontre'))
        except:
            return render_template("entrar.html",
                                   STATE=state,
                                   dest=request.args.get("dest"),
                                   form=form)
Exemplo n.º 5
0
def login():
    # Here we use a class of some kind to represent and validate our
    # client-side form data. For example, WTForms is a library that will
    # handle this for us, and we use a custom LoginForm to validate.
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        # Login and validate the user.
        # user should be an instance of your `User` class
        user = load_user(form.username.data)
        if (user is not None):
            m = hashlib.md5()
            m.update('form.password.data')
            print m.hexdigest()
            if user.id == form.username.data and \
                            user.password == m.hexdigest():
                login_user(user)
                flash('Logged in successfully.')
                return redirect(url_for('index'))
            else:
                flash('Login or password are incorrect')
    return render_template('login.html', form=form)
Exemplo n.º 6
0
def login():
    form = LoginForm(request.form)
    if form.validate():
        return jsonify(type='success',msg='Ingreso exitoso!')
    return jsonify(type='error',msg='Error en el login!')