コード例 #1
0
 def oauth_authorized(service_provider_name):
     session_user = get_current_user()
     try:
         current_provider = providers.get_by_name(service_provider_name)
         token, secret = current_provider.get_access_tokens()
         fresh_user = get_user_by_token(current_provider, token, secret)
         if session_user is not None:
             if fresh_user.id == session_user.id:
                 flash('This provider was already linked to this account.')
             else:
                 flash('Merging accounts is not currently supported.')
         else:
             log_user_in(fresh_user)
     except ServiceProviderNotFound:
         flash('Provider not found.')
     except UserDeniedRequest:
         flash('You denied us access.')
     except UserNotFound:
         if session_user is None:
             try:
                 user = get_user_by_remote_id(current_provider, token=(token,secret))
             except UserNotFound:
                 user = create_user()
             log_user_in(user)
         add_SP_to_user_by_id(
             get_current_user().id, current_provider, token, secret)
     next_url = request.args.get('next') or url_for('show_user')
     return redirect(next_url)
コード例 #2
0
    def test_add_sp_to_user_by_id(self):
        user_created = uf.create_user()
        uf.add_SP_to_user_by_id(user_created.id, sp, 'test', 'test')

        self.assertEqual(1, UserSPAccess.query.count())
        self.assertEqual(1, User.query.join(UserSPAccess).count())
コード例 #3
0
    def test_add_sp_to_user(self):
        user_created = uf.create_user()
        self.assertEqual(0, UserSPAccess.query.count())

        uf.add_SP_to_user(user_created, sp, 'test', 'test')
        self.assertEqual(1, UserSPAccess.query.count())
コード例 #4
0
    def test_get_user_by_tokens(self):
        user_created = uf.create_user()
        uf.add_SP_to_user(user_created, sp, 'test', 'test')

        user_retrieved = uf.get_user_by_token(sp, 'test', 'test')
        self.assertEqual(user_created, user_retrieved)
コード例 #5
0
 def test_add_user(self):
     uf.create_user()
     
     self.assertEqual(1, User.query.count())
     self.assertEqual(0, UserSPAccess.query.count())
コード例 #6
0
 def create_user(self):
     result = create_user(self.body['data'])
     return {
         'statusCode': result['statusCode'],
         'body': result['response']
     }
コード例 #7
0
 def test_create_user(self):
     response = create_user(user_object)
     jwt = response['response']
     self.assertEqual(response['statusCode'], 200)
     response = validate_email(my_email, jwt)
     self.assertEqual(response['statusCode'], 200)