Beispiel #1
0
def handle_bloomberg_response():
    sso_settings = current_app.config.get('BSSO_SETTINGS')
    auth = OneLogin_Saml2_Auth(prepare_onelogin_request(), sso_settings)
    auth.process_response()
    errors = auth.get_errors()
    if errors:
        # BSSO was unable to authenticate the user
        error_reason = auth.get_last_error_reason()
        current_app.logger.error('BSSO auth error(s): %s %s', errors,
                                 error_reason)
        flash(gettext('There was a problem during the sign in process.'),
              'error')
        return redirect(url_for('home.home'))
    elif auth.is_authenticated:
        # User is authenticated on BSSO, load user from GIGwork API.
        attributes = auth.get_attributes()
        user = user_repo.get_by(
            email_addr=unicode(attributes['emailAddress'][0]).lower())
        if user is not None:
            # User is authenticated on BSSO and already has a GIGwork account.
            return _sign_in_user(user, next_url=request.form.get('RelayState'))
        else:
            # User is authenticated on BSSO, but does not yet have a GIGwork account, auto create one.
            user_data = {}
            try:
                user_data['fullname'] = attributes['firstName'][
                    0] + " " + attributes['lastName'][0]
                user_data['email_addr'] = attributes['emailAddress'][0]
                user_data['name'] = attributes['username'][0]
                user_data['data_access'] = ["L4"]
                user_data['password'] = generate_password()
                create_account(user_data, auto_create=True)
                flash('A new account has been created for you using BSSO.')
                user = user_repo.get_by(
                    email_addr=unicode(user_data['email_addr'].lower()))
                return _sign_in_user(user,
                                     next_url=request.form.get('RelayState'))
            except Exception as error:
                brand = current_app.config['BRAND']
                current_app.logger.exception(
                    'Auto-account creation error: %s, for user attributes: %s',
                    error, attributes)
                flash(
                    gettext(
                        'There was a problem signing you in. Please contact your {} administrator.'
                        .format(brand)), 'error')
                return redirect(url_for('home.home'))
    else:
        # Failed to authenticate user on BSSO.
        current_app.logger.exception('BSSO login error')
        flash(
            gettext(
                'We were unable authenticate and log you into an account. Please contact a Gigwork administrator.'
            ), 'error')
        return redirect(url_for('home.home'))
Beispiel #2
0
 def generate_password(self):
     if self.data['password']:
         return
     password = util.generate_password()
     self.password.data = password
     self.confirm.data = password