def sendMessage(self, receiverId, senderId, message):
     self.myCursor = self.connection.cursor()
     userController = UserController(self.connection)
     self.myCursor.execute(
         "INSERT INTO Message(receiverId, senderId, message) VALUES(%s, %s, %s);",
         (receiverId, senderId, message))
     self.connection.commit()
     self.myCursor.execute(
         "SELECT * from message where (receiverId = %s and senderId = %s) or (receiverId = %s and senderId = %s) ORDER BY id;",
         (receiverId, senderId, senderId, receiverId))
     resultSet = self.myCursor.fetchall()
     if resultSet != []:
         for chat in resultSet:
             receiver = userController.findById(chat[0])
             sender = userController.findById(chat[1])
             receiverName = receiver.getName()
             senderName = sender.getName()
             conversation = senderName + " to " + receiverName + ": " + chat[
                 3]
             print(conversation)
             conversation = ''
             # receiverName = testUserController.findUserById(chat[0]).getName()
             # senderName = testUserController.findUserById(chat[1]).getName()
             # print(f"{senderName} to {receiverName}: {message.getMessage()}.\n")
     return None
示例#2
0
 def startApplication(self):
     while(True):
         senderId = input('Please enter your id: ')
         testUserController = UserController(self.connect)
         foundSenderId = testUserController.findUserById(senderId)
         if foundSenderId is None:
             print("The user id that you provided does not exist.")
             continue
         break
     print("\nHere is the current user list: ")
     print(testUserController.findAllUserIdExceptSenderId(senderId))
     while(True):
         receiverId = input("\nSelect a user to send your message to: ")
         foundReceiverId = testUserController.findUserById(receiverId)
         if foundReceiverId is None:
             print("The receiver id that you provided is wrong!")
             continue
         break
     testMessageController= MessageController(self.connect)
     while(True): 
         message = input("Please write your message down: ")
         foundMessage = testMessageController.sendMessage(receiverId, senderId, message)
         if foundMessage is not None:
             print(foundMessage)
         option = input("""Would you like to write another message to the same user? 
         Press 1 to write new message, any other button to quit.\n""")
         if option == "1":
             continue
         break
示例#3
0
 def setUserReloadShow(self, username, master):
     """
         Load user from database and reload items.
     """
     user_ctrl = UserController(self._db_ctrl)
     
     username = str(username.toUtf8())
     master = str(master.toUtf8())
     
     self._user = user_ctrl.selectByNameMaster(username, master)
     
     if (self._user):
         self.reloadItems()
     else:
         logging.error("something wrong, can't log in user.")
     self.show()
示例#4
0
def Login():
    try:
        if not request.json or not 'password' in request.json:
            abort(400)
        res = UserController.LoginUser(request)
        return res
    except Exception as exc:
        return make_response(jsonify({"LoginError": str(exc)}))
示例#5
0
 def getFriendEvents(user_id):
     friends = UserController.getFacebookFriends(user_id) #get your facebook friends (facebookIds)
     friendUsers = UserController.getUsersFromFriends(friends) #turn these facebookIds into user_ids
     
     client = MongoClient(System.URI)
     db = client.ConnectMe
     events = db.event
     
     if not friendUsers or len(friendUsers) == 0: #return empty list, for formatting purposes
         return list()
     
     friendEvents = events.find({"user_id" : {"$in" : friendUsers}}) #get all events where the user_id of who created it is in the list of your friends' IDs
     events_list = list()
     for event in friendEvents:
         events_list.append(event)
     
     return events_list
示例#6
0
    def __init__(self, server_rpc):
        Controller.__init__(self, server_rpc)

        self.auth = AuthController(server_rpc)
        self.sr = ServiceRequestController(server_rpc)
        self.col = CollectorController(server_rpc)
        self.dev = DeviceController(server_rpc)
        self.user = UserController(server_rpc)
        self.search = SearchController(server_rpc)
        self.src = SourceController(server_rpc)
示例#7
0
	def __init__(self, con):
		self.con = con
		self.con.ping(True)
		self.cur = self.con.cursor()
		self.userController = UserController(self.con)
		self.planController = PlanController(self.con)
		self.srController = SrController(self.con)
		self.stageController = StageController(self.con)
		self.commentController = CommentController(self.con)
		self.messageController = MessageController(self.con)
 def findConversationBetweenSenderAndReceiver(self, receiverId, senderId):
     # userController = UserController(self.connection)
     # receiver = userController.findUserById(receiverId)
     # sender = userController.findUserById(senderId)
     userController = UserController(self.connection)
     self.myCursor = self.connection.cursor()
     self.myCursor.execute(
         "SELECT receiverId, senderId, message  from message where (receiverId = %s and senderId = %s) or (receiverId = %s and senderId = %s) ORDER BY id;",
         (receiverId, senderId, senderId, receiverId))
     resultSet = self.myCursor.fetchall()
     if resultSet != []:
         for chat in resultSet:
             receiver = userController.findById(chat[0])
             sender = userController.findById(chat[1])
             receiverName = receiver.getName()
             senderName = sender.getName()
             message = receiverName + " to " + senderName + ": " + chat[2]
             print(message)
             message = ""
     return None
示例#9
0
    def logInUser(self, username, master):
        """
            Login user with username and master password.
            
            @param username: username
            @param master: master password
            
            @return: on succes user object, other False
        """
        user_ctrl = UserController(self.__db_ctrl)

        user = user_ctrl.selectByNameMaster(username, master)

        if user:
            logging.debug("user logged in")

            return user
        else:
            logging.debug("user NOT logged in")

            return False
示例#10
0
 def createDB(self):
     """
         Create DB file and new user with master password.
     """
     db_path = str(self._db_file_path.text().toUtf8())
     
     logging.debug("creating new DB: '%s'", db_path)
     
     # write to setting file
     AppSettings.writeDbFilePath(db_path)
     
     self.__db_ctrl.connectDB(db_path)
     self.__db_ctrl.createTables()
     self.__db_ctrl.insertDefRows()
     
     logging.debug("inserting user to DB: '%s'", AppSettings.USER_NAME)
     
     master = str(self._passwd.text().toUtf8())
     
     user = UserController(self.__db_ctrl)
     user.insertUser(AppSettings.USER_NAME, master)
     
     self.signalDbCreated.emit()
     self.close()
示例#11
0
class DataController():
	def __init__(self, con):
		self.con = con
		self.con.ping(True)
		self.cur = self.con.cursor()
		self.userController = UserController(self.con)
		self.planController = PlanController(self.con)
		self.srController = SrController(self.con)
		self.stageController = StageController(self.con)
		self.commentController = CommentController(self.con)
		self.messageController = MessageController(self.con)
		
	def getUserIdByName(self, userName):
		return self.userController.getUserIdByName(userName)
		
	def createUser(self, user):
		return self.userController.createUser(user)

	def getUserByName(self, userName):
		return self.userController.getUserByName(userName)

	def getUserById(self, id):
		return self.userController.getUserById(id)
	
	def updateUserMottoById(self, userId, motto):
		return self.userController.updateUserMottoById(userId, motto)

	def createPlan(self, plan):
		return self.planController.createPlan(plan)

	def deletePlanById(self, id):
		return self.planController.deletePlanById(id)

	def getPlanById(self, id):
		return self.planController.getPlanById(id)

	def getPlansByUserId(self, userId):
		return self.planController.getPlansByUserId(userId)

	def updatePlan(self, plan):
		return self.planController.updatePlan(plan)

	def createSr(self, sr):
		return self.srController.createSr(sr)

	def deleteSr(self, sr):
		return self.srController.deleteSr(sr)

	def deleteSrsByPlanId(self, planId):
		return self.srController.deleteSrsByPlanId(planId)

	def getSrsByUserId(self, userId):
		return self.srController.getSrsByUserId(userId)

	def getSrsByPlanId(self, planId):
		return self.srController.getSrsByPlanId(planId)

	def createStage(self, stage):
		return self.stageController.createStage(stage)

	def deleteStageById(self, id):
		return self.stageController.deleteStageById(id)

	def deleteStagesByPlanId(self, planId):
		return self.stageController.deleteStagesByPlanId(planId)

	def getStageById(self, id):
		return self.stageController.getStageById(id)

	def getStagesByPlanId(self, planId):
		return self.stageController.getStagesByPlanId(planId)

	def updateStage(self, stage):
		return self.stageController.updateStage(stage)

	def createComment(self, comment):
		return self.commentController.createComment(comment)

	def deleteCommentById(self, id):
		return self.commentController.deleteCommentById(id)

	def deleteCommentsByPlanId(self, planId):
		return self.commentController.deleteCommentsByPlanId(planId)

	def getCommentById(self, id):
		return self.commentController.getCommentById(id)

	def getCommentsByPlanId(self, planId):
		return self.commentController.getCommentsByPlanId(planId)

	def getCommentsByUserId(self, userId):
		return self.commentController.getCommentsByUserId(userId)
	
	def createMessage(self, message):
		return self.messageController.createMessage(message)

	def updateMessage(self, message):
		return self.messageController.updateMessage(message)

	def deleteMessageById(self, id):
		return self.messageController.deleteMessageById(id)

	def deleteMessagesByPlanId(self, planId):
		return self.messageController.deleteMessagesByPlanId(planId)

	def getUnReadMessagesByUserId(self, userId):
		return self.messageController.getUnReadMessagesByUserId(userId)

	def getAllMessagesByUserId(self, userId):
		return self.messageController.getAllMessagesByUserId(userId)

	def getAllSupervisorsByUserId(self, userId):
		plans = self.getPlansByUserId(userId)
		supervisors = list()
		ids = list()
		if plans:
			for plan in plans:
				srs = self.getSrsByPlanId(plan['id'])
				for sr in srs:
					if sr['userId'] not in ids:
						ids.append(sr['userId'])
						supervisors.append(self.getUserById(sr['userId']))
		return supervisors

	def getAllSupervisedsByUserId(self, userId):
		srs = self.getSrsByUserId(userId)
		superviseds = list()
		ids = list()
		for sr in srs:
			plan = self.getPlanById(sr['planId'])
			if plan['userId'] not in ids:
				ids.append(plan['userId'])
				superviseds.append(self.getUserById(plan['userId']))
		return superviseds

	# get the user info by userId
	def getUserInfoByUserId(self, userId):
		user = self.getUserById(userId)
		supervisors = self.getAllSupervisorsByUserId(userId)
		superviseds = self.getAllSupervisedsByUserId(userId)
		plans = self.getPlansByUserId(userId)
		planNum = len(plans)
		completedPlanNum = 0
		for plan in plans:
			if plan['unCompletedStageNum'] == 0:
				completedPlanNum += 1
		unReadMessageNum = len(self.getUnReadMessagesByUserId(userId))

		return (user, supervisors, superviseds, planNum, completedPlanNum, unReadMessageNum)

	# use user viewUserId to view the plans of planUserId
	def getPlansViewByUserId(self, planUserId, viewUserId):
		user = self.getUserById(planUserId)
		plans = self.getPlansByUserId(planUserId)
		plansForView = list()
		for plan in plans:
			plan['startTime'] = time.strftime("%Y-%m-%d", time.localtime(plan['startTime']))
			plan['endTime'] = time.strftime("%Y-%m-%d", time.localtime(plan['endTime']))
			plan['completingRate'] = 100
			if plan['unCompletedStageNum'] > 0:
				plan['completingRate'] = int(round(float(plan['completedStageNum']) \
						/ (plan['completedStageNum'] + plan['unCompletedStageNum']) * 100))
			if viewUserId == plan['userId']:
				plansForView.append(plan)
			else:
				srs = self.getSrsByPlanId(plan['id'])
				for sr in srs:
					if sr['userId'] == viewUserId:
						plansForView.append(plan)
						break

		return (user, plansForView)

	def __del__(self):
		del self.userController
		del self.planController
		del self.srController
		del self.stageController
		del self.commentController
		del self.messageController
		self.con.commit()
		self.cur.close()
示例#12
0
from flask import make_response
from User import User
from UserController import UserController
import mysql.connector as mysql
import hashlib, binascii


connection = mysql.connect(
    host="localhost",
    user="******",
    passwd="Hahaha01670",
    auth_plugin='mysql_native_password',
    database = "userregistration"
)

userController = UserController(connection)

# static_url_path = jodi base url er pore /static paay, taile oi url kono function process/handle/execute korbe na,
# oi static_folder e jabe and file er naam match kore file pathabe
 
app = Flask("userRegistration",
            static_url_path='/static',  
            static_folder='static')


def buttonHTML(redirectHTML, buttonString):
    return f"""
    	<input type="button" value="{buttonString}" 
    onclick="window.location='{redirectHTML}';" />
    """
示例#13
0
def Root():
    try:
        res = UserController.addUser(request)
        return res
    except Exception as exc:
        return make_response(jsonify({"Error": str(exc)}))
示例#14
0
from UserController import UserController

conn = UserController()
conn.createUser()
conn.getAll()
from AdministratorController import AdministratorController
from UserController import UserController


class MainController(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        QtWidgets.QMainWindow.__init__(self, parent)
        self.setupUi(self)


def changeWindow(w1, w2):
    w1.hide()
    w2.show()


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    main = MainController()
    user = UserController()
    administrator = AdministratorController()

    main.btn_user.clicked.connect(lambda: changeWindow(main, user))
    user.btn_back.clicked.connect(lambda: changeWindow(user, main))
    main.btn_administrator.clicked.connect(
        lambda: changeWindow(main, administrator))

    administrator.btn_back.clicked.connect(
        lambda: changeWindow(administrator, main))

    main.show()
    sys.exit(app.exec_())
from User import User
from UserController import UserController
import mysql.connector as mysql
import json

connection = mysql.connect(host="localhost",
                           user="******",
                           passwd="Hahaha01670",
                           auth_plugin='mysql_native_password',
                           database="Chat")

userController = UserController(connection)

# print(userController.findUserNameById(5))

# print(userController.addUser("aminebensabeur"))

# print(userController.findAllUsersWithName("ayon"))

# print(userController.findAllUsersWhoseNameStartsWithName("ayon"))

# print(userController.findAllUsersWhoseNameEndsWithName("ayon"))

# print(userController.findAllUsersWhoseContainsName("ayon"))

print(userController.updateUser(2, "Hasan"))