示例#1
0
def book(num_id):
    global books_list
    if request.method == 'GET':
        res = get_book(num_id)
        if res:
            return jsonify(res), 200
        else:
            app.make_response(app.handle_user_exception(NotFound()))
    elif request.method == 'DELETE':
        book_to_delete = BookItem.query.filter_by(id=num_id).first()
        db.session.delete(book_to_delete)
        db.session.commit()
        # books_list = list(filter(lambda x: x['id'] != num_id, books_list))
        return '{}', 200
    elif request.method == 'PUT':
        req = json.loads(request.data, strict=False)
        print(req, num_id)
        updated_book = {
            'name': req['name'],
            'author': req['author'],
            'description': req['description']
        }
        upd_book = BookItem.query.filter_by(id=num_id).update(updated_book)
        # upd_book = BookItem.query.filter_by(id=num_id).first()
        print('OLOLOL', upd_book)
        db.session.commit()
        return '{}', 200
示例#2
0
    def test_flask_make_response(self, app):
        response_text = "Output Text"

        response = app.make_response(response_text)
        assert response.data.decode('utf-8') == response_text

        api_result = APIResult({'text': "Output"})
        response = app.make_response(api_result)
        assert response.content_type == 'application/json'
        assert response.status_code == 200
        assert response.data.decode(
            'utf-8') == api_result.to_response().data.decode('utf-8')
示例#3
0
def greet(name):
    ip = request.remote_addr
    print(ip)
    reqs = __requests_done(ip)
    if reqs <= IP_LIMIT:
        resp = app.make_response(f'Hi {name}!')
        resp.headers["X-RateLimit-Limit"] = IP_LIMIT
        resp.headers["X-RateLimit-Remaining"] = (IP_LIMIT - reqs)
        return resp, 200
    else:
        resp = app.make_response("Rate limit exceeded.")
        resp.headers["X-RateLimit-Limit"] = IP_LIMIT
        resp.headers["X-RateLimit-Remaining"] = 0
        return resp, 429
示例#4
0
def index():
    # home page: list of models
    datasets = get_home_best()
    sel_form = FolderForm()
    sel_form.set_choices(get_folder_list())
    del_form = DeleteDatasetForm()
    reset_form = ResetDatasetForm()
    if request.method == 'POST':
        redirect_to_index = redirect('/index')
        response = app.make_response(redirect_to_index)
        response.set_cookie('automlk_folder', value=str(sel_form.folder.data))
        return response
    if 'automlk_folder' in request.cookies:
        folder = int(request.cookies.get('automlk_folder'))
        sel_form.folder.data = folder
    folders = [
        f for f in get_folder_list()
        if sel_form.folder.data == 0 or f['id'] == sel_form.folder.data
    ]
    return render_template('index.html',
                           datasets=datasets,
                           folders=folders,
                           refresher=int(time.time()),
                           sel_form=sel_form,
                           reset_form=reset_form,
                           del_form=del_form,
                           config=get_config())
示例#5
0
def logout():
    redirect_to_index = redirect(url_for('homepage'))
    cookie = app.make_response(redirect_to_index)
    cookie.set_cookie('github_access_token', expires=0)
    cookie.set_cookie('username', expires=0)
    flash('You have been logged out.', 'success')
    return cookie
示例#6
0
文件: views.py 项目: ralmn/CMAsk
def vote(id, option):

    db.session.flush()
    voteOption = VoteOption.query.filter_by(id=option).first_or_404()

    response = app.make_response(redirect(url_for('.result', id=id)))
    cookie = ('vote-' + id) in request.cookies
    if voteOption.vote.close is not None and voteOption.vote.close < datetime.datetime.now(
    ):
        return redirect(url_for('.result', id=id))
    if voteOption.vote.open is not None and voteOption.vote.open > datetime.datetime.now(
    ):
        return redirect(url_for('.view', id=id))
    if not cookie:
        voteOption.value = voteOption.value + 1
        db.session.commit()
        message = {
            "id": str(id),
            "slug": str(voteOption.slug()),
            "value": int(voteOption.value),
            'did': int(voteOption.id)
        }
        redis.publish(REDIS_CHAN, message)

        response.set_cookie('vote-' + str(id), voteOption.slug())
    return response
示例#7
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()
    
    error = None
    if request.method == 'POST':
        user_email = request.form['email']
        user_pass = request.form['password']
        
        
        profile = myprofile.query.filter(myprofile.email == user_email).first()
        
        
        if profile.email != user_email or profile.password != user_pass:
            error = 'Invalid Credentials. Please try again.'
        else:
            userString = user_email + " " + user_pass
            hash_object = hashlib.md5(userString)
            nowUser = profile.email
            session['nowUser'] = nowUser
            response = app.make_response(redirect(url_for('home', nowUser=nowUser)))
            response.headers['Authorization'] = 'Basic' + " " + (hash_object.hexdigest())
            return response
    return render_template('login.html', form=form)
示例#8
0
def login():
    error = None
    if request.method == 'POST':
        u = User.query.filter_by(name=request.form['name'],
                                 password=request.form['password']).first()
        if u is None:
            error = 'Invalid username or password.'
        else:
            session['logged_in'] = True
            session['user_email'] = u.email
            flash('You are logged in. Go Crazy.')
            payload = {}
            payload['name'] = u.name
            payload['email'] = u.email
            payload['password'] = u.password
            print payload
            print type(payload)
            context = dict(cid=u.id)
            encoded = jwt.encode({'some': payload},
                                 'fiveguys',
                                 algorithm='HS256')
            print encoded
            redirect_to_index = render_template(("products.html"), **context)
            response = app.make_response(redirect_to_index)
            response.set_cookie('jwt', value=encoded)
            return response

            # decode = jwt.decode(encoded, 'fiveguys', algorithms=['HS256'])
            # print decode
            #
            # return redirect(url_for('members'))

    return render_template("login.html",
                           form=LoginForm(request.form),
                           error=error)
示例#9
0
def login():
    title = 'Login page'
    form = LoginForm()
    if form.validate_on_submit() and request.method == 'POST':
        error = None
        #flash('Login requested for username = "******", remember me="%s"')%(form.username.data,str(form.remember_me.data))
        username = form.username.data
        username = username.strip()
        password = form.password.data
        username_obj = models.User.query.get(username)

        if not username_obj:
            error = "* Username or password are incorrect."
            return render_template('login.html',
                                   title=title,
                                   form=form,
                                   error=error)

        if username_obj.password != password:
            error = "* Username or passsword are incorrect."
            return render_template('login.html',
                                   title=title,
                                   form=form,
                                   error=error)

        if 'username' not in session:
            session['username'] = username
        redirect_to_user = redirect('/user')
        response = app.make_response(redirect_to_user)
        response.set_cookie('username', value=username)
        return response
    return render_template('login.html', title=title, form=form)
示例#10
0
文件: views.py 项目: wavegu/ACE9
def logout():
    logout_user()
    target = redirect(url_for('login'))
    response = app.make_response(target)
    response.delete_cookie('current_user_email')
    flash('You were logged out.', 'success')
    return response
示例#11
0
文件: views.py 项目: wavegu/ACE9
def register():
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        print form.data
        user = User(email=form.email.data,
                    password=form.password.data,
                    email_confirmed=False,
                    extension='{}')
        db.session.add(user)
        db.session.commit()

        target = redirect(url_for('index'))
        response = app.make_response(target)
        response.set_cookie('current_user_email', value=user.email)

        token = generate_confirmation_token(user.email)
        confirm_url = url_for('confirm_email', token=token, _external=True)
        html = render_template('user/activate.html', confirm_url=confirm_url)
        subject = "Please confirm your email"
        send_email(user.email, subject, html)

        login_user(user)
        flash('You registered and are now logged in. Welcome!', 'success')

        return response
    return render_template('user/register.html', form=form)
示例#12
0
文件: views.py 项目: wavegu/ACE9
def logout():
    logout_user()
    target = redirect(url_for('login'))
    response = app.make_response(target)
    response.delete_cookie('current_user_email')
    flash('You were logged out.', 'success')
    return response
示例#13
0
文件: views.py 项目: wavegu/ACE9
def register():
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        print form.data
        user = User(
            email=form.email.data,
            password=form.password.data,
            email_confirmed=False,
            extension='{}'
        )
        db.session.add(user)
        db.session.commit()

        target = redirect(url_for('index'))
        response = app.make_response(target)
        response.set_cookie('current_user_email', value=user.email)

        token = generate_confirmation_token(user.email)
        confirm_url = url_for('confirm_email', token=token, _external=True)
        html = render_template('user/activate.html', confirm_url=confirm_url)
        subject = "Please confirm your email"
        send_email(user.email, subject, html)

        login_user(user)
        flash('You registered and are now logged in. Welcome!', 'success')

        return response
    return render_template('user/register.html', form=form)
示例#14
0
def login():
    title = 'Login page'
    form = LoginForm()
    if form.validate_on_submit() and request.method == 'POST':
        error=None
        #flash('Login requested for username = "******", remember me="%s"')%(form.username.data,str(form.remember_me.data))
        username = form.username.data
        username = username.strip()
        password = form.password.data
        username_obj = models.User.query.get(username)

        if not username_obj:
            error = "* Username or password are incorrect."
            return render_template('login.html',
                                   title=title,
                                   form=form, error=error)

        if username_obj.password != password:
            error = "* Username or passsword are incorrect."
            return render_template('login.html',
                                   title=title,
                                   form=form, error=error)

        if 'username' not in session:
            session['username'] = username
        redirect_to_user = redirect('/user')
        response = app.make_response(redirect_to_user)
        response.set_cookie('username', value=username)
        return response
    return render_template('login.html',
                           title=title,
                           form=form)
示例#15
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()

    error = None
    if request.method == 'POST':
        user_email = request.form['email']
        user_pass = request.form['password']

        profile = myprofile.query.filter(myprofile.email == user_email).first()

        if profile.email != user_email or profile.password != user_pass:
            error = 'Invalid Credentials. Please try again.'
        else:
            userString = user_email + " " + user_pass
            hash_object = hashlib.md5(userString)
            nowUser = profile.email
            session['nowUser'] = nowUser
            response = app.make_response(
                redirect(url_for('home', nowUser=nowUser)))
            response.headers['Authorization'] = 'Basic' + " " + (
                hash_object.hexdigest())
            return response
    return render_template('login.html', form=form)
示例#16
0
def _jsonpify(obj):
    try:
        callback = request.args['callback']
        response = app.make_response("%s(%s)" % (callback, json.dumps(obj)))
        response.mimetype = "text/javascript"
        return response
    except KeyError:
        return jsonify(obj)
示例#17
0
def get_edit():
    current_short_prescription_id = flask.request.args.get("prescription_id")
    bundle = load_prepare_request(current_short_prescription_id)
    response = app.make_response(bundle)
    short_prescription_ids = get_prescription_ids_from_cookie()
    update_pagination(response, short_prescription_ids,
                      current_short_prescription_id)
    return response
示例#18
0
def randCode(num):
    image, code = create_validate_code()
    buf = StringIO.StringIO()
    image.save(buf,'JPEG',quality=70)
    session['rand_code'] = code
    buf_str = buf.getvalue()
    response = app.make_response(buf_str)
    response.headers['Content-Type'] = 'image/jpeg'
    return response
示例#19
0
def authorized(access_token):
    if access_token is None:
        flash('Authorization failed.')
        return redirect(homepage)
    redirect_to_index = redirect(url_for('user'))
    cookie = app.make_response(redirect_to_index)
    cookie.set_cookie('github_access_token', access_token)
    flash('You have been logged in.', 'success')
    return cookie
示例#20
0
文件: routes.py 项目: xunil/robot
def login():
    if 'robotdocent' in request.cookies:
        return redirect('/docent')
    form = LoginForm()
    if form.validate_on_submit() and form.password.data == DOCENT_PASSWORD:
        resp = app.make_response(redirect('/docent'))
        resp.set_cookie('robotdocent', value='1')
        return resp
    return render_template('login.html', title='Sign In', form=form)
示例#21
0
文件: views.py 项目: P-ppc/microblog
def code():
    code_img, strs = create_validate_code()
    session['code'] = strs

    buf = StringIO.StringIO()
    code_img.save(buf, 'JPEG', quality = 70)

    buf_str = buf.getvalue()
    response = app.make_response(buf_str)
    response.headers['Content-type'] = 'image/jpeg'
    return response
示例#22
0
def code():
    code_str,code_img = gene_code()
    session['code'] = code_str.lower()
    print gene_code()
    buf = cStringIO.StringIO()
    #code_img.save(buf,'jpeg')
    code_img.save(buf,'png')
    buf_str = buf.getvalue()
    response = app.make_response(buf_str)
    response.headers['Content-Type'] = 'image/png'
    return response
示例#23
0
文件: views.py 项目: npk/pku-jishi
def captcha():
    """docstring for captcha"""
    code = ''.join(random.sample(string.uppercase + string.digits, 4))
    session['captcha'] = hashlib.md5(code.lower()).hexdigest()
    image = lib.generate_captcha(code)
    buf = StringIO.StringIO()
    image.save(buf, 'JPEG', quality=75)
    buf_str = buf.getvalue()
    response = app.make_response(buf_str)
    response.headers['Content-Type'] = 'image/jpeg'
    return response
示例#24
0
文件: test.py 项目: ChenShuyan/pyb2c
def test():
    captcha = Captcha(font_type=g.rootpath+'/assets/Monaco.ttf')
    code_img,strs = captcha.get_captcha()
    buf = StringIO.StringIO()
    code_img.save(buf,'JPEG',quality=70)

    buf_str = buf.getvalue()
    response = app.make_response(buf_str)
    response.headers['Content-Type'] = 'image/jpeg'

    return response 
示例#25
0
 def get(cls,
         result_dict: Dict,
         _type=None,
         message=None,
         status_code: int = 200):
     from app import app
     if status_code != 200:
         result_dict = {"type": _type, "message": message}
     logger.debug(json.dumps(result_dict, indent=4))
     content = jsonify(result_dict)
     response = app.make_response((content, status_code))
     return response
示例#26
0
def get_code():
    #把strs发给前端,或者在后台使用session保存
    code_img, strs = create_validate_code()
    session['captcha'] = strs
    buf = StringIO.StringIO()
    code_img.save(buf, 'JPEG', quality=70)

    buf_str = buf.getvalue()
    buf_str = buf_str.encode('base64')
    response = app.make_response(buf_str)
    response.headers['Content-Type'] = 'image/jpeg'
    return response
示例#27
0
def get_code():
    #把strs发给前端,或者在后台使用session保存
    code_img,strs = create_validate_code()
    session['captcha'] = strs
    buf = StringIO.StringIO()
    code_img.save(buf,'JPEG',quality=70)

    buf_str = buf.getvalue()
    buf_str = buf_str.encode('base64')
    response = app.make_response(buf_str)
    response.headers['Content-Type'] = 'image/jpeg'
    return response
示例#28
0
def auth():
    username = request.form['username']
    password = request.form['password']

    if username != USERNAME or password != PASSWORD:
        return redirect('/login')

    access_token = create_access_token(identity=username)
    redirect_to_index = redirect('/')
    response = app.make_response(redirect_to_index)
    response.set_cookie('access_token_cookie', value=access_token)
    return response
示例#29
0
def authenticate(oauth_token, oauth_verifier):
    request_token = {}
    request_token['oauth_token'] = oauth_token
    request_token['oauth_token_secret'] = ''
    request_token['oauth_verifier'] = oauth_verifier
    access_token = twitter_login.get_user_token(request_token)
    
    redirect_to_index = redirect('/')
    response = app.make_response(redirect_to_index)
    response.set_cookie('access_oauth_token', value=access_token['oauth_token'])
    response.set_cookie('access_oauth_token_secret', value=access_token['oauth_token_secret'])
    return response
示例#30
0
def user():
    user = github.get('user')

    print(user["email"])
    print(user["name"])

    if user["email"] == None or user["name"] == None:
        return redirect(url_for('user_missing_data'))

    redirect_to_index = render_template('user.html', user=user)
    cookie = app.make_response(redirect_to_index)
    cookie.set_cookie('username', user['login'])
    return cookie
示例#31
0
def post_edit():
    request_bundles = flask.request.json
    short_prescription_ids = []
    for bundle in request_bundles:
        short_prescription_id = get_prescription_id(bundle)
        short_prescription_ids.append(short_prescription_id)
        add_prepare_request(short_prescription_id, bundle)
    first_bundle = request_bundles[0]
    current_short_prescription_id = get_prescription_id(first_bundle)
    response = app.make_response(first_bundle)
    update_pagination(response, short_prescription_ids,
                      current_short_prescription_id)
    return response
示例#32
0
def for_db():
  data_dict = urlparse.parse_qs(request.data)
  print "data_dict: %s " % str(data_dict)
  print "type: %s" % data_dict['type'][0]
  print data_dict['type'][0] == 'get_material'
  if data_dict['type'][0] == 'new_material':
    name = data_dict['name'][0]
    url = data_dict.get('url')
    photo_url = data_dict.get('photo_url')
    material = models.Material(name, url, photo_url)
    db.session.add(material)
    db.session.commit()
    res = app.make_response(jsonify(data_dict))
    res.mimetype = 'text/plain'
    return res
  elif data_dict['type'][0] == 'get_material':
    material = models.Material.query.filter_by(name=data_dict['name'][0]).all() or ""
    if material != "":
      res = app.make_response("present")
    else:
      res = app.make_response(material)
    return res
示例#33
0
文件: api.py 项目: ChenShuyan/pyb2c
def apiCaptcha():
    captcha = Captcha(font_type=g.rootpath+'/assets/Monaco.ttf')
    code_img,strs = captcha.get_captcha()
    session['captcha_str'] = md5(strs)
    session['captcha_time'] = g.siteTime+60
    buf = StringIO.StringIO()
    code_img.save(buf,'JPEG',quality=70)

    buf_str = buf.getvalue()
    response = app.make_response(buf_str)
    response.headers['Content-Type'] = 'image/jpeg'

    return response
示例#34
0
def for_db():
    data_dict = urlparse.parse_qs(request.data)
    print "data_dict: %s " % str(data_dict)
    print "type: %s" % data_dict['type'][0]
    print data_dict['type'][0] == 'get_material'
    if data_dict['type'][0] == 'new_material':
        name = data_dict['name'][0]
        url = data_dict.get('url')
        photo_url = data_dict.get('photo_url')
        material = models.Material(name, url, photo_url)
        db.session.add(material)
        db.session.commit()
        res = app.make_response(jsonify(data_dict))
        res.mimetype = 'text/plain'
        return res
    elif data_dict['type'][0] == 'get_material':
        material = models.Material.query.filter_by(
            name=data_dict['name'][0]).all() or ""
        if material != "":
            res = app.make_response("present")
        else:
            res = app.make_response(material)
        return res
示例#35
0
def post_dispense():
    if (config.ENVIRONMENT == "prod"):
        return app.make_response("Bad Request", 400)
    dispense_request = flask.request.json
    response = make_eps_api_process_message_request(get_access_token(),
                                                    dispense_request)
    dispense_request_xml = make_eps_api_convert_message_request(
        get_access_token(), dispense_request)
    return {
        "body": json.dumps(response.json()),
        "success": response.status_code == 200,
        "request_xml": dispense_request_xml.text,
        "request": json.dumps(dispense_request),
        "response": json.dumps(response.json()),
    }
示例#36
0
文件: views.py 项目: ralmn/CMAsk
def view(id):
    vote = Vote.query.filter_by(id=id).first_or_404()

    if vote.open is not None and vote.open > datetime.datetime.now():
        return render_template('view-open.html', **locals())

    if vote.close is not None and vote.close < datetime.datetime.now():
        return redirect(url_for('.result', id=id))

    response = app.make_response(redirect(url_for('.result', id=id)))
    cookie = ('vote-' + id) in request.cookies
    if cookie:
        return redirect(url_for('.result', id=id))

    return render_template('view.html', **locals())
示例#37
0
文件: views.py 项目: ralmn/CMAsk
def view(id):
    vote = Vote.query.filter_by(id=id).first_or_404()

    if vote.open is not None and vote.open > datetime.datetime.now():
        return render_template('view-open.html', **locals())

    if vote.close is not None and vote.close < datetime.datetime.now():
        return redirect(url_for('.result', id=id))

    response = app.make_response(redirect(url_for('.result', id=id)))
    cookie = ('vote-'+id) in request.cookies
    if cookie:
        return redirect(url_for('.result', id=id))

    return render_template('view.html', **locals())
示例#38
0
def post_login():
    login_request = flask.request.json
    auth_method = login_request["authMethod"]
    response = app.make_response({"redirectUri": "/"})
    secure_flag = not DEV_MODE
    set_auth_method_cookie(response, auth_method)
    response.set_cookie("Access-Token",
                        "",
                        expires=0,
                        secure=secure_flag,
                        httponly=True)
    response.set_cookie("Access-Token-Set",
                        "false",
                        expires=0,
                        secure=secure_flag)
    return response
示例#39
0
def randomcode(rand):
    """
    验证码视图
    :param rand:
    :return:
    """
    if request.method == "GET":
        validcode = ValidCode()
        code_img, strs = validcode.drawCode() #验证码
        session['yzCode'] = getPasswordMd5(strs.lower(), "O(@(#@EJW@!JIEW")
        buf = StringIO.StringIO()
        code_img.save(buf,'JPEG',quality=70)
        buf_str = buf.getvalue()
        response = app.make_response(buf_str)
        response.headers['Content-Type'] = 'image/jpeg'
        return response
示例#40
0
def randomcode(rand):
    """
    验证码视图
    :param rand:
    :return:
    """
    if request.method == "GET":
        validcode = ValidCode()
        code_img, strs = validcode.drawCode()  #验证码
        session['yzCode'] = getPasswordMd5(strs.lower(), "O(@(#@EJW@!JIEW")
        buf = StringIO.StringIO()
        code_img.save(buf, 'JPEG', quality=70)
        buf_str = buf.getvalue()
        response = app.make_response(buf_str)
        response.headers['Content-Type'] = 'image/jpeg'
        return response
示例#41
0
def post_sign():
    sign_request = flask.request.json
    skip_signature_page = sign_request["skipSignaturePage"]
    short_prescription_id = get_prescription_id_from_cookie()
    prepare_request = load_prepare_request(short_prescription_id)
    prepare_response = make_eps_api_prepare_request(get_access_token(),
                                                    prepare_request)
    auth_method = get_auth_method_from_cookie()
    sign_response = make_sign_api_signature_upload_request(
        auth_method, get_access_token(), prepare_response["digest"],
        prepare_response["algorithm"])
    print("Response from Signing Service signature upload request...")
    print(json.dumps(sign_response))
    response = app.make_response({"redirectUri": sign_response["redirectUri"]})
    set_skip_signature_page_cookie(response, str(skip_signature_page))
    add_prepare_response(short_prescription_id, prepare_response)
    return response
示例#42
0
文件: views.py 项目: wavegu/ACE9
def login():
    form = LoginForm(request.form)
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if not user:
            flash('User not exist...', 'danger')
            return render_template('user/login.html', form=form)
        if bcrypt.check_password_hash(user.password, request.form['password']):
            login_user(user)
            flash('Welcome.', 'success')
            target = redirect(url_for('index'))
            response = app.make_response(target)
            response.set_cookie('current_user_email', value=user.email)
            return response
        else:
            flash('Invalid  password.', 'danger')
            return render_template('user/login.html', form=form)
    return render_template('user/login.html', form=form)
示例#43
0
def free_bitcoin():
    render_word = {}
    render_word['time_left'] = None
    render_word['username'] = request.cookies.get('username') if request.cookies.get('username') else ""
    render_word['info_text'] = 'Check balance: <a href="https://faucetbox.com/en/check/' + render_word[
        'username'] + '">link</a>' if render_word['username'] else ""
    render_word['all_balance'] = mongo.db.balance.find_one({})['balance']
    ip = request.remote_addr
    reffer = request.args['ref'] if 'ref' in request.args else None
    form = FreeForm()
    user_data = Free.objects(ip=ip).order_by('-date').limit(1).first()
    if user_data:
        time_left = check_time(user_data)
        render_word['reward'] = user_data['reward']
        if time_left:
            render_word['time_left'] = time_left

            return render_template("free_bitcoin.html", **render_word)
    if form.validate_on_submit()  and recaptcha.verify():
        user_data = Free.objects(wallet=form.wallet.data).order_by('-date').limit(1).first()
        if user_data:
            time_left = check_time(user_data)
            if time_left:
                render_word['time_left'] = time_left
                render_word[
                    'info_text'] = 'Check balance: <a href="https://faucetbox.com/en/check/' + form.wallet.data + '">link</a>' + "<br>Your wallet is used, pls wait 1440 min"
                print form.wallet.data
                return render_template("free_bitcoin.html", **render_word)
        if 'collect' in request.form:
            coin = 300
        elif 'try' in request.form:
            coin = choice([100,200,600])
        send_status = send_money(form.wallet.data, coin, reffer)
        render_word['coin'] = coin
        if send_status[0]:
            Free(wallet=form.wallet.data, ip=ip, reward=coin, reffer=reffer).save()
            response = app.make_response(redirect('/free_bitcoin'))
            response.set_cookie('username', value=form.wallet.data)
            print 'OK'
            return response
        else:
            render_word['info_text'] = "Server error"

    return render_template("free_bitcoin.html", form=form, **render_word)
示例#44
0
文件: views.py 项目: wavegu/ACE9
def login():
    form = LoginForm(request.form)
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if not user:
            flash('User not exist...', 'danger')
            return render_template('user/login.html', form=form)
        if bcrypt.check_password_hash(
                user.password, request.form['password']):
            login_user(user)
            flash('Welcome.', 'success')
            target = redirect(url_for('index'))
            response = app.make_response(target)
            response.set_cookie('current_user_email', value=user.email)
            return response
        else:
            flash('Invalid  password.', 'danger')
            return render_template('user/login.html', form=form)
    return render_template('user/login.html', form=form)
示例#45
0
文件: views.py 项目: ralmn/CMAsk
def vote(id, option):

    db.session.flush()
    voteOption = VoteOption.query.filter_by(id=option).first_or_404()

    response = app.make_response(redirect(url_for('.result', id=id)))
    cookie = ('vote-'+id) in request.cookies
    if voteOption.vote.close is not None and voteOption.vote.close < datetime.datetime.now():
        return redirect(url_for('.result', id=id))
    if voteOption.vote.open is not None and voteOption.vote.open > datetime.datetime.now():
        return redirect(url_for('.view', id=id))
    if not cookie:
        voteOption.value = voteOption.value +1
        db.session.commit()
        message = {"id":str(id),"slug":str(voteOption.slug()),"value":int(voteOption.value), 'did':int(voteOption.id)}
        redis.publish(REDIS_CHAN, message)

        response.set_cookie('vote-' + str(id), voteOption.slug())
    return response
示例#46
0
def connect():
	error = None
	if request.method=="POST":
		name = request.form["name"]
		password = request.form["password"]
		path = "app/static/json/users.json"
		with open(path, "r+") as login_data:
			auth = json.load(login_data)
		if name in auth.keys():
			if auth[name] == password:
				redirect_to_index = redirect('/grabcar')
				response = app.make_response(redirect_to_index)
				response.set_cookie('username',value=name)
				response.set_cookie('password',value=password)
				return response
			else:
				error ='Invalid credentials!'
		else:
			error = 'Invalid credentials!'

		return render_template("index.html",error=error)
示例#47
0
def robots():
  res = app.make_response('User-agent: *\nAllow: /')
  res.mimetype = 'text/plain'
  return res
示例#48
0
文件: views.py 项目: Frifon/UniGram
def pageNotFound(error):
    return app.make_response(redirect('/'))
示例#49
0
文件: views.py 项目: Frifon/UniGram
def pageSomeAnotherShit(error):
    return app.make_response(redirect('/'))
示例#50
0
def logout():
    redirect_to_index = redirect('/')
    response = app.make_response(redirect_to_index)
    response.set_cookie('access_oauth_token', value='', expires=0)
    response.set_cookie('access_oauth_token_secret',  value='', expires=0)
    return response