Beispiel #1
0
    def handle(self, *args, **options):
        if len(args) != 3:
            raise CommandError("Invalid number of arguments")

        email, first_name, last_name = args[:3]

        password = options['password'] or \
            AstakosUser.objects.make_random_password()

        try:
            validate_email(email)
        except ValidationError:
            raise CommandError("Invalid email")

        has_signed_terms = not (get_latest_terms())

        try:
            user = make_local_user(email,
                                   first_name=first_name,
                                   last_name=last_name,
                                   password=password,
                                   has_signed_terms=has_signed_terms)
            if options['is_superuser']:
                user.is_superuser = True
                user.save()

        except BaseException, e:
            raise CommandError(e)
Beispiel #2
0
    def handle(self, *args, **options):
        if len(args) != 3:
            raise CommandError("Invalid number of arguments")

        email, first_name, last_name = args[:3]

        password = options['password'] or \
            AstakosUser.objects.make_random_password()

        try:
            validate_email(email)
        except ValidationError:
            raise CommandError("Invalid email")

        has_signed_terms = not(get_latest_terms())

        try:
            user = make_local_user(
                email, first_name=first_name, last_name=last_name,
                password=password, has_signed_terms=has_signed_terms)
            if options['is_superuser']:
                user.is_superuser = True
                user.save()

        except BaseException, e:
            raise CommandError(e)
Beispiel #3
0
def users_create(request):
    user_id = request.user_uniq
    req = api.utils.get_json_body(request)
    logger.info('users_create: %s request: %s', user_id, req)

    user_data = req.get('user', {})
    email = user_data.get('username', None)

    first_name = user_data.get('first_name', None)
    last_name = user_data.get('last_name', None)
    affiliation = user_data.get('affiliation', None)
    password = user_data.get('password', None)
    metadata = user_data.get('metadata', {})

    password_gen = AstakosUser.objects.make_random_password
    if not password:
        password = password_gen()

    try:
        validate_email(email)
    except ValidationError:
        raise faults.BadRequest("Invalid username (email format required)")

    if AstakosUser.objects.verified_user_exists(email):
        raise faults.Conflict("User '%s' already exists" % email)

    if not first_name:
        raise faults.BadRequest("Invalid first_name")

    if not last_name:
        raise faults.BadRequest("Invalid last_name")

    has_signed_terms = True

    try:
        user = make_local_user(email, first_name=first_name,
                               last_name=last_name, password=password,
                               has_signed_terms=has_signed_terms)
        if metadata:
            # we expect a unique local auth provider for the user
            provider = user.auth_providers.get()
            provider.info = metadata
            provider.affiliation = affiliation
            provider.save()

        user = AstakosUser.objects.get(pk=user.pk)
        code = user.verification_code
        ver_res = activation_backend.handle_verification(user, code)
        if ver_res.is_error():
            raise Exception(ver_res.message)

        # in case of auto moderation user moderation is handled within the
        # verification process, no need to reapply moderation process
        if not user.moderated:
            mod_res = activation_backend.handle_moderation(user, accept=True)
            if mod_res.is_error():
                raise Exception(ver_res.message)

    except Exception, e:
        raise faults.BadRequest(e.message)
Beispiel #4
0
def new_user():
    email = random_email()
    backend = activation_backends.get_backend()
    try:
        AstakosUser.objects.get(email=email)
        return None
    except AstakosUser.DoesNotExist:
        u = auth.make_local_user(email, first_name=random_name(),
                                 last_name=random_name())
        backend.verify_user(u, u.verification_code)
        backend.accept_user(u)
        return u
Beispiel #5
0
    def create_user(self):
        try:
            data = self.cleaned_data
        except AttributeError:
            self.is_valid()
            data = self.cleaned_data

        user = auth.make_local_user(
            email=data['email'], password=data['password1'],
            first_name=data['first_name'], last_name=data['last_name'],
            has_signed_terms=True)
        return user
Beispiel #6
0
    def create_user(self):
        try:
            data = self.cleaned_data
        except AttributeError:
            self.is_valid()
            data = self.cleaned_data

        user = auth.make_local_user(
            email=data['email'], password=data['password1'],
            first_name=data['first_name'], last_name=data['last_name'],
            has_signed_terms=True)
        return user
Beispiel #7
0
def new_user():
    email = random_email()
    backend = activation_backends.get_backend()
    try:
        AstakosUser.objects.get(email=email)
        return None
    except AstakosUser.DoesNotExist:
        u = auth.make_local_user(email, first_name=random_name(),
                                 last_name=random_name())
        backend.verify_user(u, u.verification_code)
        backend.accept_user(u)
        return u
Beispiel #8
0
def get_local_user(username, **kwargs):
    try:
        return AstakosUser.objects.get(email=username)
    except:
        user = auth_functions.make_local_user(email=username,
                                              has_signed_terms=True)
        user.set_password(kwargs.pop('password', 'password'))

        for key, value in kwargs.iteritems():
            setattr(user, key, value)
        user.save()

        if kwargs.get("is_active", True):
            backend = activation_backends.get_backend()
            backend.verify_user(user, user.verification_code)
            backend.accept_user(user)

        return user
Beispiel #9
0
def get_local_user(username, **kwargs):
    try:
        return AstakosUser.objects.get(email=username)
    except:
        user = auth_functions.make_local_user(email=username,
                                              has_signed_terms=True)
        user.set_password(kwargs.pop('password', 'password'))

        for key, value in kwargs.iteritems():
            setattr(user, key, value)
        user.save()

        if kwargs.get("is_active", True):
            backend = activation_backends.get_backend()
            backend.verify_user(user, user.verification_code)
            backend.accept_user(user)

        return user
Beispiel #10
0
 def setUp(self):
     """Common setup method for this test suite."""
     self.user1 = make_local_user("*****@*****.**")
Beispiel #11
0
 def good_transaction(self):
     make_local_user("*****@*****.**")
Beispiel #12
0
 def setUp(self):
     """Common setup method for this test suite."""
     self.user1 = make_local_user("*****@*****.**")
Beispiel #13
0
def users_create(request):
    user_id = request.user_uniq
    req = api.utils.get_json_body(request)
    logger.info('users_create: %s request: %s', user_id, req)

    user_data = req.get('user', {})
    email = user_data.get('username', None)

    first_name = user_data.get('first_name', None)
    last_name = user_data.get('last_name', None)
    affiliation = user_data.get('affiliation', None)
    password = user_data.get('password', None)
    metadata = user_data.get('metadata', {})

    password_gen = AstakosUser.objects.make_random_password
    if not password:
        password = password_gen()

    try:
        validate_email(email)
    except ValidationError:
        raise faults.BadRequest("Invalid username (email format required)")

    if AstakosUser.objects.verified_user_exists(email):
        raise faults.Conflict("User '%s' already exists" % email)

    if not first_name:
        raise faults.BadRequest("Invalid first_name")

    if not last_name:
        raise faults.BadRequest("Invalid last_name")

    has_signed_terms = True

    try:
        user = make_local_user(email,
                               first_name=first_name,
                               last_name=last_name,
                               password=password,
                               has_signed_terms=has_signed_terms)
        if metadata:
            # we expect a unique local auth provider for the user
            provider = user.auth_providers.get()
            provider.info = metadata
            provider.affiliation = affiliation
            provider.save()

        user = AstakosUser.objects.get(pk=user.pk)
        code = user.verification_code
        ver_res = user_logic.verify(user, code)
        if ver_res.is_error():
            raise Exception(ver_res.message)

        # in case of auto moderation user moderation is handled within the
        # verification process, no need to reapply moderation process
        if not user.moderated:
            mod_res = user_logic.accept(user, accept=True, notify_user=False)
            if mod_res.is_error():
                raise Exception(ver_res.message)

    except Exception, e:
        raise faults.BadRequest(e.message)
Beispiel #14
0
 def setUp(self):
     """Common setup method for this test suite."""
     with transaction.atomic():
         self.user1 = make_local_user("*****@*****.**")
Beispiel #15
0
 def setUp(self):
     """Common setup method for this test suite."""
     with transaction.atomic():
         self.user1 = make_local_user("*****@*****.**")
Beispiel #16
0
 def good_transaction(self):
     make_local_user("*****@*****.**")