Exemplo n.º 1
0
def validate_user_identity(form, data):
    msg = _('Your account was migrated from the old P2PU website.')
    username_provided = ('username' in data and data['username'])
    if username_provided and drupal.get_user(data['username']):
        form._errors['username'] = forms.util.ErrorList([msg])
    email_provided = ('email' in data and data['email'])
    if email_provided and drupal.get_user(data['email']):
        form._errors['email'] = forms.util.ErrorList([msg])
Exemplo n.º 2
0
def validate_user_identity(form, data):
    msg = _("Your account was migrated from the old P2PU website.")
    username_provided = "username" in data and data["username"]
    if username_provided and drupal.get_user(data["username"]):
        form._errors["username"] = forms.util.ErrorList([msg])
    email_provided = "email" in data and data["email"]
    if email_provided and drupal.get_user(data["email"]):
        form._errors["email"] = forms.util.ErrorList([msg])
Exemplo n.º 3
0
def validate_user_identity(form, data):
    msg = _('Your account was migrated from the old P2PU website.')
    username_provided = ('username' in data and data['username'])
    if username_provided and drupal.get_user(data['username']):
        form._errors['username'] = forms.util.ErrorList([msg])
    email_provided = ('email' in data and data['email'])
    if email_provided and drupal.get_user(data['email']):
        form._errors['email'] = forms.util.ErrorList([msg])
Exemplo n.º 4
0
def validate_user_identity(form, data):
    drupal_user_msg = _(
        'You can login directly with your username and password from the old P2PU website.'
    )
    if 'username' in data and data['username'] and drupal.get_user(
            data['username']):
        form._errors['username'] = forms.util.ErrorList([drupal_user_msg])
    if 'email' in data and data['email'] and drupal.get_user(data['email']):
        form._errors['email'] = forms.util.ErrorList([drupal_user_msg])
Exemplo n.º 5
0
def validate_user_identity(form, data):
    drupal_user_msg = _(
        'You can login directly with your username and password from the old P2PU website.'
    )
    if 'username' in data and data['username'] and drupal.get_user(
            data['username']):
        form._errors['username'] = forms.util.ErrorList([drupal_user_msg])
    if 'email' in data and data['email'] and drupal.get_user(data['email']):
        form._errors['email'] = forms.util.ErrorList([drupal_user_msg])
Exemplo n.º 6
0
def validate_user_identity(form, data):
    drupal_user_msg = _('You can login directly with your credentials from the old P2PU website.')
    log.error("%s %s" % (type(data), repr(data)))
    if 'username' in data:
        log.error("Validate user identity: %s" % repr(data['username']))
    if 'username' in data and drupal.get_user(data['username']):
        form._errors['username'] = forms.util.ErrorList([drupal_user_msg])
    if 'email' in data and drupal.get_user(data['email']):
        form._errors['email'] = forms.util.ErrorList([drupal_user_msg])
Exemplo n.º 7
0
def validate_user_identity(form, data):
    drupal_user_msg = _(
        'You can login directly with your credentials from the old P2PU website.'
    )
    log.error("%s %s" % (type(data), repr(data)))
    if 'username' in data:
        log.error("Validate user identity: %s" % repr(data['username']))
    if 'username' in data and drupal.get_user(data['username']):
        form._errors['username'] = forms.util.ErrorList([drupal_user_msg])
    if 'email' in data and drupal.get_user(data['email']):
        form._errors['email'] = forms.util.ErrorList([drupal_user_msg])
Exemplo n.º 8
0
 def authenticate(self, username=None, password=None):
     log.debug("Attempting to authenticate drupal user %s" % (username, ))
     drupal_user = drupal.get_user(username)
     if drupal_user:
         try:
             profile = UserProfile.objects.get(username=drupal_user.name)
             log.debug("Drupal user already resgistered: %s" % (username, ))
             return None
         except UserProfile.DoesNotExist:
             if drupal.check_password(drupal_user, password):
                 username, email, full_name = drupal.get_user_data(
                     drupal_user)
                 try:
                     django_user = User(username=username[:30], email=email)
                     profile = create_profile(django_user,
                                              username=username)
                     profile.full_name = full_name
                     profile.set_password(password)
                     profile.save()
                     return profile.user
                 except IntegrityError:
                     return None
     else:
         log.debug("Drupal user does not exist: %s" % (username, ))
         return None
Exemplo n.º 9
0
 def authenticate(self, username=None, password=None):
     log.debug("Attempting to authenticate drupal user %s" % (username,))
     drupal_user = drupal.get_user(username)
     if drupal_user:
         try:
             profile = UserProfile.objects.get(username=drupal_user.name)
             log.debug("Drupal user already resgistered: %s" % (username,))
             return None
         except UserProfile.DoesNotExist:
             if drupal.check_password(drupal_user, password):
                 username, email, full_name = drupal.get_user_data(
                     drupal_user)
                 try:
                     django_user = User(username=username[:30], email=email)
                     profile = create_profile(django_user,
                         username=username)
                     profile.full_name = full_name
                     profile.set_password(password)
                     profile.save()
                     return profile.user
                 except IntegrityError:
                     return None
     else:
         log.debug("Drupal user does not exist: %s" % (username,))
         return None
Exemplo n.º 10
0
 def clean(self):
     super(EmailEditForm, self).clean()
     msg = _('That email address is register at p2pu.org under a different username.')
     data = self.cleaned_data
     if 'email' in data:
         drupal_user = drupal.get_user(data['email'])
         if drupal_user and self.username != drupal_user.name:
             self._errors['email'] = forms.util.ErrorList([msg])
     return data
Exemplo n.º 11
0
 def clean(self):
     super(EmailEditForm, self).clean()
     msg = _('That email address is register under a different username.')
     data = self.cleaned_data
     if 'email' in data:
         drupal_user = drupal.get_user(data['email'])
         if drupal_user and self.username != drupal_user.name:
             self._errors['email'] = forms.util.ErrorList([msg])
     return data
Exemplo n.º 12
0
 def clean(self):
     super(EmailEditForm, self).clean()
     msg = _('That email address is register under a different username.')
     data = self.cleaned_data
     if 'email' in data:
         drupal_user = drupal.get_user(data['email'])
         if drupal_user and self.username != drupal_user.name:
             self._errors['email'] = forms.util.ErrorList([msg])
         if data['email'] != data.get('email_confirm', data['email']):
             self._errors['email_confirm'] = forms.util.ErrorList([
                 _('Email addresses do not match.')])
     return data
Exemplo n.º 13
0
def check_username(request):
    """Validate a username and check for uniqueness."""
    username = request.GET.get('username', None)
    f = UsernameField()
    try:
        f.clean(username)
    except ValidationError:
        return http.HttpResponse()
    try:
        UserProfile.objects.get(username=username)
        return http.HttpResponse()
    except UserProfile.DoesNotExist:
        if drupal.get_user(username):
            return http.HttpResponse()
    return http.HttpResponse(status=404)
Exemplo n.º 14
0
def check_username(request):
    """Validate a username and check for uniqueness."""
    username = request.GET.get('username', None)
    f = UsernameField()
    try:
        f.clean(username)
    except ValidationError:
        return http.HttpResponse()
    try:
        UserProfile.objects.get(username=username)
        return http.HttpResponse()
    except UserProfile.DoesNotExist:
        if drupal.get_user(username):
            return http.HttpResponse()
    return http.HttpResponse(status=404)
Exemplo n.º 15
0
def get_past_courses(username):
    drupal_user = get_user(username)
    past_courses = []
    if drupal_user:
        og_uids = OgUid.objects.using(DRUPAL_DB).filter(uid=drupal_user.uid)
        for og_uid in og_uids:
            course = Node.objects.using(DRUPAL_DB).get(type=COURSE_TYPE, nid=og_uid.nid)
            ct_course = ContentTypeCourse.objects.using(DRUPAL_DB).get(nid=course.nid)
            if ct_course.field_course_status_value == COMPLETE_STATUS:
                url = settings.DRUPAL_URL + get_slug(course.nid)
                image_url = get_image_url(ct_course.field_course_photo_fid)
                data = {
                    'name': course.title,
                    'url': url,
                    'organizer': og_uid.is_admin,
                    'image_url': image_url,
                }
                past_courses.append(data)
    return past_courses
Exemplo n.º 16
0
def get_past_courses(username):
    drupal_user = get_user(username)
    past_courses = []
    if drupal_user:
        og_uids = OgUid.objects.using(DRUPAL_DB).filter(uid=drupal_user.uid)
        for og_uid in og_uids:
            course = Node.objects.using(DRUPAL_DB).get(type=COURSE_TYPE, nid=og_uid.nid)
            ct_course = ContentTypeCourse.objects.using(DRUPAL_DB).get(nid=course.nid)
            if ct_course.field_course_status_value == COMPLETE_STATUS:
                url = settings.DRUPAL_URL + get_slug(course.nid)
                image_url = get_image_url(ct_course.field_course_photo_fid)
                data = {
                    'name': course.title,
                    'url': url,
                    'organizer': og_uid.is_admin,
                    'image_url': image_url,
                }
                past_courses.append(data)
    return past_courses
Exemplo n.º 17
0
 def authenticate(self, username=None, password=None):
     log.debug("Attempting to authenticate drupal user %s" % (username,))
     drupal_user = drupal.get_user(username)
     if drupal_user:
         try:
             profile = UserProfile.objects.get(username=drupal_user.name)
             log.debug("Drupal user resgistered already: %s" % (username,))
             return None
         except UserProfile.DoesNotExist:
             if drupal.check_password(drupal_user, password):
                 user_data = drupal.get_user_data(drupal_user)
                 profile = UserProfile(**user_data)
                 profile.set_password(password)
                 profile.save()
                 if profile.user is None:
                     profile.create_django_user()
                 return profile.user
     else:
         log.debug("Drupal user does not exist: %s" % (username,))
         return None