示例#1
0
def login():
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            paas = bcrypt.check_password_hash(user.password,
                                              form.password.data)
            print(paas)
            session['email'] = form.email.data
            flash('Login berhasil', 'success')
            return redirect(request.args.get('next') or url_for('admin'))
        else:
            flash('Password salah, coba lagi!', 'danger')
    return render_template('admin/login.html', form=form, title="Login page")
示例#2
0
def tournaments():
    products = Addproduct.query.filter(Addproduct.stock > 0).order_by(Addproduct.id.desc())
    product = Addproduct.query.get_or_404(6)
    p_id = 3
    filterd_resultr=Addproduct.query.filter_by(id=p_id).first()
    allresult = Addproduct.query.all()

        #Customer Login Logic 
    form = CustomerLoginFrom()
    if form.validate_on_submit():
        user = Register.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user)
            flash('You are login now!', 'success')
            next = request.args.get('next')
            return redirect(next or url_for('store'))
        flash('Incorrect email and password','danger')
        return redirect(url_for('store'))

    #Customer Register Logic
    form_R = CustomerRegisterForm()
    if form.validate_on_submit():
        hash_password = bcrypt.generate_password_hash(form.password.data)
        register = Register(name=form.name.data, username=form.username.data, email=form.email.data,password=hash_password,country=form.country.data, city=form.city.data,contact=form.contact.data, address=form.address.data, zipcode=form.zipcode.data)
        db.session.add(register)
        flash(f'Welcome {form.name.data} Thank you for registering', 'success')
        db.session.commit()
        return redirect(url_for('store'))  

        
    return render_template('tournaments.html' ,products=products, product=product, allresult=allresult, filterd_resultr=filterd_resultr, form=form, form_R=form_R )
示例#3
0
def get_Discount():
    page = request.args.get('page',1, type=int)
    products = Addproduct.query.filter(Addproduct.stock > 0, Addproduct.discount).order_by(Addproduct.id.desc()).paginate(page=page, per_page=16)
    product = Addproduct.query.get_or_404(1)

    p_id = "1"
    filterd_resultr=Addproduct.query.filter_by(id=p_id).first()
    product = Addproduct.query.get_or_404(1)
    vi_product=filterd_resultr

    #Customer Login Logic 
    form = CustomerLoginFrom()
    if form.validate_on_submit():
        user = Register.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user)
            flash('You are login now!', 'success')
            next = request.args.get('next')
            return redirect(next or url_for('store'))
        flash('Incorrect email and password','danger')
        return redirect(url_for('store'))

    #Customer Register Logic
    form_R = CustomerRegisterForm()
    if form.validate_on_submit():
        hash_password = bcrypt.generate_password_hash(form.password.data)
        register = Register(name=form.name.data, username=form.username.data, email=form.email.data,password=hash_password,country=form.country.data, city=form.city.data,contact=form.contact.data, address=form.address.data, zipcode=form.zipcode.data)
        db.session.add(register)
        flash(f'Welcome {form.name.data} Thank you for registering', 'success')
        db.session.commit()
        return redirect(url_for('store'))  

    return render_template('store.html', title='layout', grandtotal=grandtotal(), products=products, brands=brands(), product=product, filterd_resultr=filterd_resultr, vi_product=vi_product, categories=categories(), form_R=form_R, form=form)
示例#4
0
 def authenticate(cls, username, password):
     found_user = cls.query.filter_by(username=username).first()
     if found_user:
         authenticated_user = bcrypt.check_password_hash(
             found_user.password, password)
         if authenticated_user:
             return found_user
     return False
示例#5
0
def customer_login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = CustomerLoginFrom()
    if form.validate_on_submit():
        # Register.query.filter_by(lock=False).first()
        user = Register.query.filter_by(username=form.username.data).first()
        if user and bcrypt.check_password_hash(
                user.password, form.password.data.encode('utf8')):
            if user.lock == True:
                flash(
                    Markup(
                        "Account has been locked ! <a href='mailto: [email protected]' class='alert-link' >Help here</a>"
                    ), 'danger')
                return redirect(url_for('customer_login'))
            login_user(user)

            # Xu ly gio hang
            if 'Shoppingcart' in session:
                orders = CustomerOrder.query.filter(
                    CustomerOrder.customer_id == current_user.id).filter(
                        CustomerOrder.status == None).order_by(
                            CustomerOrder.id.desc()).all()
                product_id = [order.orders for order in orders]
                for key, item in session['Shoppingcart'].items():
                    if key not in product_id:
                        customer_id = current_user.id
                        invoice = secrets.token_hex(5)
                        order = CustomerOrder(
                            invoice=invoice,
                            customer_id=customer_id,
                            orders={key: session['Shoppingcart'][key]},
                            status=None)
                        db.session.add(order)
                        db.session.commit()
            session.pop('Shoppingcart', None)
            orders = CustomerOrder.query.filter(
                CustomerOrder.customer_id == current_user.id).filter(
                    CustomerOrder.status == None).order_by(
                        CustomerOrder.id.desc()).all()
            session.modified = True
            for order in orders:
                for product_id, DictItems in order.orders.items():
                    DictItems = {product_id: DictItems}
                    if 'Shoppingcart' not in session:
                        session['Shoppingcart'] = DictItems
                    else:
                        session['Shoppingcart'] = MagerDicts(
                            session['Shoppingcart'], DictItems)

            next = request.args.get('next')
            return redirect(next or url_for('home'))
        flash('Incorrect email and password', 'danger')
        return redirect(url_for('customer_login'))
    return render_template('customers/login.html',
                           form=form,
                           brands=brands(),
                           categories=categories())
示例#6
0
def login():
    form = LoginForm(request.form)
    if request.method == "POST" and form.validate():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            session['email'] = form.email.data
            flash(f'Welcome {form.email.data} You are logged in now', 'success')
            return redirect(request.args.get('next') or url_for('admin'))
        else:
            flash('Your password is wrong! Try again.', 'danger')
    return render_template('admin/login.html', form=form, title='Login Page')
示例#7
0
文件: routes.py 项目: arshupt/VegMart
def customerLogin():
    form = CustomerLoginForm()
    if form.validate_on_submit():
        user = Register.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user)
            next = request.args.get('next')
            return redirect(next or url_for('hom'))
        flash('Incorrect Email or Password', 'danger')
        return redirect(url_for('customerLogin'))
    return render_template('customer/login.html', form=form)
def login():
    form = LoginForm(request.form)
    if request.method == "POST" and form.validate():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            session["email"] = form.email.data
            flash(f"Welcome, {user.username}. You are now logged in.",
                  "success")
            return redirect(url_for("admin"))

    return render_template("admin/login.html", form=form, title="Log In")
示例#9
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            session['email'] = form.email.data
            flash(f'welcome {form.email.data} you are logedin now', 'success')
            return redirect(url_for('admin'))
        else:
            flash(f'Wrong email and password', 'success')
            return redirect(url_for('login'))
    return render_template('admin/login.html', title='Login page', form=form)
示例#10
0
def login():
    form = LoginForm(request.form)
    if request.method == "POST" and form.validate():
        admin = Admin.query.filter_by(email = form.email.data).first()
        if admin and bcrypt.check_password_hash(admin.password, form.password.data):
            session['email'] = form.email.data
            flash(f'Welcome Admin {form.email.data}', 'success')
            return redirect(url_for('admin'))
        else:
            flash('Wrong Password', 'danger')

    return render_template('admin/login.html', form=form, title='Login Page')
示例#11
0
def login():
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        user = User.query.filter_by(email= form.email.data).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            print("HOLA ")
            session['email'] = form.email.data
            flash(f'Bienvenido {form.email.data}, haz iniciado sesion', 'success')
            return redirect(request.args.get('next') or url_for('admin'))
        else:
            flash('Password incorrecta', 'danger')
    return render_template('admin/login.html', form=form, title='Iniciar Sesion')
示例#12
0
def customer_login():
    form = CustomerLoginForm()
    if form.validate_on_submit():
        user = Register.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user)
            flash(f'¡Bienvenido {form.email.data}!', 'success')
            next = request.args.get('next')
            return redirect(next or url_for('home', form=form))
        flash('contraseña o usuario incorrectos', 'danger')
        return redirect(url_for('customerLogin', form=form))

    return render_template('customer/login.html', form=form)
def login():
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        user = Admin.query.filter_by(email=form.email.data).first()
        password = form.password.data.encode('utf8')
        if user and bcrypt.check_password_hash(user.password, password):
            session['email'] = form.email.data
            flash(f'welcome {form.email.data} you are logedin now', 'success')
            return redirect(url_for('admin'))
        else:
            flash(f'Wrong email and password', 'danger')
            return redirect(url_for('login'))
    return render_template('admin/login.html', title='Login page', form=form)
示例#14
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            session['email'] = form.email.data
            flash(f'Добро пожаловать {form.email.data} !', 'success')
            return redirect(url_for('admin'))
        else:
            flash(f'Некоректные электронная почта или пароль', 'danger')
            return redirect(url_for('login'))
    return render_template('admin/login.html', title='Вход', form=form)
示例#15
0
文件: routes.py 项目: MrSpooner/Shop
def customerLogin():
    form = CustomerLoginFrom()
    if form.validate_on_submit():
        user = Register.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user)
            flash('Вы вошли', 'success')
            next = request.args.get('next')
            return redirect(next or url_for('home'))
        flash('Неправильно введены данные','danger')
        return redirect(url_for('customerLogin'))
            
    return render_template('customer/login.html', form=form)
示例#16
0
def customerLogin():
    form = CustomerLoginForm()
    if form.validate_on_submit():
        user = RegisterModel.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user)
            flash("Succesfully Logged in", 'success')
            next = request.args.get('next')
            return redirect(next or url_for('home'))
        flash("Incorrect email or password")
        return redirect(url_for('customerLogin'))
    return render_template('customers/login.html', form=form)
示例#17
0
def login():
    form = LoginForm(request.form)
    if request.method == "POST" and form.validate():
        user = User.query.filter_by(username=form.username.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            flash("yo logged biatch")
            session['username'] = form.username.data
            return redirect(request.args.get('next') or url_for('admin'))
        else:
            flash("wrong!")

    return render_template('admin/login.html', form=form, title="Login Page")
示例#18
0
def login():
    form = LoginForm(request.form)
    if request.method == "POST" and form.validate():
        user = Admin.query.filter_by(phno=form.phno.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            session['phno'] = form.phno.data
            flash(f'You have successfully logged in', 'success')
            return redirect(request.args.get('next') or url_for('billing'))
        else:
            flash('wrong password', 'danger ')
            return redirect(url_for('login'))
    return render_template('', form=form, title='Admin Access')
示例#19
0
文件: views.py 项目: jod35/shop
def login_page():
    form = LoginForm()
    email = request.form.get('email')
    password = request.form.get('password')
    user = Seller.query.filter_by(email=email).first()

    if user and bcrypt.check_password_hash(user.password, password):
        try:
            login_user(user)
            return redirect(url_for('index'))
        except:
            flash("Invalid Username or Password")
            return redirect(url_for('login_page'))
    return render_template('login.html', form=form)
示例#20
0
def customerlogin():
    form = LoginForm()
    if request.method == 'POST' and form.validate():
        user = Register.query.filter_by(username=form.username.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user)
            flash(f"You are now logged in", 'success')
            next = request.args.get('next')
            return redirect(next or url_for('brand.home'))

        flash(f'Incorrect password or username, try again', 'danger')

    return render_template('customer/login.html', form=form)
示例#21
0
def landing2():
    form = CustomerLoginFrom()
    if form.validate_on_submit():
        user = Register.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user)
            flash('You are login now!', 'success')
            next = request.args.get('next')
            return redirect(next or url_for('store'))
        flash('Incorrect email and password', 'danger')
        return redirect(url_for('customerLogin'))

    return render_template('landingtest.html', title='layout', form=form)
示例#22
0
def login():
    from shop.admin.models import Admin
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        admin = Admin.query.filter_by(email=form.email.data).first()
        if admin and bcrypt.check_password_hash(admin.password.encode('ascii'),
                                                form.password.data):
            session['admin_email'] = form.email.data
            flash(f'Welcome {admin.name}, you are logged in now', 'success')
            return redirect(
                request.args.get('next') or url_for('management.admin'))
        else:
            flash('wrong password, please try again', 'danger')
    return render_template('admin/login.html', form=form, title='Login Page')
示例#23
0
def login():
    form = LoginForm(request.form)
    if request.method == "POST" and form.validate():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            session['email'] = form.email.data
            flash(
                f'Bienvenido {form.email.data} has iniciado sesión correctamente',
                'success')
            return redirect(request.args.get('next') or url_for('admin'))
        else:
            flash('Wrong password, please try again', 'danger')

    return render_template('admin/login.html', form=form, title='Login Page')
示例#24
0
def login():
    form = LoginForm(request.form)
    if request.method == "POST" and form.validate():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            session['email'] = form.email.data
            flash(f'Bienvenido{form.email.data} ya estas registrado',
                  'success')
            return redirect(request.args.get('next') or url_for('admin'))
        else:
            flash(f'Intentar de nuevo', 'danger')
    return render_template('admin/login.html',
                           form=form,
                           title="Pagina de Login")
示例#25
0
def customer_login():
    form = CustomerLoginForm()
    if request.method == "POST":
        user = Customer.query.filter_by(email=form.email.data).first()
        user_password = user.password.encode('ascii')
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user)
            flash('You are logged in.', 'success')
            next = request.args.get('next')
            return redirect(next or url_for('home'))
        else:
            flash(f'incorrect email and password', 'danger')
            print('incorrect email and password')
            return redirect(url_for('customer_login'))

    return render_template('customer/login.html', form=form)
示例#26
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = Users.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('home'))
        else:
            flash('Login Unsuccessfully,Please check your account again',
                  'danger')
    return render_template('customer/login.html', title='Login', form=form)
def changes_password():
    if 'email' not in session:
        flash(f'please login first', 'danger')
        return redirect(url_for('login'))
    user = Admin.query.filter_by(email=session['email'])
    detail_password_admin = Admin.query.get_or_404(user[0].id)
    old_password = request.form.get('oldpassword')
    new_password = request.form.get('newpassword')
    if request.method == "POST":
        if not bcrypt.check_password_hash(detail_password_admin.password, old_password.encode('utf8')):
            flash(f'Old passwords do not match!', 'danger')
            return redirect(url_for('changes_password'))
        detail_password_admin.password = bcrypt.generate_password_hash(new_password).decode('utf8')
        flash(f'Change Password Complete!', 'success')
        db.session.commit()
        return redirect(url_for('changes_password'))
    return render_template('admin/change_password.html', title='Change Password', user=user[0])
示例#28
0
def customer_login_page(page, id):
    if current_user.is_authenticated:
        if page == "rate":
            return redirect(url_for('detail', id))
    form = CustomerLoginFrom()
    if form.validate_on_submit():
        user = Register.query.filter_by(username=form.username.data).first()
        if user and bcrypt.check_password_hash(
                user.password, form.password.data.encode('utf8')):
            login_user(user)
            return redirect(url_for('detail', id=id))
        flash('Incorrect email and password', 'danger')
        return redirect(url_for('customer_login_page', page=page, id=id))
    return render_template('customers/login.html',
                           form=form,
                           brands=brands(),
                           categories=categories())
示例#29
0
def customerLogin():
    form = CustomerLoginFrom()
    if form.validate_on_submit():
        user = Customers.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user)
            session['logged_in'] = True
            session['uid'] = user.id
            session['s_name'] = user.name
            flash('You are login now!', 'success')
            next = request.args.get('next')
            return redirect(next or url_for('home'))
        flash('Incorrect email and password', 'danger')
        return redirect(url_for('customerLogin'))

    return render_template('customer/login.html', form=form)
示例#30
0
def login():
    form = LoginForm(request.form)
    form1 = RegistrationForm()
    if request.method == "POST" and form.validate():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            session['email'] = form.email.data
            flash(f'welcome {form1.name.data} you are logged in', 'success')
            return redirect(request.args.get('next') or url_for('admin'))
        else:
            flash(
                'Incorrect username or password. Please enter your correct username and password or click forget password',
                'danger')
    return render_template('admin/login.html',
                           form=form,
                           form1=form1,
                           title='Login Page')