Ejemplo n.º 1
0
 def __init__(self, id_, username, hashed_password):
     self.username = username
     self.hashed_password = hashed_password
     self.id = id_
     self.name = mongo.get_name(id_)
     self.email = mongo.get_email(id_)
     self.profile_pic = mongo.get_profile_pic(id_)
Ejemplo n.º 2
0
def content_detail(bID):
    global file_id
    global up_count, down_count
    global upvote
    global downvote
    global book
    up_count = 0
    down_count = 0
    file_id = str(bID)
    book = mongoBook.get_book(file_id)
    # print(book)
    # print(type(book))
    image_link = book["front"]
    # image_link = 'https://drive.google.com/thumbnail?authuser=0&sz=w320&id=1ArSB7DUAsUgxppF-Oc99n5BrztO7s-Ti'
    download_count = book["download"]
    file_link = 'https://drive.google.com/file/d/' + file_id + '/view?usp=sharing'
    page_num = book["page_number"]
    description = book["description"]
    Author = book["author"]
    upvote = len(book['upvote'])
    downvote = len(book["downvote"])
    title = book["book_name"]

    # Display comments
    comment_content = []
    comment_user_name = []
    comment_user_profilepic = []
    comment_time = []
    data = mongoComment.get_all_comment(file_id)
    print(data)
    for cursor in data:
        comment_content.append(cursor['content'])
        comment_user_profilepic.append(
            mongoUsr.get_profile_pic(cursor['user_id']))
        comment_user_name.append(mongoUsr.get_name(cursor['user_id']))
        comment_time.append(cursor['time'])

    comment_content.reverse()
    comment_user_name.reverse()
    comment_time.reverse()
    comment_user_profilepic.reverse()

    up_icon = down_icon = ''
    
    if id_ in mongoBook.get_up(file_id):
        up_icon = '/static/images/up_active.png'
        down_icon = '/static/images/down_disabled.png'
    elif id_ in mongoBook.get_down(file_id):
        up_icon = '/static/images/up_disabled.png'
        down_icon = '/static/images/down_active.png'
    else:
        up_icon = '/static/images/up.png'
        down_icon = '/static/images/down.png'

    return render_template("content.html", comment_numb=len(comment_content), content=comment_content, time=comment_time, cusername=comment_user_name, cprofile_pic=comment_user_profilepic, display_navbar="inline", title=title, name=first_Name, picture=profile_pic, upvote_count=upvote, downvote_count=downvote, download_count=download_count, Author=Author, file_link=file_link, image_link=image_link, page_num=page_num, description=description, file_id=bID, up_icon = up_icon, down_icon = down_icon)
Ejemplo n.º 3
0
def index():
    if current_user.is_authenticated:
        # form = Password()
        id_ = user.get_id()
        name = mongoUsr.get_name(id_)
        email = mongoUsr.get_email(id_)
        profile_pic = mongoUsr.get_profile_pic(id_)
        first_Name = name.split(' ', 1)[0]
        if mongoAdmin.is_admin(id_):
            role = 'admin'
        else:
            role = 'member'
        print("Logged in")
        return render_template('profile.html', name=first_Name, email=email, picture=profile_pic, role = role, display_navbar="inline")

    else:
        print("Not logged in")
        return render_template("login.html", text="Login", display_noti="none", display_navbar="none", name="SIGN UP NOW!")
Ejemplo n.º 4
0
def login():
    # Find out what URL to hit for Google login
    if request.method == "POST":
        username = request.form["username"]
        password = request.form["password"]
        # hashed_password = bcrypt.generate_password_hash(password).decode('utf-8')
        # print(hashed_password)
        usr_checked = mongoUsr.login(bcrypt, username, password)
        if usr_checked:
            # @login_manager.user_loader
            global user
            global first_Name
            global profile_pic
            global id_
            id_ = mongoUsr.get_id(usr_checked.username)
            user = logUsr.user_info.get(id_)
            name = mongoUsr.get_name(id_)
            first_Name = name.split(' ', 1)[0]
            profile_pic = mongoUsr.get_profile_pic(id_)
            login_user(user)
            try:
                return redirect(last_url[-1])
            except: 
                return redirect(url_for("index"))
        else:
            print("login failed")

        return redirect(url_for("index"))

    elif request.method == 'GET':
        google_provider_cfg = get_google_provider_cfg()
        authorization_endpoint = google_provider_cfg["authorization_endpoint"]

        # Use library to construct the request for login and provide
        # scopes that let you retrieve user's profile from Google
        request_uri = client.prepare_request_uri(
            authorization_endpoint,
            redirect_uri=request.base_url + "/callback",
            scope=["openid", "email", "profile"],
        )
        print(request_uri)
        return redirect(request_uri)
Ejemplo n.º 5
0
def admin():
    materials = mongoAdmin.total_materials()
    users = mongoAdmin.total_users()
    online = mongoAdmin.total_online()

    online_list = []
    offline_list = []
    offline_last = []
    users_id = mongoAdmin.get_all_id()

    for ele in users_id:
        name = mongoUsr.get_name(ele)
        if mongoAdmin.is_online(ele) == 'Active':
            online_list.append(name)
        else:
            offline_list.append(name)
            offline_last.append(mongoAdmin.is_online(ele))

    online_list.sort()

    return render_template("admin.html", display_navbar="none", name=first_Name, users = users, materials = materials, online = online, online_list = online_list, offline_list = offline_list, len_online = len(online_list), len_offline = len(offline_list), offline_last = offline_last)