Exemple #1
0
 def retrieve_user_data(self):
     db = DBHandler()
     db.connect()
     query = "SELECT userid, email, signup_date, permissions FROM GetPermissions"
     cursor = db.executeQuery(query, ())
     tupls = cursor.fetchall()
     return tupls
Exemple #2
0
    def getAllPosts(self):
        db = DBHandler()
        db.connect()

        query = "SELECT * FROM Posts ORDER BY date DESC;"
        cursor = db.executeQuery(query, ())
        tupls = cursor.fetchall()
        return tupls
Exemple #3
0
    def getUserPosts(self, userid):
        db = DBHandler()
        db.connect()

        query = "SELECT * FROM Posts WHERE userid = %s ORDER BY date DESC;"
        cursor = db.executeQuery(query, userid)
        tupls = cursor.fetchall()
        return tupls
Exemple #4
0
    def check(self, request):
        db = DBHandler()
        db.connect()

        email = request.args.get('returnEmail', 0, type=str)
        pw1 = request.args.get('returnPassword', 0, type=str)
        pw2 = request.args.get('confirmPassword', 0, type=str)
        query = ("SELECT email, password FROM Users " + \
                "WHERE email = %s;")
        cursor = db.executeQuery(query, (email))

        tupl = cursor.fetchone()
        if (tupl != None) and (tupl[0] == email):
            db.disconnect()
            return "email_registered"
        elif not pw1 == pw2:
            db.disconnect()
            return "pw_match"
        else:
            salt = hashlib.sha256(urandom(256)).hexdigest()
            pw = hashlib.sha256(pw1 + salt).hexdigest()
            query = "INSERT INTO Users (email, password, salt) values(%s, %s, %s);"
            db.resetUsersIncrement()
            db.executeUpdate(query, (email, pw, salt))
            query = "SELECT userid, email, signup_date FROM Users WHERE email = %s;"
            cursor = db.executeQuery(query, (email))
            tupl = cursor.fetchone()

            userid = tupl[0]
            email = tupl[1]
            signupdate = tupl[2]

            perms = CheckPermissions()
            isadmin = perms.check_permissions("admin", userid)

            user = User()
            user.create_user(userid, email, isadmin, signupdate)
            session['userid'] = user.get_userid()
            session['email'] = user.get_email()
            session['signupdate'] = user.get_signupdate()

            return "valid_register"
Exemple #5
0
    def check_permissions(self, permission_reqs, userid):

        db = DBHandler()
        db.connect()

        query = "SELECT userid, permission FROM Permissions WHERE userid = %s;"
        cursor = db.executeQuery(query, (str(userid)))
        tupls = cursor.fetchall()
        match = False
        for (userid, permission) in tupls:
            if permission in permission_reqs:
                match = True
        db.disconnect()
        return match
Exemple #6
0
    def update_email(self, request):
        db = DBHandler()
        db.connect()
        
        email1 = request.args.get('returnEmail', 0, type=str)
        email2 = request.args.get('returnConfEmail', 0, type=str)
        pw = request.args.get('returnPassword', 0, type=str)
        query = ("SELECT password, salt FROM Users " + \
                "WHERE email = %s;")
        cursor = db.executeQuery(query, session['email'])

        tupl = cursor.fetchone()
        pw_retr = tupl[0]
        salt = tupl[1]
        pw = hashlib.sha256(pw + salt).hexdigest()
        
        query = ("SELECT email FROM Users " + \
                "WHERE email = %s;")
        cursor = db.executeQuery(query, email1)
        tupl = cursor.fetchone()

        if email1 != email2:
            db.disconnect()
            return "email_nomatch"
        elif pw != pw_retr:
            db.disconnect()
            return "password_fail"
        elif tupl != None:
            db.disconnect()
            return "email_used"
        else:
            query = "UPDATE Users SET email=%s WHERE email=%s;"
            db.executeUpdate(query, (email1, session['email']))
            session['email'] = email1
            db.disconnect()
            return "valid_update"
Exemple #7
0
    def login_js(self, request):
        formEmail = request.args.get('returnEmail', 0, type=str)
        formPassword = request.args.get('returnPassword', 0, type=str)
        password = ""

        db = DBHandler()
        db.connect()
        query = (
            "SELECT userid, email, password, salt, signup_date FROM Users WHERE email = %s;"
        )
        cursor = db.executeQuery(query, (formEmail))

        tupl = cursor.fetchone()
        db.disconnect()

        if not (tupl == None):
            userid = tupl[0]
            email = tupl[1]
            password = tupl[2]
            salt = tupl[3]
            signupdate = tupl[4]

            formPassword = hashlib.sha256(formPassword + salt).hexdigest()

            if (password == formPassword):
                perms = CheckPermissions()
                isadmin = perms.check_permissions("admin", userid)

                user = User()
                user.create_user(userid, email, isadmin, signupdate)
                session['userid'] = user.get_userid()
                session['email'] = user.get_email()
                session['signupdate'] = user.get_signupdate()

                return True
            else:
                time.sleep(0.4)
                return False
        return False