diff --git a/example/gae/auth/models.py b/example/gae/auth/models.py index beb8ad3..c7cab8f 100644 --- a/example/gae/auth/models.py +++ b/example/gae/auth/models.py @@ -99,12 +99,14 @@ def from_profile(cls, user, profile): if not user or user.is_anonymous(): email = profile.data.get("email") if not email: - logging.warning("Social connection could not provide email") - raise Exception(_("Social connection could not provide email")) + msg = "Cannot create new user, authentication provider did not not provide email" + logging.warning(msg) + raise Exception(_(msg)) conflict = User.query(User.email == email).get() if conflict: - msg = _("Cannot create new user, email {} is already used. Login and then connect external profile.") - raise Exception(msg.format(email)) + msg = _("Cannot create new user, email {} is already used. Login and then connect external profile.").format(email) + logging.warning(msg) + raise Exception(msg) now = datetime.now() user = User( diff --git a/example/gae/website/settings.py b/example/gae/website/settings.py index 48b7aa4..c0765e0 100644 --- a/example/gae/website/settings.py +++ b/example/gae/website/settings.py @@ -99,5 +99,6 @@ }, } +# Settings with secrets if PRODUCTION: from website.settings_prd import * diff --git a/example/sqla/auth/models.py b/example/sqla/auth/models.py index 50fb7e6..b8ceb39 100644 --- a/example/sqla/auth/models.py +++ b/example/sqla/auth/models.py @@ -67,6 +67,9 @@ def gravatar(self): encoded = hashlib.md5(email).hexdigest() return "https://secure.gravatar.com/avatar/%s.png" % encoded + def social_connections(self): + return SocialConnection.query.filter(SocialConnection.user_id == self.id).all() + # @login_manager.user_loader # def load_user(user_id): # return None #User.get(user_id) @@ -105,12 +108,14 @@ def from_profile(cls, user, profile): if not user or user.is_anonymous(): email = profile.data.get("email") if not email: - logging.warning("Social connection could not provide email") - raise Exception(_("Social connection could not provide email")) + msg = "Cannot create new user, authentication provider did not not provide email" + logging.warning(msg) + raise Exception(_(msg)) conflict = User.query.filter(User.email == email).first() if conflict: - msg = _("Cannot create new user, email {} is already used. Login and then connect external profile.") - raise Exception(msg.format(email)) + msg = _("Cannot create new user, email {} is already used. Login and then connect external profile.").format(email) + logging.warning(msg) + raise Exception(msg) now = datetime.now() user = User( diff --git a/example/sqla/auth/templates/User/profile.html b/example/sqla/auth/templates/User/profile.html index 4651988..1cb9bba 100644 --- a/example/sqla/auth/templates/User/profile.html +++ b/example/sqla/auth/templates/User/profile.html @@ -22,5 +22,34 @@

Hi {{ current_user.cn }}

Logout + {% with connections=current_user.social_connections() %} + {% if connections %} +
+
+

Connections

+ {% for connection in connections %} + + + + {% endfor %} + +
+
+ + {% endif %} + {% endwith %} +
+
+

Connect another account

+ +
+ + + + +
+ +
+
{% endblock %} diff --git a/example/sqla/db.sqlite b/example/sqla/db.sqlite index 2b3897f..4585252 100644 Binary files a/example/sqla/db.sqlite and b/example/sqla/db.sqlite differ diff --git a/example/sqla/main.py b/example/sqla/main.py index 8d8d318..9df2b5d 100644 --- a/example/sqla/main.py +++ b/example/sqla/main.py @@ -67,9 +67,9 @@ app.wsgi_app = DebuggedApplication(app.wsgi_app, True) if __name__ == "__main__": - # for coonvienience in setting up OAuth ids and secretes we use the example.com domain. + # for convenience in setting up OAuth ids and secretes we use the example.com domain. # This should allow you to circumvent limits put on localhost/127.0.0.1 usage - # Just map dev.example.com on 127.0.0.1 ip adress. + # Just map dev.example.com on 127.0.0.1 ip address. logging.debug("PRODUCTION: %s" % PRODUCTION) logging.debug("app.debug: %s" % app.debug) logging.debug("app.testing: %s" % app.testing) diff --git a/example/sqla/website/settings.py b/example/sqla/website/settings.py index a73ce88..75be9ca 100644 --- a/example/sqla/website/settings.py +++ b/example/sqla/website/settings.py @@ -68,22 +68,35 @@ # Flask-SocialBlueprint # https://github.com/wooyek/flask-social-blueprint SOCIAL_BLUEPRINT = { + # https://developers.facebook.com/apps/ "flask_social_blueprint.providers.Facebook": { + # App ID 'consumer_key': '197…', + # App Secret 'consumer_secret': 'c956c1…' }, + # https://apps.twitter.com/app/new "flask_social_blueprint.providers.Twitter": { + # Your access token from API Keys tab 'consumer_key': 'bkp…', + # access token secret 'consumer_secret': 'pHUx…' }, + # https://console.developers.google.com/project "flask_social_blueprint.providers.Google": { + # Client ID 'consumer_key': '797….apps.googleusercontent.com', + # Client secret 'consumer_secret': 'bDG…' }, + # https://github.com/settings/applications/new "flask_social_blueprint.providers.Github": { + # Client ID 'consumer_key': '6f6…', + # Client Secret 'consumer_secret': '1a9…' }, } -from website.settings_prd import * +# Settings with secrets +from website.settings_local import * diff --git a/setup.py b/setup.py index 5ac6fec..e6bb152 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,6 @@ # '': ['requirements.txt'] # }, - # metadata for upload to PyPI 'author': "Janusz Skonieczny", 'author_email': "js@bravelabs.pl", 'description': "An OAuth based authentication blueprint for flask. Easy to extend and override", diff --git a/src/flask_social_blueprint/__init__.py b/src/flask_social_blueprint/__init__.py index 3f4967b..8b45ebc 100644 --- a/src/flask_social_blueprint/__init__.py +++ b/src/flask_social_blueprint/__init__.py @@ -57,7 +57,6 @@ def no_connection(self, profile, provider): except Exception as ex: logging.warn(ex, exc_info=True) do_flash(_("Could not register: {}").format(ex.message), "warning") - abort(500) return self.login_failed_redirect(profile, provider) return self.login_connection(connection, profile, provider)