def take_interview(self): # Take interview intro self.client_socket.send( ('Your available interviews:').encode() ) # db connection conn = sqlite3.connect('interview.db') # try: # # interview_ids = db.retrieve_interview_by_answer(conn, self._USER_ID) # except TypeError: # self.client_socket.send( ('You have no assigned interviews.').encode() ) #retrieve interviews using self object user_id = db.retrieve_user_by_name(conn, self._USER_NAME) interview_ids = db.retrieve_interview_by_answer(conn, user_id) # one or more interviews exist for interview_id in interview_ids: interview_name = db.retrieve_interview_title(conn, interview_id[0]) self.client_socket.send(("ID: " + str(interview_id[0]) + " Name: " + str(interview_name)).encode()) # outgoing signal to terminate client display loop self.client_socket.send( ('end').encode() ) ## INTERVIEW SELECTION ## # outgoing selection request self.client_socket.send( ('Enter the interview ID you wish to take').encode() ) # incoming selection input interview_id = int(self.client_socket.recv(1024).decode()) # <PROTOCOL: # - retrieve interview based on criteria questions = db.retrieve_questions(conn, interview_id) # - generate loop for each question for question in questions: self.client_socket.send( ('(' + str(question[0]) + ') ' + question[4:]).encode() ) # - for each question, ask for answer, link it to question answer = str(self.client_socket.recv(1024).decode()) answer_id = int(db.retrieve_answer_id_by_question(conn, user_id, question[0])) db.update_answer(conn, answer, answer_id) self.client_socket.send( ('end').encode() ) # - add interview to review list> self.client_socket.send( ('Interview complete').encode() ) conn.close()
def run(self): #greet and request username and password self.client_socket.send( ('Welcome to the Interview Portal').encode() ) sqlFile = 'schema.sql' qry = open(sqlFile, 'r').read() conn= sqlite3.connect( 'interview.db' ) cur = conn.cursor() cur.executescript(qry) new_USER_PW = LoginAuthentication.get_hashed_password("admin") cur.execute("INSERT OR IGNORE INTO Users ( user_name, user_password, user_perms) VALUES ( ?, ?, ?);", ("sysadmin", new_USER_PW, 0)) conn.commit() #Creating a new user response = str(self.client_socket.recv(1024).decode()) # User chooses to login or create a new account if (response == '1'): checking_pass = True while (checking_pass): try: self._USER_NAME = str(self.client_socket.recv(1024).decode()) self._USER_PW = str(self.client_socket.recv(1024).decode()) cur.execute("SELECT * FROM Users WHERE user_name== ? ", (self._USER_NAME,)) conn.commit() hashed_password = cur.fetchone()[2] if (self.checkpassword(self._USER_PW, hashed_password)): self.client_socket.send(("Logging In").encode()) self.client_socket.send(("Redirecting...").encode()) checking_pass = False else: self.client_socket.send(("Failed in else").encode()) self.client_socket.send(("Username or password did not match. Try again:").encode()) except: self.client_socket.send(("Failed").encode()) self.client_socket.send(("Username or password did not match. Try again:").encode()) if (response == '2'): exists = True while exists: try: self._USER_NAME = str(self.client_socket.recv(1024).decode()) #self._USER_AUTH = int(self.client_socket.recv(1024).decode()) self._USER_PW = str(self.client_socket.recv(1024).decode()) cur.execute("INSERT INTO Users ( user_name, user_password, user_perms) VALUES ( ?, ?, ?);", (self._USER_NAME, self._USER_PW, 3)) conn.commit() self.client_socket.send(("Succesful").encode()) self.client_socket.send(("Account created successfully").encode()) exists = False pass except: error = "Integrity Error" self.client_socket.send((error).encode()) self.client_socket.send(("Username already exists. Please choose a different one.").encode()) User_Row = conn.execute("SELECT user_name FROM Users WHERE user_name = ?", (self._USER_NAME,)).fetchone() user_id = db.retrieve_user_by_name(conn, self._USER_NAME) cred = str(db.retrieve_user_auth(conn, user_id)) conn.commit() ## ## ## ## ## _LOGIN_STATUS = (User_Row != None) if _LOGIN_STATUS == True: # CHANGE cred TO USER CREDENTIAL IDENTIFIER BELOW self.client_socket.send((cred).encode()) while(True): response = str(self.client_socket.recv(1024).decode()) print(response) if(cred == '0'): #ADMIN if response == '1': self.create_interview() elif response == '2': self.review_submissions() elif response == '3': self.assign_interview() elif response == '4': self.manage_users() elif response == '5': self.manage_interviews() elif response.upper() == 'Q': break elif(cred == '1'): #LAWYER if response == '1': self.create_interview() elif response == '2': self.review_submissions() elif response == '3': self.assign_interview() elif response == '4': self.manage_interviews() elif response.upper() == 'Q': return elif(cred == '3'): #INTERVIEWEE if response == '1': self.take_interview() elif response.upper() == 'Q': break else: self.client_socket.send( ("Invalid Username").encode() ) self.terminate_session() return self.terminate_session()
def manage_users(self): self.client_socket.send( ('Welcome to User Management').encode() ) conn = sqlite3.connect('interview.db') while(True): option = self.client_socket.recv(1024).decode() if (option == '1'): users = str(db.retrieve_user_all(conn)) self.client_socket.send((users).encode()) check_user = self.client_socket.recv(1024).decode() print("check user" + check_user) user_id = '' user_conf= '' try: user_id = db.retrieve_user_by_name(conn, check_user) user_conf = check_user self.client_socket.send( (user_conf).encode() ) except TypeError: user_conf = 'User does not exist' self.client_socket.send( (user_conf).encode() ) break #self.client_socket.send( (user_conf).encode() ) new_auth = self.client_socket.recv(1024).decode() if (new_auth == 'Invalid Authorization Level'): print(new_auth) break print('Assigning new Authorization Level') db.update_user_auth(conn, user_id, new_auth) conf = ('User ' + check_user + ' has been reassigned an Authorization level') self.client_socket.send( (conf).encode() ) break elif (option == '2'): users = str(db.retrieve_user_all(conn)) self.client_socket.send((users).encode()) check_user = self.client_socket.recv(1024).decode() user_id = '' user_conf= '' try: user_id = str(db.retrieve_user_by_name(conn, check_user)) user_conf = check_user self.client_socket.send( (user_conf).encode() ) except TypeError: user_conf = 'User does not exist' self.client_socket.send( (user_conf).encode() ) break second_conf = self.client_socket.recv(1024).decode() response = '' if (second_conf.upper() == 'Y'): db.delete_user(conn, user_id) response = ('user ' + check_user + ' has been deleted') else: response = ('Operation has been cancelled') self.client_socket.send( (response).encode() ) break else: break print('Exiting User Management') return
def review_submissions(self): # interview review intro self.client_socket.send( ('Review Submissions').encode( )) #Receives a username from client User_Search = self.client_socket.recv(1024).decode() # "Enter the username of the interviewee:" ###CHECK DATABASE FOR USER### # import sqlite3 first conn= sqlite3.connect( 'interview.db' ) interview_user = '' while True: try: interview_user = db.retrieve_user_by_name(conn, User_Search) break except TypeError: #if no existing user self.client_socket.send( ('User does not exist, try again.').encode() ) if interview_user == 'quit': return User_Search = self.client_socket.recv(1024).decode() #interview_user = db.retrieve_user_by_name(conn, User_Search) self.client_socket.send( ('User exists').encode() )#user_conf #User_Found = User_Row[0] #else #display list of available interviews conn= sqlite3.connect( 'interview.db' ) interview_ids = db.retrieve_interview_by_answer(conn, interview_user) for interview_id in interview_ids: interview_name = db.retrieve_interview_title(conn, interview_id[0]) self.client_socket.send(("ID: " + str(interview_id[0]) + " Name: " + str(interview_name)).encode()) #self.client_socket.send( str(interviews).encode() ) #Receives a interview from client self.client_socket.send( ('end').encode() ) interview_id = self.client_socket.recv(1024).decode() interview_name = '' while True: try: interview_name = db.retrieve_interview_title(conn, interview_id) break except TypeError: self.client_socket.send( ('Interview does not exist, try again.').encode() ) if interview_name == 'quit': return interview_id = self.client_socket.recv(1024).decode() self.client_socket.send( ('Displaying Interview').encode() ) #interview_conf ###ADD INTERVIEW TO USER'S INBOX### conn= sqlite3.connect( 'interview.db' ) questions = db.retrieve_questions(conn, interview_id) for question in questions: questionStr = str(question[4:]) print('ind 1 = '+ questionStr) print('ind 0 = '+ str(question[0])) answer = str( db.retrieve_answer(conn, interview_user, str(question[0]) )) self.client_socket.send( ('Q: ' + questionStr + '\nA: ' + answer).encode() ) #interview_conf self.client_socket.send( ('End of Interview').encode() ) #interview_conf print('End of Interview')
def assign_interview(self): # intro message self.client_socket.send( ('Interview Assignment').encode( )) #Receives a username from client User_Search = self.client_socket.recv(1024).decode() # "Enter the username of the interviewee:" ###CHECK DATABASE FOR### # import sqlite3 first conn= sqlite3.connect( 'interview.db' ) interview_user = '' while True: try: interview_user = db.retrieve_user_by_name(conn, User_Search) break except TypeError: #if no existing user self.client_socket.send( ('User does not exist, try again.').encode() ) if interview_user == 'quit': return User_Search = self.client_socket.recv(1024).decode() #interview_user = db.retrieve_user_by_name(conn, User_Search) self.client_socket.send( ('User exists').encode() )#user_conf #User_Found = User_Row[0] #else #display list of available interviews conn= sqlite3.connect( 'interview.db' ) interviews = db.retrieve_interview_all(conn) for interview in interviews: self.client_socket.send( ('(' + str(interview[0]) + ') ' + interview[1]).encode() ) #Receives a interview from client self.client_socket.send( ('end').encode() ) interview_id = self.client_socket.recv(1024).decode() while True: try: interview_name = db.retrieve_interview_title(conn, interview_id) break except TypeError: self.client_socket.send( ('Interview does not exist, try again.').encode() ) if interview_name == 'quit': return interview_id = self.client_socket.recv(1024).decode() self.client_socket.send( ('Assigning Interview').encode() ) #interview_conf ###ADD INTERVIEW TO USER'S INBOX### #db.assign_interview(conn, interview_id, interview_user ) #self.client_socket.send( (interview_name + " has been assigned to " + User_Search + ".").encode() ) #interview_conf conn= sqlite3.connect( 'interview.db' ) questions = db.retrieve_questions(conn, interview_id) for question in questions: db.add_answer(conn, interview_user, question[0], None, interview_id) print('created answer space for question: ' + str(question[0])) #self.client_socket.send( ('(' + str(interview[0]) + ') ' + interview[1]).encode() ) self.client_socket.send( (interview_name + " has been assigned to " + User_Search + ".").encode() ) #interview_conf conn.close() return