示例#1
0
文件: login.py 项目: bbcf/biorepo
 def choose_lab_post(self, *args, **kw):
     u = kw.get('lab_choice', None)
     configp = ConfigParser.RawConfigParser()
     configp.read(path_conf_labs())
     list_labs = (configp.get('LABS:main', 'keys')).split(',')
     if u is not None and u in list_labs:
         session['current_lab'] = u
         session['first_passage'] = False
         session.save()
         principal = session["principal_tequila"]
         tmp_user, tmp_lab = self.build_user(principal)
         raise redirect('/login')
     elif u is not None and u not in list_labs:
         flash("Your lab is not registered into BioRepo, please contact the administrator", "error")
         raise redirect('/login/out')
     else:
         print "--------------- Problem in choose_lab() --------"
         flash('Something strange happen, contact your administrator', 'error')
         raise redirect('/login/out')
示例#2
0
文件: login.py 项目: bbcf/biorepo
 def choose_lab_post(self, *args, **kw):
     u = kw.get('lab_choice', None)
     configp = ConfigParser.RawConfigParser()
     configp.read(path_conf_labs())
     list_labs = (configp.get('LABS:main', 'keys')).split(',')
     if u is not None and u in list_labs:
         session['current_lab'] = u
         session['first_passage'] = False
         session.save()
         principal = session["principal_tequila"]
         tmp_user, tmp_lab = self.build_user(principal)
         raise redirect('/login')
     elif u is not None and u not in list_labs:
         flash(
             "Your lab is not registered into BioRepo, please contact the administrator",
             "error")
         raise redirect('/login/out')
     else:
         print "--------------- Problem in choose_lab() --------"
         flash('Something strange happen, contact your administrator',
               'error')
         raise redirect('/login/out')
示例#3
0
文件: login.py 项目: bbcf/biorepo
    def build_user(self, principal):
        '''
        Build an User and his/her Lab(s) from a principal hash from Tequila
        @param principal: the hash from Tequila
        @return: an User, his/her Lab(s)
        '''
        hash = dict(item.split('=') for item in principal.split('\n') if len(item.split('=')) > 1)
        user = User()
        lab = Labs()
        #initialize the configparser
        configp = ConfigParser.RawConfigParser()
        print "################# NEW CONNEXION ###############"
        print hash, "--- connexion"
        now2 = datetime.datetime.now()
        print "##############       TIME      #############"
        print now2.ctime()

        if(hash.has_key('firstname')):
            user.firstname = hash.get('firstname').decode("utf-8")
        if(hash.has_key('name')):
            user.name = hash.get('name').decode("utf-8")
        if(hash.has_key('email')):
            user.email = hash.get('email')
        #testing unit
        tmp_u = hash['allunits'].lower()
        list_units = tmp_u.split(',')
        print list_units, "list_units"
        #possibility to add one or several external lab(s) to a collaborator without Shibboleth agreement
        test_user = DBSession.query(User).filter(User._email == user.email).first()
        #if it is not the first connexion for the user
        if test_user is not None:
            #get his/her lab(s) registered
            test_labs = test_user.labs
            #check if we get a Shibboleth bypass for this one
            if len(test_labs) > 0:
                for l in test_labs:
                    if str(l.name) not in list_units:
                        print "Shibboleth bypass for : " + str(l.name)
                        list_units.append(str(l.name))

        #parsing conf file labs.ini
        configp.read(path_conf_labs())
        list_labs = (configp.get('LABS:main', 'keys')).split(',')
        print list_labs, "list_labs in labs.ini"
        valid = False
        # try:
        #     test = session['current_lab']
        #     exist = True
        # except:
        #     exist = False

        if len(list_units) > 1 and session['first_passage'] == True:
            cpt_labs = len(list_units)
            cpt = 0
            for u in list_units:
                if u in list_labs:
                    raise redirect('choose_lab', {'list_units': list_units})

                else:
                    cpt += 1
                    pass
                    if cpt == cpt_labs:
                        flash("Sorry, your lab is not registered in BioRepo, please contact the administrator", 'error')
                        raise redirect('/')
        elif len(list_units) > 1 and session['first_passage'] == False:
            valid = True
            u = session["current_lab"]
            lab.name = u
            lab.path_raw = path_raw(u)
            lab.path_processed = path_processed(u)
            lab.path_tmp = path_tmp(u)
            session["tmp_user"] = user
            session["tmp_lab"] = lab
            session.save()
        #the user is affiliated to one lab
        elif len(list_units) < 2 and list_units != ['unsupported']:
            for u in list_units:
                if u in list_labs:
                    #creating the Labs keys
                    valid = True
                    lab.name = u
                    lab.path_raw = path_raw(u)
                    lab.path_processed = path_processed(u)
                    lab.path_tmp = path_tmp(u)
                    session['current_lab'] = u
                    session.save()
                else:
                    flash("Sorry, your lab is not registered in BioRepo, please contact the administrator to do it", 'error')
                    raise redirect('/')
        #the user is an external collaborator, not from EPFL
        elif len(list_units) == 1 and list_units == ['unsupported']:
            print "---- OUTSIDE USER DETECTED ----"
            valid = True
            mail = user.email
            user_tocheck = DBSession.query(User).filter(User._email == mail).first()
            if user_tocheck is None or len(user_tocheck.labs) == 0 or len(user_tocheck.labs) > 2:
                valid = False
            #ext_users have only one lab
            else:
                for l in user_tocheck.labs:
                    lab_name = str(l.name)
                    lab.name = lab_name
                    lab.path_raw = path_raw(lab_name)
                    lab.path_processed = path_processed(lab_name)
                    lab.path_tmp = path_tmp(lab_name)
                    session['current_lab'] = lab_name
                    session.save()

        #IMPORTANT : where you have to put your name if you are a super admin
        if valid == True or hash['user'] == 'mouscaz' or hash['user'] == 'fdavid':
            return user, lab
        else:
            flash("Sorry, your lab is not registered in BioRepo", 'error')
            raise redirect('/')
示例#4
0
文件: login.py 项目: bbcf/biorepo
    def build_user(self, principal):
        '''
        Build an User and his/her Lab(s) from a principal hash from Tequila
        @param principal: the hash from Tequila
        @return: an User, his/her Lab(s)
        '''
        hash = dict(
            item.split('=') for item in principal.split('\n')
            if len(item.split('=')) > 1)
        user = User()
        lab = Labs()
        #initialize the configparser
        configp = ConfigParser.RawConfigParser()
        print "################# NEW CONNEXION ###############"
        print hash, "--- connexion"
        now2 = datetime.datetime.now()
        print "##############       TIME      #############"
        print now2.ctime()

        if (hash.has_key('firstname')):
            user.firstname = hash.get('firstname').decode("utf-8")
        if (hash.has_key('name')):
            user.name = hash.get('name').decode("utf-8")
        if (hash.has_key('email')):
            user.email = hash.get('email')
        #testing unit
        tmp_u = hash['allunits'].lower()
        list_units = tmp_u.split(',')
        print list_units, "list_units"
        #possibility to add one or several external lab(s) to a collaborator without Shibboleth agreement
        test_user = DBSession.query(User).filter(
            User._email == user.email).first()
        #if it is not the first connexion for the user
        if test_user is not None:
            #get his/her lab(s) registered
            test_labs = test_user.labs
            #check if we get a Shibboleth bypass for this one
            if len(test_labs) > 0:
                for l in test_labs:
                    if str(l.name) not in list_units:
                        print "Shibboleth bypass for : " + str(l.name)
                        list_units.append(str(l.name))

        #parsing conf file labs.ini
        configp.read(path_conf_labs())
        list_labs = (configp.get('LABS:main', 'keys')).split(',')
        print list_labs, "list_labs in labs.ini"
        valid = False
        # try:
        #     test = session['current_lab']
        #     exist = True
        # except:
        #     exist = False

        if len(list_units) > 1 and session['first_passage'] == True:
            cpt_labs = len(list_units)
            cpt = 0
            for u in list_units:
                if u in list_labs:
                    raise redirect('choose_lab', {'list_units': list_units})

                else:
                    cpt += 1
                    pass
                    if cpt == cpt_labs:
                        flash(
                            "Sorry, your lab is not registered in BioRepo, please contact the administrator",
                            'error')
                        raise redirect('/')
        elif len(list_units) > 1 and session['first_passage'] == False:
            valid = True
            u = session["current_lab"]
            lab.name = u
            lab.path_raw = path_raw(u)
            lab.path_processed = path_processed(u)
            lab.path_tmp = path_tmp(u)
            session["tmp_user"] = user
            session["tmp_lab"] = lab
            session.save()
        #the user is affiliated to one lab
        elif len(list_units) < 2 and list_units != ['unsupported']:
            for u in list_units:
                if u in list_labs:
                    #creating the Labs keys
                    valid = True
                    lab.name = u
                    lab.path_raw = path_raw(u)
                    lab.path_processed = path_processed(u)
                    lab.path_tmp = path_tmp(u)
                    session['current_lab'] = u
                    session.save()
                else:
                    flash(
                        "Sorry, your lab is not registered in BioRepo, please contact the administrator to do it",
                        'error')
                    raise redirect('/')
        #the user is an external collaborator, not from EPFL
        elif len(list_units) == 1 and list_units == ['unsupported']:
            print "---- OUTSIDE USER DETECTED ----"
            valid = True
            mail = user.email
            user_tocheck = DBSession.query(User).filter(
                User._email == mail).first()
            if user_tocheck is None or len(
                    user_tocheck.labs) == 0 or len(user_tocheck.labs) > 2:
                valid = False
            #ext_users have only one lab
            else:
                for l in user_tocheck.labs:
                    lab_name = str(l.name)
                    lab.name = lab_name
                    lab.path_raw = path_raw(lab_name)
                    lab.path_processed = path_processed(lab_name)
                    lab.path_tmp = path_tmp(lab_name)
                    session['current_lab'] = lab_name
                    session.save()

        #IMPORTANT : where you have to put your name if you are a super admin
        if valid == True or hash['user'] == 'mouscaz' or hash[
                'user'] == 'fdavid':
            return user, lab
        else:
            flash("Sorry, your lab is not registered in BioRepo", 'error')
            raise redirect('/')