Exemple #1
0
    def loadUser(self, username, password):
        from auth import User

        try:

            api = WaApiClient(self.getSetting('Client ID'),
                              self.getSetting('Client secret'))

            api.authenticate_with_contact_credentials(username, password)
            contact = api.execute_request('Contacts/me')

            id = contact['Id']

            user = User(username)
            user.id = id
            user.groups = []
            user.firstName = contact['FirstName']
            user.lastName = contact['LastName']

            contact = api.execute_request('Contacts/' + str(id))

            fieldValues = contact['FieldValues']

            approved = False

            groupList = []
            for fieldValueItem in fieldValues:
                if fieldValueItem['FieldName'] == 'Group participation':
                    groupList = fieldValueItem['Value']
                    break

            for group in groupList:
                user.groups.append(group['Label'])

            logger.debug(f"Authenticating {username}")
            logger.debug(user.groups)
            return user
        except HTTPError as err:
            logger.debug("HTTPError Validating User: "******"Unhandled Error Validating User:", exc_info=True)
            raise

        return None
Exemple #2
0
def login():
    if request.method == 'GET':
        return '''
               <form action='login' method='POST'>
                <input type='text' name='email' id='email' placeholder='email'></input>
                <input type='password' name='pw' id='pw' placeholder='password'></input>
                <input type='submit' name='submit'></input>
               </form>
               '''

    email = request.form['email']
    if request.form['pw'] == users[email]['pw']:
        user = User()
        user.id = email
        flask_login.login_user(user)
        return redirect(url_for('protected'))

    return 'Bad login'