Add Discourse auth
This commit is contained in:
parent
fa8d68ad52
commit
77def611cc
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
BIN
webclient/public/discourselogo.png
Normal file
BIN
webclient/public/discourselogo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 5.7 KiB |
|
@ -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) {
|
|||
|
||||
<p>would like to request Spaceport authentication.</p>
|
||||
|
||||
<p>URL: <a href='http://wiki.protospace.ca/Welcome_to_Protospace' target='_blank' rel='noopener noreferrer'>wiki.protospace.ca</a></p>
|
||||
<p>URL: <a href='https://wiki.protospace.ca/Welcome_to_Protospace' target='_blank' rel='noopener noreferrer'>wiki.protospace.ca</a></p>
|
||||
|
||||
<AuthForm user={user}>
|
||||
<Header size='small'>Success!</Header>
|
||||
<p>You can now log into the wiki:</p>
|
||||
<p><a href='http://wiki.protospace.ca/index.php?title=Special:UserLogin&returnto=Welcome+to+Protospace' rel='noopener noreferrer'>Protospace Wiki</a></p>
|
||||
<p>You can now log into the Wiki:</p>
|
||||
<p>
|
||||
Username: {user.username}<br/>
|
||||
Password: [this Spaceport password]
|
||||
</p>
|
||||
<p><a href='https://wiki.protospace.ca/index.php?title=Special:UserLogin&returnto=Welcome+to+Protospace' rel='noopener noreferrer'>Protospace Wiki</a></p>
|
||||
</AuthForm>
|
||||
</Segment>
|
||||
);
|
||||
}
|
||||
|
||||
export function AuthDiscourse(props) {
|
||||
const { user } = props;
|
||||
|
||||
return (
|
||||
<Segment compact padded>
|
||||
<Header size='medium'>
|
||||
<Image src={'/discourselogo.png'} />
|
||||
Protospace Discourse
|
||||
</Header>
|
||||
|
||||
<p>would like to request Spaceport authentication.</p>
|
||||
|
||||
<p>URL: <a href='https://forum.protospace.ca' target='_blank' rel='noopener noreferrer'>forum.protospace.ca</a></p>
|
||||
|
||||
<AuthForm user={user}>
|
||||
<Header size='small'>Success!</Header>
|
||||
<p>You can now log into the Discourse:</p>
|
||||
<p>
|
||||
Username: {user.username}<br/>
|
||||
Password: [this Spaceport password]
|
||||
</p>
|
||||
<p><a href='https://forum.protospace.ca' rel='noopener noreferrer'>Protospace Discourse</a></p>
|
||||
</AuthForm>
|
||||
</Segment>
|
||||
);
|
||||
|
@ -127,6 +158,10 @@ export function Auth(props) {
|
|||
<Route path='/auth/wiki'>
|
||||
<AuthWiki user={user} />
|
||||
</Route>
|
||||
|
||||
<Route path='/auth/discourse'>
|
||||
<AuthDiscourse user={user} />
|
||||
</Route>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user