diff --git a/apiserver/apiserver/api/serializers.py b/apiserver/apiserver/api/serializers.py index c769574..c4f857e 100644 --- a/apiserver/apiserver/api/serializers.py +++ b/apiserver/apiserver/api/serializers.py @@ -561,11 +561,20 @@ class MyPasswordChangeSerializer(PasswordChangeSerializer): data = dict( username=self.user.username, password=self.data['new_password1'], + email=self.user.email, + first_name=self.user.member.first_name, ) if utils_auth.wiki_is_configured(): if utils_auth.set_wiki_password(data) != 200: - msg = 'Problem connecting to Auth server: set.' + msg = 'Problem connecting to Wiki Auth server: set.' + utils.alert_tanner(msg) + logger.info(msg) + raise ValidationError(dict(non_field_errors=msg)) + + if utils_auth.discourse_is_configured(): + if utils_auth.set_discourse_password(data) != 200: + msg = 'Problem connecting to Discourse Auth server: set.' utils.alert_tanner(msg) logger.info(msg) raise ValidationError(dict(non_field_errors=msg)) @@ -602,11 +611,20 @@ class MyPasswordResetConfirmSerializer(PasswordResetConfirmSerializer): data = dict( username=self.user.username, password=self.data['new_password1'], + email=self.user.email, + first_name=self.user.member.first_name, ) if utils_auth.wiki_is_configured(): if utils_auth.set_wiki_password(data) != 200: - msg = 'Problem connecting to Auth server: set.' + msg = 'Problem connecting to Wiki Auth server: set.' + utils.alert_tanner(msg) + logger.info(msg) + raise ValidationError(dict(non_field_errors=msg)) + + if utils_auth.discourse_is_configured(): + if utils_auth.set_discourse_password(data) != 200: + msg = 'Problem connecting to Discourse Auth server: set.' utils.alert_tanner(msg) logger.info(msg) raise ValidationError(dict(non_field_errors=msg)) @@ -653,10 +671,14 @@ class HistorySerializer(serializers.ModelSerializer): class SpaceportAuthSerializer(LoginSerializer): def authenticate(self, **kwargs): - result = super().authenticate(**kwargs) + user = super().authenticate(**kwargs) + + if user: + data = self.context['request'].data.copy() + data['email'] = user.email + data['first_name'] = user.member.first_name - if result: - data = self.context['request'].data utils_auth.set_wiki_password(data) + utils_auth.set_discourse_password(data) - return result + return user diff --git a/apiserver/apiserver/api/utils_auth.py b/apiserver/apiserver/api/utils_auth.py index 6a6f1a2..98481ec 100644 --- a/apiserver/apiserver/api/utils_auth.py +++ b/apiserver/apiserver/api/utils_auth.py @@ -9,6 +9,9 @@ from apiserver.api import utils def wiki_is_configured(): return bool(secrets.WIKI_AUTH_API_URL and secrets.AUTH_API_KEY) +def discourse_is_configured(): + return bool(secrets.DISCOURSE_AUTH_API_URL and secrets.AUTH_API_KEY) + def auth_api(url, data): try: @@ -25,3 +28,12 @@ def set_wiki_password(data): password=data['password'], ) return auth_api(secrets.WIKI_AUTH_API_URL + 'set-wiki-password', auth_data) + +def set_discourse_password(data): + auth_data = dict( + username=data['username'], + password=data['password'], + first_name=data['first_name'], + email=data['email'], + ) + return auth_api(secrets.DISCOURSE_AUTH_API_URL + 'set-discourse-password', auth_data) diff --git a/apiserver/apiserver/secrets.py.example b/apiserver/apiserver/secrets.py.example index 1cf694e..0827e23 100644 --- a/apiserver/apiserver/secrets.py.example +++ b/apiserver/apiserver/secrets.py.example @@ -45,6 +45,11 @@ LDAP_API_KEY = '' # with trailing slash WIKI_AUTH_API_URL = '' +# Discourse Auth API url +# should contain the IP and port of the script and machine connected over VPN +# with trailing slash +DISCOURSE_AUTH_API_URL = '' + # Auth API key # should be equal to the auth token value set in # spaceport/authserver/secrets.py diff --git a/webclient/public/discourselogo.png b/webclient/public/discourselogo.png new file mode 100644 index 0000000..294285f Binary files /dev/null and b/webclient/public/discourselogo.png differ diff --git a/webclient/public/wikilogo.png b/webclient/public/wikilogo.png index 228f352..e0763ee 100644 Binary files a/webclient/public/wikilogo.png and b/webclient/public/wikilogo.png differ diff --git a/webclient/src/Auth.js b/webclient/src/Auth.js index dabeecc..755c5ad 100644 --- a/webclient/src/Auth.js +++ b/webclient/src/Auth.js @@ -18,7 +18,7 @@ export function AuthForm(props) { const handleSubmit = (e) => { if (input.username.includes('@')) { - setError({ username: 'Username, not email.' }); + setError({ username: 'Spaceport username, not email.' }); } else { if (loading) return; setLoading(true); @@ -104,12 +104,43 @@ export function AuthWiki(props) {

would like to request Spaceport authentication.

-

URL: wiki.protospace.ca

+

URL: wiki.protospace.ca

Success!
-

You can now log into the wiki:

-

Protospace Wiki

+

You can now log into the Wiki:

+

+ Username: {user.username}
+ Password: [this Spaceport password] +

+

Protospace Wiki

+
+ + ); +} + +export function AuthDiscourse(props) { + const { user } = props; + + return ( + +
+ + Protospace Discourse +
+ +

would like to request Spaceport authentication.

+ +

URL: forum.protospace.ca

+ + +
Success!
+

You can now log into the Discourse:

+

+ Username: {user.username}
+ Password: [this Spaceport password] +

+

Protospace Discourse

); @@ -127,6 +158,10 @@ export function Auth(props) { + + + + ); }