def register1():
    if request.method == 'POST':

        req = request.form

        username = req.get('username')
        password = req.get('password')

        if username and database.checkUser(conn, username, password):
            session["USERNAME"] = username
            session["USER_ID"] = database.readUser(conn, username)
            # return render_template('home-page.html', username = username)
            movie_id, movie_title, movie_poster, movie_genres, genre_name, combine_id = fetch_movies(
            )
            might_like_title, might_like_poster, might_like_id = fetch_user_might_like_movies(
            )
            continue_watch_title, continue_watch_poster, continue_watch_id = fetch_continue_watch_movies(
            )
            return render_template(
                'movie-page.html',
                poster_id_title=zip(combine_id, movie_title, movie_poster),
                might_id_title_poster=zip(might_like_id, might_like_title,
                                          might_like_poster),
                continue_id_title_poster=zip(continue_watch_id,
                                             continue_watch_title,
                                             continue_watch_poster))

        else:
            return render_template('LoginPage.html',
                                   msg="Wrong Username or Password")
Exemple #2
0
def check():
    userList = [request.form['username'], request.form['password']]
    checkMark = checkUser(userList[0], userList[1])
    if checkMark == 1:
        session['ID'] = userList
        return redirect('/dashboard')
    else:
        return render_template("login.html",
                               errorMessage='Invalid username or password.')
Exemple #3
0
def login():
    data = request.get_json()
    username = data['username']
    password = data['password']
    result = checkUser(username, password)
    ip = result[0]
    if result:
        #session['user_id']=result[0]
        return {'errcode': 0, 'errmsg': '登录成功', 'id': ip}
    else:
        return {'errcode': 401, 'errmsg': '用户不存在或密码错误'}
Exemple #4
0
def userInfo():
    if request.method == 'POST':
        user = User()
        user.name = request.form.get("name")
        session['name'] = user.name;
        user.pwd = request.form.get("password")
        result = database.checkUser(user.name, user.pwd)
        if result:
            user.pNumber = result[0][3]
            user.age = result[0][2]
            user.sex = "male"
            if not result[0][5]:
                user.sex = "femail"
            return render_template("userInformation.html", user=user)
        return redirect(url_for('login'))
Exemple #5
0
    def POST(self):
        try:
            name = web.input().user
            passwd = web.input().passwd
            if database.checkUser(name, passwd):
                session.login = 1
                session.user = name
            else:
                clearSession()
        except:
            clearSession()

        if logged():
            raise web.seeother('/')
        else:
            raise web.seeother('/login_error')
Exemple #6
0
    def POST(self):
        try:
            name = web.input().user
            passwd = web.input().passwd
            if database.checkUser( name, passwd ):
                session.login = 1
                session.user = name
            else:
                clearSession()
        except:
            clearSession()

        if logged():
            raise web.seeother('/')
        else:
            raise web.seeother('/login_error')
Exemple #7
0
    def handle_client(self, conn, addr):
        HEADER = self.HEADER
        FORMAT = self.FORMAT
        SEPARATOR = self.SEPARATOR
        print(f"[NEW CONNECTION] {addr} connected.")
        USER = ''

        connected = True
        while connected:

            msg_length = conn.recv(HEADER).decode(FORMAT)

            if msg_length:
                msg_length = int(msg_length)
                msg = conn.recv(msg_length).decode(FORMAT)
                info = msg.split(SEPARATOR)

                if info[0] not in ('start?','file','fetch'):
                    print(f"[{addr}] {msg}")

                if info[0] == 'login':
                    user = checkUser(SEPARATOR.join((info[1], info[2])))
                    if user == f'True{SEPARATOR}True':
                        print(self.participants)
                        if info[1] not in self.participants:
                            conn.send(user.encode(FORMAT))
                            USER = info[1]
                            self.participants.update({USER: {"time": None, "%": None, "len": None, "logged": True}})
                            self.ui.participants = self.participants
                            self.ui.update_board()
                            continue
                        elif self.participants[info[1]]["logged"] == False:
                            conn.send(user.encode(FORMAT))
                            USER = info[1]
                            self.participants[info[1]]["logged"] = True
                            self.ui.participants = self.participants
                            self.ui.update_board()
                            continue
                        else:
                            conn.send(f'No{SEPARATOR}No'.encode(FORMAT))
                            continue
                    else:
                        conn.send(user.encode(FORMAT))
                        continue
                
                elif info[0] == "fetch":
                    conn.send(
                        SEPARATOR.join(('fetch',str(self.ui.start),json.dumps(self.participants),str(self.ui.count))).encode(FORMAT)
                    )
                    continue

                elif info[0] == self.LOGIN_MESSAGE:
                    conn.send(json.dumps(self.challenge).encode(FORMAT))
                    continue

                elif info[0] == 'file':
                    with open(f"solutions\\{info[1]}", 'w') as file:
                        file.write(info[2])
                    conn.send('Done'.encode(FORMAT))
                    t = settings.TIME * 60 - self.ui.count
                    self.participants[USER]["time"] = f"{t // 60}:{'0' * ((s := t % 60) < 10) + str(s)}"
                    self.check_files()
                    continue

                elif info[0] == 'example_file':
                    with open(settings.EXAMPLE_FILE, 'r') as file:
                        conn.send(f"challange.py{SEPARATOR}{file.read()}".encode(FORMAT))
                        continue

                if msg == self.DISCONNECT_MESSAGE:
                    if self.participants[USER]["time"] is None:
                        self.participants.pop(USER)
                        self.ui.participants = self.participants
                        self.ui.update_board()
                    else:
                        self.participants[USER]["logged"] = False
                    connected = False
                else:
                    conn.send("None".encode(FORMAT))
        conn.close()
Exemple #8
0
def makeBorrow(user_id, item_id, nitems):
    data = checkItem(item_id)
    if data != "Error":  # does this item exist?
        itemName = data[0]

        userName = database.checkUser(user_id)
        if userName != "Error":  #if username is not existing print error message
            userName = userName[1] + " " + userName[
                2]  #,else make full user name

            if int(data[1]
                   ) >= nitems:  #user not entered ammount exceing stock?

                if (checkBorrowedAmount(user_id, item_id)) < 1:
                    """
                    
                    sql = "UPDATE items SET availableAmount = availableAmount-(%s) WHERE (id = %s)"
                    val = [nitems,item_id]
                    mycursor.execute(sql,val)
                    mydb.commit()
                    itemName = data[0]
                    from datetime import date
                    from dateutil.relativedelta import relativedelta
                    date = date.today() + relativedelta(months=+1)
                    sql = "INSERT INTO borrowed (item_id, user_id, itemName, dueDate ,borrowedAmount,userName) VALUES (%s,%s,%s,%s,%s,%s);"
                    val = [item_id,user_id,itemName,date,nitems,userName]
                    mycursor.execute(sql,val)
                    mydb.commit()
                    sql = "UPDATE users SET borrowedItems = borrowedItems+(%s) WHERE (id = %s);"
                    val = [nitems,user_id]
                    mycursor.execute(sql,val)
                    mydb.commit()
                    """
                    from datetime import date
                    from dateutil.relativedelta import relativedelta
                    date = date.today() + relativedelta(months=+1)
                    datum = str(date.year)
                    datum += str(date.month)
                    datum += str(date.day)
                    date = datum
                    #for x in len(date):
                    #    date += date[x]
                    #print (date)

                    mycursor = mydb.cursor()
                    sql = (
                        "CALL makeBorrow(%s,%s,'%s',%s,%s,'%s')" %
                        (item_id, user_id, itemName, date, nitems, userName))
                    # print (sql)
                    mycursor.execute(sql, "")
                    mydb.commit()

                else:
                    print("Sorry,you have already borrowed this item!")

            else:
                print("You can't borrow more items than in stock!")
        else:
            print("This user does not exist")

    elif data == "NoMore":  # does this item exist but is not currently in stock?
        print("This item is not available right now")
    else:
        print("This item does not exist!")
                               database="ivica3730k_test_app")
import user_input
from user_input import clear_screen
print("Welcome to the python borrow system!!!")
import dialogs
import database
import item

#print(item.checkBorrowedAmount(1,2))
#item.makeBorrow(1,2,5)
#quit()

while (1):

    id_user = user_input.integer_number("Input your Id to log in")
    data = database.checkUser(id_user)
    if data == "Error":
        print("User does not exist:")
    else:
        isAdmin = bool(data[6])
        userid = int(data[0])
        if isAdmin:  #user is an admin
            adminPass = user_input.text_string(
                "Since you are an Admin, you need to input your password here:"
            )
            if database.checkAdminPass(id_user, adminPass):
                print("Welcome back, Admin")
                isAdmin = True
                break
            else:
                print("Wrong password,logging in as standard user")