Esempio n. 1
0
File: index.py Progetto: culee/moody
def admin():
    global check_delete
    check_delete = 2

    if ("user_id" in session):
        user = User.objects.with_id(session["user_id"])
        if user.username == "admin":
            all_user = User.objects()
            length_user = len(all_user)
            length_contributed_user = len(User.objects(contributed__gt=0))
            length_user_contribution = len(Contribution.objects(approved=True))
            length_base = len(Book.objects()) + len(Video.objects()) + \
                len(Song.objects()) + len(Place.objects())
            not_approved_contribution = Contribution.objects(approved=False)
            length = len(not_approved_contribution)

            return render_template("admin.html", user=user,
                                   all_user=all_user,
                                   not_approved_contribution=not_approved_contribution,
                                   length=length,
                                   length_user=length_user - 1,
                                   length_user_contribution=length_user_contribution,
                                   length_base=length_base,
                                   length_contributed_user=length_contributed_user)
        else:
            flash("You don't have permission to visit here. Get out!")
            return render_template("404.html"), 404
    else:
        return redirect(url_for('login'))
Esempio n. 2
0
def signup():
    if request.method == "GET":
        return render_template('signup.html')
    elif request.method == "POST":
        form = request.form
        new_user = User(
            name=form['name'],
            email=form['email'],
            username=form['username'],
            password=form['password'],
        )
        new_user.save()
        return ('Saved')
Esempio n. 3
0
File: index.py Progetto: culee/moody
def login():
    if 'user_id' in session:
        flash("You have already logged in.")
        return render_template("404.html"), 404
    else:
        global check_login
        global happy_user
        error = None

        if request.method == "GET":
            return render_template('login.html')
        elif request.method == "POST":
            form = request.form
            username = form["username"]
            password = form["password"]

            acc = User.objects(username=username, password=password).first()
            if acc is None:
                error = 'Login failed. Try logging in again.'
                return render_template('login.html', error=error)
            else:
                session["user_id"] = str(acc["id"])
                if username == "admin":
                    flash("Hello Boss. Have a good day.")
                    return redirect(url_for('admin'))
                else:
                    flash('You were successfully logged in.')
                    if check_login == 1:
                        return redirect(url_for('index'))
                    elif check_login == 2:
                        return redirect(url_for('recommend', happy=happy_user))
                    if check_login == 3:
                        return redirect(url_for('contribute'))
                    else:
                        return redirect(url_for('index'))
def newuser():
    if request.method == "GET":
        return render_template("newuser.html")
    elif request.method == "POST":
        form = request.form
        username = form["username"]
        password = form["password"]
        email = form["email"]
        fullname = form["fullname"]

        new_user = User(username="******",
                        password="******",
                        email="email",
                        fullname="fullname")
        new_user.save()
        return "Thêm thành công"
def sign_in():
    if request.method == "GET":
        return render_template("sign_in.html")
    elif request.method == "POST":
        form = request.form
        user_name = form["user_name"]
        pass_word = form["pass_word"]
        email = form["email"]
        full_name = form["full_name"]

        new_user = User(user_name=user_name,
                        pass_word=pass_word,
                        email=email,
                        full_name=full_name)
        new_user.save()
        return redirect(url_for("sign_in"))
def sign_in():
    if request.method == "GET":
        return render_template('sign_in.html')
    elif request.method == "POST":
        form = request.form
        fullname = form['fullname']
        email = form['email']
        username = form['username']
        password = form['password']
        all_user = User.objects(username=username).first()
        if all_user == None:
            new_user = User(fullname=fullname,
                            email=email,
                            username=username,
                            password=password)
            new_user.save()
            return "Tạo tải khoản thành công"
        else:
            return "Tên đăng nhập đã có người dùng "
Esempio n. 7
0
def user(user_name):
    user = User.objects(user_name=user_name)
    products = Item.objects(name=user_name)
    print(products)
    if "logged_in" in session and session["logged_in"] == True:
        return render_template('user/user.html',
                               user=user[0],
                               products=products)
    else:
        return redirect(url_for("homepage"))
Esempio n. 8
0
def sign_in():
    if request.method == "GET":
        return render_template('sign_in.html')
    elif request.method == "POST":
        form = request.form
        fullname = form['fullname']
        email = form['email']
        username = form['username']
        password = form['password']
        all_user = User.objects(username=username).first()
        if all_user == None:
            new_user = User(fullname=fullname,
                            email=email,
                            username=username,
                            password=password)
            new_user.save()
            return redirect(url_for('log_in'))
        else:
            return 'Tên đăng nhập đã bị trùng, vui lòng bấm back để nhập lại'
Esempio n. 9
0
File: index.py Progetto: culee/moody
def signup():
    if 'user_id' in session:
        flash("You have already logged in. Try logging out before creating new account.")
        return render_template("404.html"), 404
    else:
        error = None
        if request.method == "GET":
            return render_template('signup.html')
        elif request.method == "POST":
            form = request.form
            f_user = User.objects(username=form['username'])
            f_user2 = User.objects(email=form['email'])

            if (form["fullname"] == "") or (form["username"] == "") or (form["password"] == "") or (form["email"] == ""):
                error = "Sign up failed. Try signing up again."
            elif f_user:
                error = "Username existed. Try another one."
            elif f_user2:
                error = "Email existed. Try another one."
            else:
                new_user = User(fullname=form["fullname"],
                                username=form["username"],
                                password=form["password"],
                                email=form["email"],
                                contributed=0
                                )
                new_user.save()
                flash('You were successfully signed up.')
                return redirect(url_for('login'))
            return render_template('signup.html', error=error)
def login():
    all_user = User.object()
    if request.method == "GET":
        return render_template('login.html')
    elif request.method == "POST":
        form = request.form
        username = form['username']
        password = form['password']
        for user in all_user:
            if username == user.username and password == user.password:
                return redirect(url_for('detail'))
            else:
                return "Sai mat khau hoac tai khoan"
def login():
    if request.method == 'GET':
        return render_template('login.html')
    if request.method == 'POST':
        form = request.form
        username = form['username']
        password = form['password']
        account = User.objects(username=username, password=password).first()
        if account == None:
            return "Bạn nhập sai tên tài khoản hoặc mật khẩu."
        else:
            session['logged_in'] = str(account['id'])

            return redirect(url_for('index'))
Esempio n. 12
0
def log_in():
    if request.method == "GET":
        return render_template("log_in.html")
    elif request.method == "POST":
        form = request.form
        user_name = form["user_name"]
        pass_word = form["pass_word"]
        account_info = User.objects(user_name=user_name).get().to_mongo()
        correct_pass_word = account_info["pass_word"]
        if pass_word == correct_pass_word:
            session["loggedin"] = True
            session["user_name"] = user_name
            return redirect(url_for("search1"))
        else:
            return "Incorrect"
Esempio n. 13
0
def forgot_password():
    if request.method == "GET":
        return render_template('forgot_password.html')
    elif request.method == "POST":
        form = request.form
        user_username = form['user_username']
        user_email = form['user_email']
        user_password = form['user_password']
        account = User.objects(username=user_username,
                               email=user_email).first()
        if account == None:
            return redirect(url_for('forgot_password'))
        else:
            account.update(set__password=user_password)
            return redirect(url_for('log_in'))
Esempio n. 14
0
def login():
    if request.method == "GET":
        return render_template('login.html')
    elif request.method == "POST":
        form = request.form
        username = form['username']
        password = form['password']

        #query from database
        user = User.objects(username=username, password=password)
        if len(user) == 0:
            return "User not found"
        else:
            session['loggedin'] = True
            # session['useremail'] = user.email
            # session['username'] = user.name
            return redirect(url_for('search'))
Esempio n. 15
0
def log_in():
    if request.method == "GET":
        return render_template('login.html')
    elif request.method == "POST":
        form = request.form
        username_input = form['username']
        password_input = form['password']
        account = User.objects(username=username_input,
                               password=password_input).first()
        if account == None:
            return redirect(url_for('log_in'))
        else:
            session['logged_user'] = str(account['id'])
            if session['pre_page'] == 'detail':
                return redirect(
                    url_for('get_detail', service_id=session['service_id']))
            elif session['pre_page'] == 'home':
                return redirect(url_for('index'))
Esempio n. 16
0
File: index.py Progetto: culee/moody
from flask import *
from models.service import User, Song, Book, Video, Place, Contribution
from process import mlab
from process.standardize import Standard, Standard1
from random import *

app = Flask(__name__)
app.secret_key = "moody"
mlab.connect()

admin = User.objects(username="******").first()
admin_id = str(admin["id"])

check_login = 0
check_delete = 0
check_contribute = 0
contributed = 0
happy_user = 1
count = 0


@app.errorhandler(404)
def page_not_found(e):
    return render_template("error.html",
                           error_code=404,
                           error_message="Oops, page not found."), 404


@app.errorhandler(500)
def internal_error(e):
    return render_template("error.html",
Esempio n. 17
0
# hera2 = Service.objects().get(id = id_to_find)
service = Service.objects().with_id(id_to_find)


#print
# print(hera1)
# print(hera2.to_mongo()) #to_mongo: Nhin het field
# print(hera3.to_mongo())

#Delete
# hera3.delete()

Check whether document exist
if service is not None:
    # hera3.delete()
    # print(service.name)
    #to update
    print(service.yob)
    service.update(set__yob = 2005)
    service.reload()
    print(service.yob)
else:
    print("Service not found")

id_user = "******"
# user = User.objects().get(full_name = "Nathan Drake").to_mongo()
user = User.objects(full_name = "Nathan Drake").get().to_mongo()
password = user["pass_word"]

print(password)
Esempio n. 18
0
def homepage():
    all_items = Item.objects()
    # return render_template('homepage.html', all_items = all_items)
    # @app.route('/sign-up', methods = ['GET','POST'])
    # def sign_up():
    if request.method == "GET":
        # return render_template('homepage/sign-up.html')
        user_name = session.get('user_name', None)

        return render_template('homepage.html',
                               all_items=all_items,
                               message='',
                               user_name=user_name)

    elif request.method == "POST":
        form = request.form

        user_name = form.get('user_name', None)
        password = form.get('password', None)
        email = form.get('email', None)
        phone = form.get('phone', None)

        user = form.get('user', None)
        pas = form.get('pass', None)

        out = form.get('out', None)

        # Comment
        id_item_comment = form.get('button', None)
        author_comment = form.get('author-{0}'.format(id_item_comment), None)
        content_comment = form.get('content-{0}'.format(id_item_comment), None)

        if user != None:

            user = User.objects(user_name=user, password=pas)
            if len(user) == 0:
                message = "NOT found user name or invalid password!"
                user_name = None
                return render_template('homepage.html',
                                       all_items=all_items,
                                       message=message,
                                       user_name=user_name,
                                       id_click='')
            else:
                session['logged_in'] = True
                session['user_name'] = user[0].user_name
                print("successfully signed in")
                return redirect(url_for("user", user_name=user[0].user_name))
        if email != None:

            new_user = User(user_name=user_name,
                            password=password,
                            email=email,
                            phone=phone)
            new_user.save()
            return redirect(url_for('homepage'))
        if out != None:
            session['logged_in'] = False
            session['user_name'] = None
            user_name = session['user_name']
            message = ''
            return render_template('homepage.html',
                                   all_items=all_items,
                                   message=message,
                                   user_name=user_name,
                                   id_click='')
        if id_item_comment != None:
            new_comment = Comment(author=author_comment,
                                  content=content_comment)
            new_comment.save()
            item = Item.objects(id=id_item_comment)[0]
            list_comment = item.comments
            list_comment.append(new_comment)
            print(list_comment)
            item.update(set__comments=list_comment)
            item.reload()
            user_name = session['user_name']

            return render_template('homepage.html',
                                   all_items=all_items,
                                   message='',
                                   user_name=user_name,
                                   id_click=id_item_comment)
Esempio n. 19
0
from models.service import Service, User
import mlab

mlab.connect()

user = User.objects(username="******")
print(user.email)