예제 #1
0
파일: users.py 프로젝트: waleedusman/orams
def send_invite(token):
    """Send invite
    ---
    tags:
      - auth
    consumes:
      - application/json
    parameters:
      - name: token
        in: path
        type: string
        required: true
        default: all
    responses:
      200:
        description: Email address
        type: object
        properties:
          email_address:
            type: string
          name:
            type: string
    """
    try:
        data = decode_creation_token(token.encode())
        email_address = data.get('email_address', None)
        name = data.get('name', None)
        framework = data.get('framework', 'digital-marketplace')
        user_type = data.get('user_type', None)
        send_account_activation_email(name, email_address, user_type,
                                      framework)
        return jsonify(email_address=email_address, name=name), 200
    except InvalidToken:
        return jsonify(
            message='An error occured when trying to send an email'), 400
예제 #2
0
def send_invite(token):
    """Send invite
    ---
    tags:
      - auth
    consumes:
      - application/json
    parameters:
      - name: e
        in: query
        type: string
        required: true
        description: URL encoded email address
      - name: token
        in: path
        type: string
        required: true
        default: all
    responses:
      200:
        description: Email address
        type: object
        properties:
          email_address:
            type: string
          name:
            type: string
    """
    email_address_encoded = request.args.get('e') or ''
    if not email_address_encoded:
        return jsonify(
            message=
            'You must provide an email address when validating a new account'
        ), 400
    email_address = unquote_plus(email_address_encoded)
    claim = user_claims_service.find(type='signup',
                                     token=token,
                                     email_address=email_address,
                                     claimed=False).one_or_none()
    if not claim:
        return jsonify(message='Invalid token'), 400
    name = claim.data.get('name', None)
    framework = claim.data.get('framework', 'digital-marketplace')
    user_type = claim.data.get('user_type', None)
    send_account_activation_email(token, email_address, framework)
    return jsonify(email_address=email_address, name=name), 200
예제 #3
0
def signup():
    """Signup user
    ---
    tags:
      - auth
    consumes:
      - application/json
    parameters:
      - name: body
        in: body
        required: true
        schema:
          id: SignupUser
          required:
            - name
            - email_address
            - user_type
          properties:
            name:
              type: string
            email_address:
              type: string
            user_type:
              type: string
            employment_status:
              type: string
            line_manager_name:
              type: string
            line_manager_email:
              type: string
            framework:
              type: string
    responses:
      200:
        description: User
        schema:
          $ref: '#/definitions/UserInfo'
    """
    json_payload = request.get_json()
    name = json_payload.get('name', None)
    email_address = json_payload.get('email_address', None)
    user_type = json_payload.get('user_type', None)
    employment_status = json_payload.get('employment_status', None)
    line_manager_name = json_payload.get('line_manager_name', None)
    line_manager_email = json_payload.get('line_manager_email', None)
    framework = json_payload.get('framework', 'digital-marketplace')

    user = User.query.filter(
        User.email_address == email_address.lower()).first()

    if user is not None:
        send_user_existing_password_reset_email(user.name, email_address)
        return jsonify(
            email_address=email_address,
            message="Email invite sent successfully"
        ), 200

    if user_type == 'seller' or user_type == 'applicant':
        if is_duplicate_user(email_address):
            return jsonify(
                email_address=email_address,
                message='An account with this email domain already exists'
            ), 409

    if user_type == 'buyer' and not has_whitelisted_email_domain(get_email_domain(email_address)):
        return jsonify(
            email_address=email_address,
            message="A buyer account must have a valid government entity email domain"
        ), 403

    user_data = {
        'name': name,
        'user_type': user_type,
        'framework': framework,
        'employment_status': employment_status
    }
    claim = user_claims_service.make_claim(type='signup', email_address=email_address, data=user_data)
    if not claim:
        return jsonify(message="There was an issue completing the signup process."), 500

    publish_tasks.user_claim.delay(
        publish_tasks.compress_user_claim(claim),
        'created'
    )

    if employment_status == 'contractor':
        try:
            send_account_activation_manager_email(
                token=claim.token,
                manager_name=line_manager_name,
                manager_email=line_manager_email,
                applicant_name=name,
                applicant_email=email_address,
                framework=framework
            )
            return jsonify(
                email_address=email_address,
                message="Email invite sent successfully"
            ), 200

        except EmailError:
            return jsonify(message='An error occured when trying to send an email'), 500

    if employment_status == 'employee' or user_type == 'seller':
        try:
            send_account_activation_email(
                token=claim.token,
                email_address=email_address,
                framework=framework
            )
            return jsonify(
                email_address=email_address,
                message="Email invite sent successfully"
            ), 200

        except EmailError:
            return jsonify(
                email_address=email_address,
                message='An error occured when trying to send an email'
            ), 500

    else:
        return jsonify(
            email_address=email_address,
            message='An error occured when trying to send an email'
        ), 400
예제 #4
0
파일: users.py 프로젝트: waleedusman/orams
def signup():
    """Signup user
    ---
    tags:
      - auth
    consumes:
      - application/json
    parameters:
      - name: body
        in: body
        required: true
        schema:
          id: SignupUser
          required:
            - name
            - email_address
            - user_type
          properties:
            name:
              type: string
            email_address:
              type: string
            user_type:
              type: string
            employment_status:
              type: string
            line_manager_name:
              type: string
            line_manager_email:
              type: string
            framework:
              type: string
    responses:
      200:
        description: User
        schema:
          $ref: '#/definitions/UserInfo'
    """
    json_payload = request.get_json()
    name = json_payload.get('name', None)
    email_address = json_payload.get('email_address', None)
    user_type = json_payload.get('user_type', None)
    employment_status = json_payload.get('employment_status', None)
    line_manager_name = json_payload.get('line_manager_name', None)
    line_manager_email = json_payload.get('line_manager_email', None)
    framework = json_payload.get('framework', 'digital-marketplace')

    user = User.query.filter(
        User.email_address == email_address.lower()).first()

    if user is not None:
        return jsonify(
            email_address=email_address,
            message="A user with the email address '{}' already exists".format(
                email_address)), 409

    if user_type == 'seller' or user_type == 'applicant':
        if is_duplicate_user(email_address):
            return jsonify(
                email_address=email_address,
                message='An account with this email domain already exists'
            ), 409

    # New ORAMS users don't need their email domain checked as that's done manually
    if framework == 'orams':
        try:
            orams_send_account_activation_admin_email(name, email_address,
                                                      framework)
            return jsonify(email_address=email_address,
                           message="Email invite sent successfully"), 200

        except EmailError:
            return jsonify(
                message='An error occured when trying to send an email'), 500

    if user_type == 'buyer' and not has_whitelisted_email_domain(
            get_email_domain(email_address)):
        return jsonify(
            email_address=email_address,
            message=
            "A buyer account must have a valid government entity email domain"
        ), 403

    if employment_status == 'contractor':
        try:
            send_account_activation_manager_email(
                manager_name=line_manager_name,
                manager_email=line_manager_email,
                applicant_name=name,
                applicant_email=email_address,
                framework=framework)
            return jsonify(email_address=email_address,
                           message="Email invite sent successfully"), 200

        except EmailError:
            return jsonify(
                message='An error occured when trying to send an email'), 500

    if employment_status == 'employee' or user_type == 'seller':
        try:
            send_account_activation_email(name=name,
                                          email_address=email_address,
                                          user_type=user_type,
                                          framework=framework)
            return jsonify(email_address=email_address,
                           message="Email invite sent successfully"), 200

        except EmailError:
            return jsonify(
                email_address=email_address,
                message='An error occured when trying to send an email'), 500

    else:
        return jsonify(
            email_address=email_address,
            message='An error occured when trying to send an email'), 400