예제 #1
0
	def login(self, username, password):
		checkData(locals())

		if len(password) == 0 or len(username) == 0:
			raise MissingInputDataError("Insert username and password!")

		from app.backend.controller.usersManager import UsersManager

		usersManager = UsersManager()

		try:
			user = usersManager.getUser(username, password)
			sessionKey = self.__generateSessionKey()
			userUuid = user.uuid
			expireTimestamp = datetime.datetime.now() + datetime.timedelta(days=1)
			
			session = Session(sessionKey = sessionKey, userUuid = userUuid, expireTimestamp = expireTimestamp)
			
			try:
				session.store()
				sessionData = {"sessionKey" : sessionKey, "userUuid" : userUuid}
				return sessionData
			except SessionCreationError as e:
				raise e
			else:
				return None

		except UserNotFoundError as e:
			raise e
		else:
			return None
예제 #2
0
	def logout(self, username):
		checkData(locals())

		from app.backend.controller.usersManager import UsersManager
		usersManager = UsersManager()		
		user = usersManager.getUser(username)
		userUuid = user.uuid

		session = Session(userUuid = userUuid)
		session.retrieve()

		session.delete()

		return {}