def findByEmail(self, email, otherParams=None): queryParams = {"email": email} if (otherParams != None and otherParams.has_key("password")): queryParams["password"] = otherParams["password"] collection = self.dbManager.getCollection(self.collectionName) match = collection.find_one(queryParams) if (match != None): match = self.adaptBSON(match) userInstance = User("") userInstance.parseBSON(match) return userInstance return None
def main(): user_list = [] register = Registry() register.add_role('admin') register.add_resource('design', 'python') register.allow('admin', 'view', 'design') register.allow('admin', 'create', 'design') register.allow('admin', 'update', 'design') register.allow('admin', 'delete', 'design') admin_user = User('admin') admin_user.add_roles('admin') user_list.append(admin_user) current_user = admin_user while True: view_message(current_user) print("Press 4 to quit") s = int(input()) if s == 4: exit(0) if s == 1: print("Enter user name") name = input() flag = True for user in user_list: if user.name == name: current_user = user flag = False if flag: print("User does not exist") if 'admin' in current_user.get_roles(): if s == 2: print("Enter User Name") name = input() user_list.append(User(name)) if s == 3: print("Enter role name") s = input() register.add_role(s) else: if s == 2: print(current_user.get_roles()) if s == 3: print(register.get_resources())
def findAll(self, otherParams=None): queryParams = {} matchedUsers = [] # if(otherParams != None and otherParams.has_key("omicType")): # queryParams["omicType"] = otherParams["omicType"] collection = self.dbManager.getCollection(self.collectionName) match = collection.find(queryParams) if (match != None): userInstance = None for instance in match: instance = self.adaptBSON(instance) userInstance = User("") userInstance.parseBSON(instance) matchedUsers.append(userInstance) return matchedUsers return None
def test_fulltime_student_has_attr(): user_data = User("69", "Noah", "*****@*****.**") student = FullTimeStudent(user_data) assert hasattr(student, "user_data") assert hasattr(student.user_data, "uid") assert hasattr(student.user_data, "full_name") assert hasattr(student.user_data, "email") assert hasattr(student, "major") assert hasattr(student, "exp_grad_date") assert student.maximum_enrollment == 3
def load(self, university_id: str): # print(self.db_helper) user_data = self.db_helper.load_user_by_id(university_id) student_data = self.db_helper.load_student_by_id(university_id) user = User(user_data['university_id'], user_data['name'], user_data['email']) if student_data['fulltime']: student = FullTimeStudent(user) else: student = PartTimeStudent(user) student.exp_grad_date = student_data['expected_graduation'] student.major = student_data['major'] restrictions = self.db_helper.load_student_restrictions(university_id) restrictions = [RESTRICTION_MAPPER[r] for r in restrictions] student.restrictions = restrictions return student
def userManagementNewGuestSession(request, response): #VARIABLE DECLARATION userInstance = None daoInstance = None try: #**************************************************************** # Step 1.GENERATE RANDOM PASSWORD AND A RANDOM EMAIL FOR GUEST USER #**************************************************************** logging.info("STEP1 - GETTING RANDOM PASS AND USER...") password = getRandowWord(6) #GENERATE A RANDOM PASSWORD USING A WORD daoInstance = UserDAO() valid = False userName = "" from random import randrange while valid == False: userName = "******" + str(randrange(99999)) valid = daoInstance.findByEmail(userName + "@paintomics.org") == None #**************************************************************** # Step 2. ADD NEW USER TO DATABASE #**************************************************************** logging.info( "STEP2 - CREATING USER INSTANCE AND SAVING TO DATABASE...") userInstance = User("") userInstance.setEmail(userName + "@paintomics.org") from hashlib import sha1 userInstance.setPassword(sha1(password.encode('ascii')).hexdigest()) userInstance.setUserName(userName) userInstance.setAffiliation("GUEST USER") #Update the last login date at the database from time import strftime today = strftime("%Y%m%d") userInstance.setCreationDate(today) userInstance.setLastLogin(today) userInstance.setIsGuest(True) userID = daoInstance.insert(userInstance) #**************************************************************** # Step 3. Create user directories #**************************************************************** logging.info("STEP3 - INITIALIZING DIRECTORIES...") initializeUserDirectories(str(userID)) #**************************************************************** # Step 4. Create new session #**************************************************************** logging.info("STEP4 - GETTING A NEW SESSION TOKEN...") sessionToken = UserSessionManager().registerNewUser("" + str(userID)) response.setContent({ "success": True, "userID": userID, "userName": userInstance.getUserName(), "sessionToken": sessionToken, "p": password }) except Exception as ex: handleException(response, ex, __file__, "userManagementNewGuestSession") finally: if (daoInstance != None): daoInstance.closeConnection() return response
def userManagementSignUp(request, response, ROOT_DIRECTORY): #VARIABLE DECLARATION userInstance = None daoInstance = None try: #**************************************************************** # Step 1.READ PARAMS AND CHECK IF USER ALREADY EXISTS #**************************************************************** logging.info("STEP1 - READ PARAMS AND CHECK IF USER ALREADY EXISTS...") formFields = request.form email = formFields.get("email") email = email.lower() password = formFields.get("password") userName = adapt_string(formFields.get("userName")) affiliation = adapt_string(formFields.get("affiliation")) daoInstance = UserDAO() userInstance = daoInstance.findByEmail(email) if userInstance != None: logging.info("STEP1 - ERROR! EMAIL ALREADY AT THE DATABASE...") raise CredentialException("Email is already registered") #**************************************************************** # Step 2. Add user to database #**************************************************************** logging.info( "STEP2 - CREATING USER INSTANCE AND SAVING TO DATABASE...") userInstance = User("") userInstance.setEmail(email) from hashlib import sha1 userInstance.setPassword(sha1(password.encode('ascii')).hexdigest()) userInstance.setUserName(userName) userInstance.setAffiliation(affiliation) #Update the last login date at the database from time import strftime today = strftime("%Y%m%d") userInstance.setCreationDate(today) userInstance.setLastLogin(today) userID = daoInstance.insert(userInstance) #**************************************************************** # Step 3. Sending confirmation email #**************************************************************** logging.info("STEP3 - SENDING CONFIRMATION EMAIL... TODO!!") try: #TODO: SERVER ADDRESS AND ADMIN EMAIL message = '<html><body>' message += "<a href='" + "http://bioinfo.cipf.es/paintomics/" + "' target='_blank'>" message += " <img src='" + "http://bioinfo.cipf.es/paintomics/" + "resources/images/paintomics_white_300x66' border='0' width='150' height='33' alt='Paintomics 3 logo'>" message += "</a>" message += "<div style='width:100%; height:10px; border-top: 1px dotted #333; margin-top:20px; margin-bottom:30px;'></div>" message += "<h1>Welcome to Paintomics 3!</h1>" message += "<p>Thanks for joining, " + userInstance.getUserName( ) + "! You're already able to work with Paintomics.</p>" message += "<p>Your user name is as follows:</p>" message += "<p><b>Username:</b> " + userInstance.getEmail( ) + "</p></br>" message += "<p>Login in to Paintomics 3 at </p><a href='" + "http://bioinfo.cipf.es/paintomics/" + "'>" + "http://bioinfo.cipf.es/paintomics/" + "</a>" message += "<div style='width:100%; height:10px; border-top: 1px dotted #333; margin-top:20px; margin-bottom:30px;'></div>" message += "<p>Problems? E-mail <a href='mailto:" + "*****@*****.**" + "'>" + "*****@*****.**" + "</a></p>" message += '</body></html>' sendEmail(ROOT_DIRECTORY, userInstance.getEmail(), userInstance.getUserName(), "Welcome to Paintomics 3", message, isHTML=True) except Exception: logging.error("Failed to send the email.") #**************************************************************** # Step 4. Create user directories #**************************************************************** logging.info("STEP4 - INITIALIZING DIRECTORIES...") initializeUserDirectories(str(userID)) response.setContent({"success": True}) except Exception as ex: handleException(response, ex, __file__, "userManagementSignUp") finally: if (daoInstance != None): daoInstance.closeConnection() return response