def _do_login(self, proposal_code, proposal_number, proposal_password, beamline_name, impersonate=False): if not impersonate: login_name = self.dbConnection.translate( proposal_code, 'ldap') + str(proposal_number) logging.getLogger().debug('ProposalBrick: querying LDAP...') ok, msg = self.ldapConnection.login(login_name, proposal_password) if not ok: msg = "%s." % msg.capitalize() self.refuseLogin(None, msg) return logging.getLogger().debug( "ProposalBrick: password for %s-%s validated" % (proposal_code, proposal_number)) # Get proposal and sessions logging.getLogger().debug('ProposalBrick: querying ISPyB database...') prop = self.dbConnection.getProposal(proposal_code, proposal_number) # Check if everything went ok prop_ok = True try: prop_ok = (prop['status']['code'] == 'ok') except KeyError: prop_ok = False if not prop_ok: self.ispybDown() return logging.getLogger().debug('ProposalBrick: got sessions from ISPyB...') proposal = prop['Proposal'] person = prop['Person'] laboratory = prop['Laboratory'] try: sessions = prop['Session'] except KeyError: sessions = None # Check if there are sessions in the proposal todays_session = None if sessions is None or len(sessions) == 0: pass else: # Check for today's session for session in sessions: beamline = session['beamlineName'] start_date = "%s 00:00:00" % session['startDate'].split()[0] end_date = "%s 23:59:59" % session['endDate'].split()[0] try: start_struct = time.strptime(start_date, "%Y-%m-%d %H:%M:%S") except ValueError: pass else: try: end_struct = time.strptime(end_date, "%Y-%m-%d %H:%M:%S") except ValueError: pass else: start_time = time.mktime(start_struct) end_time = time.mktime(end_struct) current_time = time.time() # Check beamline name if beamline == beamline_name: # Check date if current_time >= start_time and current_time <= end_time: todays_session = session break if todays_session is None: is_inhouse = self.session_hwobj.is_inhouse(proposal["code"], proposal["number"]) if not is_inhouse: if BlissWidget.isInstanceRoleClient(): self.refuseLogin( None, "You don't have a session scheduled for today!") return if not self.askForNewSession(): self.refuseLogin(None, None) return current_time = time.localtime() start_time = time.strftime("%Y-%m-%d 00:00:00", current_time) end_time = time.mktime(current_time) + 60 * 60 * 24 tomorrow = time.localtime(end_time) end_time = time.strftime("%Y-%m-%d 07:59:59", tomorrow) # Create a session new_session_dict = {} new_session_dict['proposalId'] = prop['Proposal']['proposalId'] new_session_dict['startDate'] = start_time new_session_dict['endDate'] = end_time new_session_dict['beamlineName'] = beamline_name new_session_dict['scheduled'] = 0 new_session_dict['nbShifts'] = 3 new_session_dict['comments'] = "Session created by the BCM" session_id = self.dbConnection.createSession(new_session_dict) new_session_dict['sessionId'] = session_id todays_session = new_session_dict localcontact = None else: session_id = todays_session['sessionId'] logging.getLogger().debug( 'ProposalBrick: getting local contact for %s' % session_id) localcontact = self.dbConnection.getSessionLocalContact(session_id) self.acceptLogin(prop['Proposal'],\ prop['Person'],\ prop['Laboratory'],\ todays_session,\ localcontact)
def _do_login(self, username, proposal_password, beamline_name, impersonate=False): logging.getLogger().debug('SoleilLoginBrick _do_login: username %s' % username) logging.getLogger().debug( 'SoleilLoginBrick _do_login: proposal_password %s' % proposal_password) logging.getLogger().debug( 'SoleilLoginBrick _do_login: beamline_name %s' % beamline_name) logging.getLogger().debug( 'SoleilLoginBrick _do_login: impersonate %s' % impersonate) if not impersonate: #login_name=self.dbConnection.translate(proposal_code,'ldap')+str(proposal_number) login_name = username logging.getLogger().debug('SoleilLoginBrick: querying LDAP...') ok, msg = self.ldapConnection.login(login_name, proposal_password) logging.getLogger().debug( "SoleilLoginBrick: password for %s validated" % (username, )) if not ok: msg = "%s." % msg.capitalize() self.refuseLogin(None, msg) return userinfo = self.ldapConnection.getinfo(login_name) gid = userinfo.get('gidNumber', '') uid = userinfo.get('uidNumber', '') if gid and len(gid) > 0: gid = gid[0] else: gid = '' if uid and len(uid) > 0: uid = uid[0] else: uid = '' msg = "SoleilLoginBrick: Searching today's valid session for " msg += "User %s on beamline %s..." % (login_name, beamline_name) logging.getLogger().debug(msg) validsess = self.ldapConnection.find_valid_sessions_for_user( login_name, beamline_name) logging.getLogger().debug("SoleilLoginBrick: validsess: %s" % validsess) if len(validsess) > 0: projuser = validsess[0].username else: projuser = None logging.getLogger().debug( "SoleilLoginBrick: Number of valid session found: %d" % len(validsess)) logging.getLogger().debug("SoleilLoginBrick: Project users: %s" % (projuser)) self.session_hwobj.set_user_info(login_name, uid, gid, projuser) # Get proposal and sessions logging.getLogger().debug( 'SoleilLoginBrick: querying ISPyB database ...') logging.getLogger().debug("SoleilLoginBrick: Project users: %s" % (projuser)) proposal_code = "mx" logging.getLogger().debug("SoleilLoginBrick: proposal_code: %s" % proposal_code) proposal_number = projuser if proposal_number == None: proposal_number = "2014" logging.getLogger().debug("SoleilLoginBrick: proposal_number: %s" % proposal_number) prop = self.dbConnection.getProposal(proposal_code, proposal_number) logging.getLogger().debug("SoleilLoginBrick: prop: %s" % prop) # Check if everything went ok prop_ok = True try: prop_ok = (prop['status']['code'] == 'ok') except KeyError: prop_ok = False if not prop_ok: self.ispybDown() return logging.getLogger().debug( 'SoleilLoginBrick: got sessions from ISPyB: % s' % (prop)) proposal = prop['Proposal'] person = prop['Person'] laboratory = prop['Laboratory'] try: sessions = prop['Session'] except KeyError: sessions = None # Check if there are sessions in the proposal # TODO: remove most of this code next 30 lines is not needed anymore it # is in the SOLEILLdapLogin hwobj in find_valid_sessions_for_user() todays_session = None if sessions is None or len(sessions) == 0: pass else: # Check for today's session for session in sessions: beamline = session['beamlineName'] start_date = "%s 00:00:00" % session['startDate'].split()[0] end_date = "%s 23:59:59" % session['endDate'].split()[0] logging.getLogger().debug( 'SoleilLoginBrick: beamline % s start %s end %s' % (beamline, start_date, end_date)) todays_session = sessions[0] #try: # start_struct=time.strptime(start_date,"%Y-%m-%d %H:%M:%S") #except ValueError: # pass #else: # try: # end_struct=time.strptime(end_date,"%Y-%m-%d %H:%M:%S") # except ValueError: # pass # else: # start_time=time.mktime(start_struct) # end_time=time.mktime(end_struct) # current_time=time.time() # # Check beamline name # if beamline.lower() == beamline_name.lower(): # # Check date # if current_time>=start_time and current_time<=end_time: # todays_session=session # break if todays_session is None: is_inhouse = self.session_hwobj.is_inhouse(proposal["code"], proposal["number"]) if not is_inhouse: if BlissWidget.isInstanceRoleClient(): self.refuseLogin( None, "You don't have a session scheduled for today!") return if not self.askForNewSession(): self.refuseLogin(None, None) return current_time = time.localtime() start_time = time.strftime("%Y-%m-%d 00:00:00", current_time) end_time = time.mktime(current_time) + 60 * 60 * 24 tomorrow = time.localtime(end_time) end_time = time.strftime("%Y-%m-%d 07:59:59", tomorrow) # Create a session new_session_dict = {} new_session_dict['proposalId'] = prop['Proposal']['proposalId'] new_session_dict['startDate'] = start_time new_session_dict['endDate'] = end_time new_session_dict['beamlineName'] = beamline_name new_session_dict['scheduled'] = 0 new_session_dict['nbShifts'] = 3 new_session_dict['comments'] = "Session created by the BCM" session_id = self.dbConnection.createSession(new_session_dict) new_session_dict['sessionId'] = session_id todays_session = new_session_dict localcontact = None else: session_id = todays_session['sessionId'] logging.getLogger().debug( 'SoleilLoginBrick: getting local contact for %s' % session_id) localcontact = self.dbConnection.getSessionLocalContact(session_id) self.acceptLogin(prop['Proposal'],\ prop['Person'],\ prop['Laboratory'],\ todays_session,\ localcontact)
def _do_login(self, proposal_code,proposal_number,proposal_password,beamline_name, impersonate=False): if not impersonate: login_name=self.dbConnection.translate(proposal_code,'ldap')+str(proposal_number) logging.getLogger().debug('ProposalBrick: querying LDAP...') ok, msg=self.ldapConnection.login(login_name,proposal_password) if not ok: msg="%s." % msg.capitalize() self.refuseLogin(None,msg) return logging.getLogger().debug("ProposalBrick: password for %s-%s validated" % (proposal_code,proposal_number)) # Get proposal and sessions logging.getLogger().debug('ProposalBrick: querying ISPyB database...') prop=self.dbConnection.getProposal(proposal_code,proposal_number) # Check if everything went ok prop_ok=True try: prop_ok=(prop['status']['code']=='ok') except KeyError: prop_ok=False if not prop_ok: self.ispybDown() return logging.getLogger().debug('ProposalBrick: got sessions from ISPyB...') proposal=prop['Proposal'] person=prop['Person'] laboratory=prop['Laboratory'] try: sessions=prop['Session'] except KeyError: sessions=None # Check if there are sessions in the proposal todays_session=None if sessions is None or len(sessions)==0: pass else: # Check for today's session for session in sessions: beamline=session['beamlineName'] start_date="%s 00:00:00" % session['startDate'].split()[0] end_date="%s 23:59:59" % session['endDate'].split()[0] try: start_struct=time.strptime(start_date,"%Y-%m-%d %H:%M:%S") except ValueError: pass else: try: end_struct=time.strptime(end_date,"%Y-%m-%d %H:%M:%S") except ValueError: pass else: start_time=time.mktime(start_struct) end_time=time.mktime(end_struct) current_time=time.time() # Check beamline name if beamline==beamline_name: # Check date if current_time>=start_time and current_time<=end_time: todays_session=session break if todays_session is None: is_inhouse = self.session_hwobj.is_inhouse(proposal["code"], proposal["number"]) if not is_inhouse: if BlissWidget.isInstanceRoleClient(): self.refuseLogin(None,"You don't have a session scheduled for today!") return if not self.askForNewSession(): self.refuseLogin(None,None) return current_time=time.localtime() start_time=time.strftime("%Y-%m-%d 00:00:00", current_time) end_time=time.mktime(current_time)+60*60*24 tomorrow=time.localtime(end_time) end_time=time.strftime("%Y-%m-%d 07:59:59", tomorrow) # Create a session new_session_dict={} new_session_dict['proposalId']=prop['Proposal']['proposalId'] new_session_dict['startDate']=start_time new_session_dict['endDate']=end_time new_session_dict['beamlineName']=beamline_name new_session_dict['scheduled']=0 new_session_dict['nbShifts']=3 new_session_dict['comments']="Session created by the BCM" session_id=self.dbConnection.createSession(new_session_dict) new_session_dict['sessionId']=session_id todays_session=new_session_dict localcontact=None else: session_id=todays_session['sessionId'] logging.getLogger().debug('ProposalBrick: getting local contact for %s' % session_id) localcontact=self.dbConnection.getSessionLocalContact(session_id) self.acceptLogin(prop['Proposal'],\ prop['Person'],\ prop['Laboratory'],\ todays_session,\ localcontact)
def _do_login(self, username, proposal_password, beamline_name, impersonate=False): logging.getLogger().debug('SoleilLoginBrick _do_login: username %s' % username) logging.getLogger().debug('SoleilLoginBrick _do_login: proposal_password %s' % proposal_password) logging.getLogger().debug('SoleilLoginBrick _do_login: beamline_name %s' % beamline_name) logging.getLogger().debug('SoleilLoginBrick _do_login: impersonate %s' % impersonate) if not impersonate: #login_name=self.dbConnection.translate(proposal_code,'ldap')+str(proposal_number) login_name=username logging.getLogger().debug('SoleilLoginBrick: querying LDAP...') ok, msg=self.ldapConnection.login(login_name,proposal_password) logging.getLogger().debug("SoleilLoginBrick: password for %s validated" % (username,)) if not ok: msg="%s." % msg.capitalize() self.refuseLogin(None,msg) return userinfo = self.ldapConnection.getinfo(login_name) gid = userinfo.get('gidNumber','') uid = userinfo.get('uidNumber','') if gid and len(gid) > 0: gid = gid[0] else: gid = '' if uid and len(uid) > 0: uid = uid[0] else: uid = '' msg = "SoleilLoginBrick: Searching today's valid session for " msg += "User %s on beamline %s..." % (login_name, beamline_name) logging.getLogger().debug(msg) validsess = self.ldapConnection.find_valid_sessions_for_user(login_name, beamline_name) logging.getLogger().debug("SoleilLoginBrick: validsess: %s" % validsess) if len(validsess) > 0: projuser = validsess[0].username else: projuser = None logging.getLogger().debug("SoleilLoginBrick: Number of valid session found: %d" % len(validsess)) logging.getLogger().debug("SoleilLoginBrick: Project users: %s" % (projuser)) self.session_hwobj.set_user_info( login_name, uid, gid, projuser ) # Get proposal and sessions logging.getLogger().debug('SoleilLoginBrick: querying ISPyB database ...') logging.getLogger().debug("SoleilLoginBrick: Project users: %s" % (projuser)) proposal_code = "mx" logging.getLogger().debug("SoleilLoginBrick: proposal_code: %s" % proposal_code) proposal_number = projuser if proposal_number == None: proposal_number = "2014" logging.getLogger().debug("SoleilLoginBrick: proposal_number: %s" % proposal_number) prop=self.dbConnection.getProposal(proposal_code, proposal_number) logging.getLogger().debug("SoleilLoginBrick: prop: %s" % prop) # Check if everything went ok prop_ok=True try: prop_ok=(prop['status']['code']=='ok') except KeyError: prop_ok=False if not prop_ok: self.ispybDown() return logging.getLogger().debug('SoleilLoginBrick: got sessions from ISPyB: % s' % (prop)) proposal=prop['Proposal'] person=prop['Person'] laboratory=prop['Laboratory'] try: sessions=prop['Session'] except KeyError: sessions=None # Check if there are sessions in the proposal # TODO: remove most of this code next 30 lines is not needed anymore it # is in the SOLEILLdapLogin hwobj in find_valid_sessions_for_user() todays_session=None if sessions is None or len(sessions)==0: pass else: # Check for today's session for session in sessions: beamline=session['beamlineName'] start_date="%s 00:00:00" % session['startDate'].split()[0] end_date="%s 23:59:59" % session['endDate'].split()[0] logging.getLogger().debug('SoleilLoginBrick: beamline % s start %s end %s' % (beamline, start_date, end_date)) todays_session=sessions[0] #try: # start_struct=time.strptime(start_date,"%Y-%m-%d %H:%M:%S") #except ValueError: # pass #else: # try: # end_struct=time.strptime(end_date,"%Y-%m-%d %H:%M:%S") # except ValueError: # pass # else: # start_time=time.mktime(start_struct) # end_time=time.mktime(end_struct) # current_time=time.time() # # Check beamline name # if beamline.lower() == beamline_name.lower(): # # Check date # if current_time>=start_time and current_time<=end_time: # todays_session=session # break if todays_session is None: is_inhouse = self.session_hwobj.is_inhouse(proposal["code"], proposal["number"]) if not is_inhouse: if BlissWidget.isInstanceRoleClient(): self.refuseLogin(None,"You don't have a session scheduled for today!") return if not self.askForNewSession(): self.refuseLogin(None,None) return current_time=time.localtime() start_time=time.strftime("%Y-%m-%d 00:00:00", current_time) end_time=time.mktime(current_time)+60*60*24 tomorrow=time.localtime(end_time) end_time=time.strftime("%Y-%m-%d 07:59:59", tomorrow) # Create a session new_session_dict={} new_session_dict['proposalId']=prop['Proposal']['proposalId'] new_session_dict['startDate']=start_time new_session_dict['endDate']=end_time new_session_dict['beamlineName']=beamline_name new_session_dict['scheduled']=0 new_session_dict['nbShifts']=3 new_session_dict['comments']="Session created by the BCM" session_id=self.dbConnection.createSession(new_session_dict) new_session_dict['sessionId']=session_id todays_session=new_session_dict localcontact=None else: session_id=todays_session['sessionId'] logging.getLogger().debug('SoleilLoginBrick: getting local contact for %s' % session_id) localcontact=self.dbConnection.getSessionLocalContact(session_id) self.acceptLogin(prop['Proposal'],\ prop['Person'],\ prop['Laboratory'],\ todays_session,\ localcontact)