Exemplo n.º 1
0
def create():
    form = UserForm()
    if form.validate():
        if not _is_email_address_valid(form.email.data):
            return jsonify({'email': ['Email address is already in use']}), 400

        new_user = form.data
        add_token_data(new_user)
        if form.company.data:
            new_user['company'] = ObjectId(form.company.data)
        get_resource_service('users').post([new_user])
        send_token(new_user, token_type='new_account')
        return jsonify({'success': True}), 201
    return jsonify(form.errors), 400
Exemplo n.º 2
0
def create():
    form = UserForm()
    if form.validate():
        if not _is_email_address_valid(form.email.data):
            return jsonify({'email': ['Email address is already in use']}), 400

        new_user = form.data
        add_token_data(new_user)
        if form.company.data:
            new_user['company'] = ObjectId(form.company.data)

        # Flask form won't accept default value if any form data was passed in the request.
        # So, we need to set this explicitly here.
        new_user['receive_email'] = True

        get_resource_service('users').post([new_user])
        send_token(new_user, token_type='new_account')
        return jsonify({'success': True}), 201
    return jsonify(form.errors), 400
Exemplo n.º 3
0
def _resend_token(user_id, token_type):
    """
    Sends a new token for a given user_id
    :param user_id: Id of the user to send the token
    :param token_type: validate or reset_password
    :return:
    """
    if not user_id:
        return BadRequest(gettext('User id not provided'))

    user = find_one('users', _id=ObjectId(user_id))

    if not user:
        return NotFound(gettext('User not found'))

    if send_token(user, token_type):
        return jsonify({'success': True}), 200

    return jsonify({'message': 'Token could not be sent'}), 400