Exemplo n.º 1
0
    def collection_post(self):
        """Create a new user."""

        param = NewUser({'name': self.request.validated['username'],
                         'password': self.request.validated['password']})
        try:
            user = User.create(param)
        except Exception as exc:
            raise AuthenticationError(exc.message)
        log.info('Created user {} with name {}'.
                 format(user.user_id, user.name))
        user_url = self.request.route_path('User', user_id=user.user_id)
        self.request.response.location = user_url.encode('utf-8')
        return {'location': user_url}
Exemplo n.º 2
0
def create_user(**kwargs):

    from caliopen.base.user.core import User
    from caliopen.base.user.parameters import NewUser
    from caliopen.base.user.parameters import NewContact
    param = NewUser()
    param.name = kwargs['email']
    param.password = kwargs['password']
    contact = NewContact()
    contact.given_name = kwargs.get('given_name')
    contact.family_name = kwargs.get('family_name')
    param.contact = contact
    user = User.create(param)
    user.save()
    log.info('User %s (%s) created' % (user.user_id, user.user_name))
Exemplo n.º 3
0
def validate_signup_params(username, email, password, password_repeat, given_name='', family_name=''):
    """Retrieve matching username and password.
    If no match is found, then return errors.

    @param string username
    @param string password
    @return Authentication
    """
    creation = namedtuple('Creation', ['success', 'user', 'errors'])
    errors = {
            'globals': [],
            'given_name': [],
            'family_name': [],
            'username': [],
            'password': [],
            'password_repeat': []
        }

    # validate user input
    has_error = False;
    if not password == password_repeat:
        errors['password_repeat'].append(messages['password_missmatch'])
        has_error = True

    # if an error occurred, then return the failed attempt
    if has_error:
        return creation(success=False, errors=errors, user=None)

    # create the user from parameters
    try:
        param = NewUser()
        param.name = email
        param.password = password
        contact = NewContact()
        contact.given_name = given_name
        contact.family_name = family_name
        param.contact = contact
        user = User.create(param)
        user.save()
        user = user.to_api()
        return  creation(success=True, user=user, errors=None)

    except (KeyError, Exception), exc:
        # prepare errors
        errors['globals'].append(str(exc))
        return creation(success=False, errors=errors, user=None)