Esempio n. 1
0
def update_user_profiles():
  for u in User.objects.exclude(username='******'):
    try:
      p = UserProfile.objects.get(user=u)
      print("  User '" + str(u) + "'' has a profile.")

      if SHIBBOLETH_ENABLED:
        if (not p.user.email or len(p.user.email) == 0) and (p.user.username.find('@') > 0):
          p.user.email = p.user.username
          p.user.save()

      if not p.top_level_domain and (p.user.email and len(p.user.email) > 0):
        p.set_domain_info()
        print("    Setting top level: " + p.top_level_domain)
        print("       Setting domain: " + p.domain + "\n")

    except:
      print("  Creating UserProfile for: " + u.username)

      p = UserProfile(user=u)

      if u.username == 'anonymous':
        p.account_type = AccountType.objects.get(type_id=0)
      else:  
        p.account_type = AccountType.objects.get(type_id=DEFAULT_ACCOUNT_TYPE)
      p.save()
Esempio n. 2
0
def create_users(users):
    
    for person in users:
        try:
          print("Update User: "******"Create User: "******"Summary of results for " + str(user))
          wsrg.save()
          user_stats = StatsUser(user=user, ws_report_group=wsrg)  
        user_stats.save()   

        if person[0] != 'anonymous':
          stats_reg_users.user_stats.add(user_stats)
          stats_reg_users.save()
Esempio n. 3
0
def create_users(users):

    for person in users:
        is_anonymous = person[0] == 'anonymous'

        try:
            print("Update User: "******"Create User: "******"Summary of results for " +
                                      str(user))
            wsrg.save()
            user_stats = StatsUser(user=user, ws_report_group=wsrg)
        user_stats.save()

        if not is_anonymous:
            stats_reg_users.user_stats.add(user_stats)
            stats_reg_users.save()
Esempio n. 4
0
def update_user_profiles():
    for u in User.objects.exclude(username='******'):
        try:
            p = UserProfile.objects.get(user=u)
            print("  User '" + str(u) + "'' has a profile.")

            if SHIBBOLETH_ENABLED:
                if (not p.user.email or len(p.user.email)
                        == 0) and (p.user.username.find('@') > 0):
                    p.user.email = p.user.username
                    p.user.save()

            if not p.top_level_domain and (p.user.email
                                           and len(p.user.email) > 0):
                p.set_domain_info()
                print("    Setting top level: " + p.top_level_domain)
                print("       Setting domain: " + p.domain + "\n")

        except:
            print("  Creating UserProfile for: " + u.username)

            p = UserProfile(user=u)

            if u.username == 'anonymous':
                p.account_type = AccountType.objects.get(type_id=0)
            else:
                p.account_type = AccountType.objects.get(
                    type_id=DEFAULT_ACCOUNT_TYPE)
            p.save()
Esempio n. 5
0
    def get_redirect_url(self, *args, **kwargs):

        user = self.request.user

        if user.username == SHIBBOLETH_SUPERUSER:
            user.is_staff = True
            user.is_superuser = True
            user.save()

        try:
            profile = UserProfile.objects.get(user=user)
        except:
            atype = AccountType.objects.get(type_id=DEFAULT_ACCOUNT_TYPE)
            profile = UserProfile(user=user, account_type=atype)
            profile.save()

        try:
            stats = StatsUser.objects.get(user=user)
        except ObjectDoesNotExist:
            wsrg = WebsiteReportGroup(title="Summary of results for " +
                                      str(user))
            wsrg.save()
            stats = StatsUser(user=user, ws_report_group=wsrg)
            stats.save()

        # Try to populate user information from shibboleth information
        if user.first_name == '' or user.last_name == '' or user.email == '':
            try:
                user.first_name = self.request.META['givenName']
                user.last_name = self.request.META['sn']
                user.email = self.request.META['mail']
                user.save()
            except:
                pass

        self.url = SITE_URL

        return super(ShibbolethLogin, self).get_redirect_url(*args, **kwargs)
Esempio n. 6
0
    def get_redirect_url(self, *args, **kwargs):

        user = self.request.user

        if user.username == SHIBBOLETH_SUPERUSER:
            user.is_staff     = True
            user.is_superuser = True
            user.save()

        try: 
            profile = UserProfile.objects.get(user=user)
        except:    
            atype = AccountType.objects.get(type_id=DEFAULT_ACCOUNT_TYPE)
            profile = UserProfile(user=user, account_type=atype)
            profile.save()

        try: 
            stats = StatsUser.objects.get(user=user)
        except ObjectDoesNotExist:
            wsrg =  WebsiteReportGroup(title="Summary of results for " + str(user))
            wsrg.save()
            stats = StatsUser(user=user, ws_report_group=wsrg)  
            stats.save()

        # Try to populate user information from shibboleth information
        if user.first_name == '' or user.last_name == '' or user.email == '':
            try:
                user.first_name = self.request.META['givenName']
                user.last_name  = self.request.META['sn']
                user.email      = self.request.META['mail']
                user.save()
            except:
                pass    

        self.url = SITE_URL

        return super(ShibbolethLogin, self).get_redirect_url(*args, **kwargs)