Beispiel #1
0
def login():
   if request.method == 'POST':
      user = request.form['nm']
      return redirect(url_for('success',name = user))
   else:
      user = request.args.get('nm')
      return redirect(url_for('success',name = user))
Beispiel #2
0
def login():
   if request.method == "POST":
      if request.form["username"] == "admin" :
         return redirect(url_for("success"))
      else:
         abort(451)
   else:
      return redirect(url_for("index"))
Beispiel #3
0
def hello_user(name):
    logging.info("[name is]:{}.format(name)")
    if name == 'admin':
        #重定向
        return redirect("http://127.0.0.1:5000/admin")
    if name == 'guest':
        return redirect("http://127.0.0.1:5000/guest")
    else:
        return redirect("http://www.baidu.com")
def newOnlineshopping():
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        newOnlineshopping = Onlineshopping(
            name=request.form['name'])
        session.add(newOnlineshopping)
        flash
        ('New Onlineshopping %s Successfully Created' % newOnlineshopping.name)
        session.commit()
        return redirect(url_for('showshoppingwebsites'))
    else:
        return render_template('newshoppingwebsite.html')
Beispiel #5
0
    def get(self, p=''):
        hide_dotfile = request.args.get('hide-dotfile', request.cookies.get('hide-dotfile', 'no'))

        path = os.path.join(root, p)
        files = xml_bring_names(xml_url)

        if path in get_all_folders(files):
            print(get_all_folders(files))
            contents = []
            for filename in get_files_list(files, path[:-1]):
#                print(get_files_list(files, path[:-1]))
                info = {}
                info['type'] = dir_or_file(filename)
                if info['type'] == "dir":
                    info['name'] = filename[:-1]
                else:
                    info['name'] = filename
#                print(info)
                contents.append(info)
            page = render_template('index.html', path=p, contents=contents, hide_dotfile=hide_dotfile)
            result = make_response(page, 200)
            result.set_cookie('hide-dotfile', hide_dotfile, max_age=16070400)
        elif path in files:
            download_link = 'https://%s.blob.core.windows.net/%s/%s' % (storage_name, container_name, path)
            result = redirect(download_link, 301)
        else:
            result = make_response('Not found', 404)
        return result
Beispiel #6
0
def filtrarColor(request, color):
	login(request)
	products = Producto.objects.filter(color=color).order_by('nombre')

	if products is not None:
			# LISTADO FILTRO
		categories = Producto.objects.values_list('categoria', flat=True).distinct().order_by('categoria')
		product_type = Producto.objects.values_list('tipo_producto', flat=True).distinct().order_by('tipo_producto')
		brand = Producto.objects.values_list('marca', flat=True).distinct().order_by('marca')
		size = Producto.objects.values_list('talla', flat=True).distinct().order_by('talla')
		colour = Producto.objects.values_list('color', flat=True).distinct().order_by('color')

		context = {
			'products': products,
			'categories': categories,
			'product_type': product_type,
			'brand': brand,
			'size': size,
			'colour': colour
		}

		return render(request, 'store/listado.html', context)

	else:
		return redirect('products')

	return render(request, 'store/listado.html', {'products':products})
Beispiel #7
0
def complete(id):

    todo = Todo.query.filter_by(id=int(id)).first()
    todo.complete = True
    db.session.commit()
    
    return redirect(url_for('index'))
Beispiel #8
0
def register():
    if request.method == "POST":
        username = request.form['username']
        password = request.form['password']
        db = get_db()
        error = None

        if not username:
            error = '*Username required'
        elif not password:
            error = '*Password required'
        elif db.execute(
            'SELECT id FROM user WHERE username = ?', (username,)
        ).fetchone() is not None:
            error = 'User {} is already registered.'.format(username)

        if error is None:
            db.execute(
                'INSERT INTO user (username, password) VALUES (?, ?)',
                (username, generate_password_hash(password))
            )
            db.commit()
            return redirect(url_for('auth.login'))

        flash(error)
def deleteOnlineshopping(shoppingwebsite_id):
    if 'username' not in login_session:
        return redirect('/login')
    shoppingwebsiteToDelete = session.query(
        Onlineshopping).filter_by(id=shoppingwebsite_id).one()
    if request.method == 'POST':
        session.delete(shoppingwebsiteToDelete)
        flash('%s Successfully Deleted' % shoppingwebsiteToDelete.name)
        session.commit()
        return
        redirect(url_for('showshoppingwebsites',
                 shoppingwebsite_id=shoppingwebsite_id))
    else:
        return
        render_template
        ('deleteshoppingwebsite.html', shoppingwebsite=shoppingwebsiteToDelete)
Beispiel #10
0
def update(id):
    todo = request.form.get("todoitemupdate")
    update_this =  Todo.query.get(id)
    update_this.text = todo
    db.session.commit()

    return redirect(url_for('index'))
Beispiel #11
0
def new(request):
    x = Board() #x는 변수 
    #x.title = request.GET['title']
    #x.text = request.GET['text']
    #x.category = request.GET['category']
    x.save()
    return redirect('/')
Beispiel #12
0
def sign_up():
    if request.method == 'POST':
        email = request.form.get('email')
        first_name = request.form.get('firstName')
        password1 = request.form.get('password1')
        password2 = request.form.get('password2')

        user = User.query.filter_by(email=email).first()
        if user:
            flash('Email already exists.', category='error')
        elif len(email) < 4:
            flash('Email must be greater than 3 characters.', category='error')
        elif len(first_name) < 2:
            flash('First name must be greater than 1 character.', category='error')
        elif password1 != password2:
            flash('Passwords don\'t match.', category='error')
        elif len(password1) < 7:
            flash('Password must be at least 7 characters.', category='error')
        else:
            new_user = User(email=email, first_name=first_name, password=generate_password_hash(
                password1, method='sha256'))
            db.session.add(new_user)
            db.session.commit()
            login_user(new_user, remember=True)
            flash('Account created!', category='success')
            return redirect(url_for('views.home'))

    return render_template("sign_up.html", user=current_user)
Beispiel #13
0
def deleteUser(request):
	try:
		u = User.objects.get(username= request.user.username)
		u.delete()
		return redirect('home')
	except User.DoesNotExist:
		return render(request, 'store/home.html')
	return render(request, 'store/home.html')
Beispiel #14
0
def updat(request, Board_id):
    x = get_object_or_404(Lol, pk=Board_id)
    #x.title = request.GET['title']
    #x.text = request.GET['text']
    #x.category = request.GET['category']
    #x.date = datetime.datetime.now()
    x.save()
    return redirect('/'+str(Board_id))
Beispiel #15
0
def ComprarProducto(request, id_producto):
	instance = Carrito()
	instance.producto = Producto.objects.get(id_producto=id_producto).nombre
	instance.precio = Producto.objects.get(id_producto=id_producto).precio
	instance.cliente = request.user.username
	instance.save()
	messages.success(request, 'Tu producto ha sido agregado con éxito al carrito')
	return redirect('homeCarrito')
Beispiel #16
0
def scrape():
    mars = mongo.db.mars
    mars_data = scrape_mars.scrape()
    mars.update(
        {},
        mars_data,
        upsert=True
    )
    return redirect("http://localhost:5000/", code=302)
def editOnlineshopping(shoppingwebsite_id):
    if 'username' not in login_session:
        return redirect('/login')
    editedOnlineshopping = session.query(
        Onlineshopping).filter_by(id=shoppingwebsite_id).one()
    if request.method == 'POST':
        if request.form['name']:
            editedOnlineshopping.name = request.form['name']
            session.add(editedOnlineshopping)
            session.commit()
            flash
            ('Onlineshopping Successfully Edited %s'
             % editedOnlineshopping.name)
            return redirect(url_for('showshoppingwebsites'))
    else:
        return
        render_template
        ('editShoppingwebsite.html', shoppingwebsite=editedOnlineshopping)
Beispiel #18
0
def login():

    form = LoginForm()
    if form.validate_on_submit():
        if form.email.data == "*****@*****.**" and form.password.data == "password":
            flash("You successfully logged in!","success")
            return redirect(url_for('home'))
        else:
            flash('Login unsuccessful, please check username and password','danger')
    return render_template('login.html',title='Login',form=form)
Beispiel #19
0
def cart(request):
    tokenValue = request.COOKIES.get("token")
    if not tokenValue:
        return redirect('/login/')
    try:
        user = User.objects.get(tokenValue=tokenValue)
    except User.DoesNotExist as e:
        return JsonResponse({'error':2})
    carts = Cart.objects.filter(user__tokenValue=tokenValue)
    return render(request, 'cart/cart.html', {'carts':carts})
def newProducts(shoppingwebsite_id):
    if 'username' not in login_session:
        return redirect('/login')
    shoppingwebsite =
    session.query(Onlineshopping).filter_by(id=shoppingwebsite_id).one()
    if request.method == 'POST':
        newProduct = Products(name=request.form['name'], price=request.form[
                        'price'], course=request.form['course'],
                        shoppingwebsite_id=shoppingwebsite_id,
                        user_id=shoppingwebsite.user_id)
        session.add(newProduct)
        session.commit()
        flash('New Product %s Item Successfully Created' % (newProduct.name))
        return
        redirect(url_for('showProduct', shoppingwebsite_id=shoppingwebsite_id))
    else:
        return
        render_template
    ('newproduct.html',
        shoppingwebsite_id=shoppingwebsite_id)
Beispiel #21
0
def login():
    if request.method == "GET":
        return render_template("login.html")
    else:
        username = request.form["username"]
        password = request.form["password"]
        if utils.authenticate(username, password):
            session['username'] = username
            return redirect(url_for("user_profile"))
        else:
            return "Error: Incorrect username or password <hr><a href = '/home'>Try again</a></hr>"
Beispiel #22
0
def login():
   error = None
   
   if request.method == 'POST':
      if request.form['username'] != 'admin' or \
         request.form['password'] != 'admin':
         error = 'Invalid username or password. Please try again!'
      else:
         flash('You were successfully logged in')
         return redirect(url_for('index'))
			
   return render_template('login.html', error = error)
def login():
	users = mongo.db.users
	login_user = users.find_one({"name":request.form['username']})

	if login_user:
		if bcrypt.hashpw(request.form['pass'].encode('UTF-8'),login_user['password'].encode('UTF-8')) == login_user['password'].encode('UTF-8'):
			session['username'] = request.form['username']
			return redirect(url_for('index'))

		return 'Invalid username/password'

	return 'No User found'
Beispiel #24
0
def login():
    login_form = LoginForm()
    if login_form.validate_on_submit():
        user = User.query.filter_by(email = login_form.email.data).first()
        if user is not None and user.verify_password(login_form.password.data):
            login_user(user,login_form.remember.data)
            return redirect(request.args.get('next') or url_for('main.index'))

        flash('Invalid username or Password')

    title = "watchlist login"
    return render_template('auth/login.html',login_form = login_form,title=title)
Beispiel #25
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(email = form.email.data, username = form.username.data,password = form.password.data)
        db.session.add(user)
        db.session.commit()

        mail_message("Welcome to blogt","email/welcome_user",user.email,user=user)
        
        return redirect(url_for('auth.login'))
        title = "Account"
    return render_template('auth/register.html',registration_form = form)
Beispiel #26
0
def login(request):
    if request.method == 'GET':
        if request.is_ajax():
            strNum = '1234567890'
            rand_str = ''
            for i in range(0, 6):
                rand_str += strNum[random.randrange(0, len(strNum))]
            msg = "您的验证码是:%s。请不要把验证码泄露给其他人。"%rand_str
            phone = request.GET.get('phoneNum')
            # send_sms(msg, phone)
            request.session["code"] = rand_str
            print("*********", rand_str)
            response = JsonResponse({"data": "ok"})
            return response
        else:
            return render(request, "mine/login.html")
    else:
        phone = request.POST.get("username")
        passwd = request.POST.get("passwd")
        code = request.session.get("code")

        if passwd == code:
            # 验证码验证成功
            # 判断用户是否存在
            uuidStr = str(uuid.uuid4())
            try:
                user = User.objects.get(pk=phone)
                user.tokenValue = uuidStr
                user.save()
            except User.DoesNotExist as e:
                # 注册
                user = User.create(phone, None, uuidStr, "hhhh")
                user.save()
            request.session["phoneNum"] = phone
            response = redirect("/mine/")
            response.set_cookie("token", uuidStr)
            return response
        else:
            # 验证码验证失败
            return redirect("/login/")
Beispiel #27
0
def login(request):
	# codigo para el formulario del login con autenticación
	login_form = AuthenticationForm()
	if request.method == "POST" and 'login_btn':
		login_form = AuthenticationForm(data=request.POST)
		if login_form.is_valid():
			username = login_form.cleaned_data['username']
			password = login_form.cleaned_data['password']
			user = authenticate(username=username, password=password)

			if user is not None:
				do_login(request, user)
				return redirect('home')
def editProducts(shoppingwebsite_id, product_id):
    if 'username' not in login_session:
        return redirect('/login')
    editedProduct = session.query(Products).filter_by(id=product_id).one()
    shoppingwebsite =
    session.query(Onlineshopping).filter_by(id=shoppingwebsite_id).one()
    if request.method == 'POST':
        if request.form['name']:
            editedProduct.name = request.form['name']
        if request.form['price']:
            editedProduct.price = request.form['price']
        if request.form['course']:
            editedProduct.course = request.form['course']
        session.add(editedProduct)
        session.commit()
        flash('Products Successfully Edited')
        return
        redirect(url_for('showProduct', shoppingwebsite_id=shoppingwebsite_id))
    else:
        return
        render_template
        ('editproduct.html',
            shoppingwebsite_id=shoppingwebsite_id,
            product_id=product_id, product=editedProduct)
Beispiel #29
0
def register():
    
    form = RegistrationForm()
    
    # if form.validate_on_submit():
    #     flash(f'Accout created for {form.username.data}!',"success")
    #     return redirect(url_for('home'))
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data,email=form.email.data,password=hashed_password)   
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created successfully! You are now able to login','success')
        return redirect(url_for('login'))
    return render_template('register.html',title='Register',form=form)
Beispiel #30
0
def login():
    if request.method == 'POST':
        email = request.form.get('email')
        password = request.form.get('password')

        user = User.query.filter_by(email=email).first()
        if user:
            if check_password_hash(user.password, password):
                flash('Logged in successfully!', category='success')
                login_user(user, remember=True)
                return redirect(url_for('views.home'))
            else:
                flash('Incorrect password, try again.', category='error')
        else:
            flash('Email does not exist.', category='error')

    return render_template("login.html", user=current_user)
Beispiel #31
0
    def post(self , request):
        form = self.form_class(request.POST)

        if form.is_valid():
            user = form.save(commit=False)

            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            user.set_password(password)
            user.save()
            user = authenticate(username=username , password=password)

            if user is not None:
                if user.is_active:
                    login(request , user)
                    return redirect('music:index')

        return render(request, self.template_name , {'form':form})
Beispiel #32
0
def host_del(p_id):
	host  = Host.query.filter_by(id=p_id).first()
	db.session.delete(host)
	return redirect(url_for('.host'))
Beispiel #33
0
def logout():
    session['username'] = ""
    return redirect(url_for("home"))