Пример #1
0
def commente():
    login = request.cookies.get('login_email')
    if request.method == 'POST' and login is not None:

        #blog detils
        titleBlog = request.get_json()['title']
        email = request.get_json()['email']
        comment = request.get_json()['comment']
        _id = request.get_json()['_id']

        # #who commenting
        # login_name = request.get_json()['name']
        # login_email = request.get_json()['mail']
        # login_id = request.get_json()['id']

        print(titleBlog)

        if Users.blogExists(titleBlog):
            comment = Comments(titleBlog=titleBlog,
                               comment=comment,
                               email=email,
                               _id=_id)
            comment.save_to_mongo()
            return redirect(url_for('welcome'))
    return redirect(url_for('login'))
Пример #2
0
def blog():
    blogform = BlogForm(request.form['author'], request.form['title'],request.form['email'],request.cookies.get('login_id'),request.form['description'], request.files['file'])

    if request.method == 'POST' and request.cookies.get('login_email') is  not  None:
        
        author  = blogform.author
        title =   blogform.title
        email =   blogform.email
        description = blogform.description
        titleblog =  title.lower()

        f = blogform.filename
        filename = secure_filename(f.filename)
        f.save(os.path.join(os.getcwd() +'/static/uploads', filename))
        
        print(Users.blogExists(request.form['title']))
    
        if Users.blogExists(request.form['title'])  == False:
            userImage =  Database.find_one("user", {"firstname":author})['image']
            cookie = request.cookies.get('login_email')
            person = Users.get_by_email(cookie)
            blog = Blogs(author=author,titleblog=titleblog,description=description,email=email,filename=filename, userImage=userImage)
            blog.save_to_mongo()
            if request.cookies.get('login_email') ==  email:
                data =  Database.find_one(UserConstants.COLLECTION,{"email":email})

                flash('you have successfull created a blog')
                response = make_response(redirect(url_for('welcome', author=data["firstname"], lastname=data['lastname'], email=request.form['email'])))
                response.set_cookie('login_email', request.form['email'])
                response.set_cookie('login_author', data['firstname'])
                response.set_cookie('login_id', data['_id'])
                return response
            else:
                return render_template('blogform.html',point=blogform.message("A blog with that name already exist") )
        else:
            return render_template('blogform.html',point=blogform.message("A blog with that name already exist"))
    return redirect(url_for('login_route'))