Discourse check if user exists before creating account
This commit is contained in:
parent
4aee074527
commit
7bbfb05065
|
@ -202,6 +202,9 @@ def set_discourse_password(username, password, first_name, email):
|
||||||
abort(400)
|
abort(400)
|
||||||
|
|
||||||
|
|
||||||
|
user_exists = username in discourse_usernames
|
||||||
|
|
||||||
|
if not user_exists:
|
||||||
logger.info('Creating Discourse user for: ' + username)
|
logger.info('Creating Discourse user for: ' + username)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
|
@ -211,16 +214,17 @@ def set_discourse_password(username, password, first_name, email):
|
||||||
'email': email,
|
'email': email,
|
||||||
'active': True,
|
'active': True,
|
||||||
'approved': True,
|
'approved': True,
|
||||||
'user_fields[10]': 'Spaceport auth'
|
'user_fields[10]': 'Spaceport auth',
|
||||||
|
'user_fields[11]': 'other',
|
||||||
}
|
}
|
||||||
response = discourse_api_post('https://forum.protospace.ca/users.json', data)
|
response = discourse_api_post('https://forum.protospace.ca/users.json', data)
|
||||||
response = response.json()
|
response = response.json()
|
||||||
logger.info('Response: %s', response)
|
logger.info('Response: %s', response)
|
||||||
|
|
||||||
if response['success']:
|
|
||||||
logger.info('Skipping set password')
|
logger.info('Skipping set password')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
else:
|
||||||
logger.info('User exists, setting Discourse password for: ' + username)
|
logger.info('User exists, setting Discourse password for: ' + username)
|
||||||
|
|
||||||
script = 'User.find_by(username: "{}").update!(password: "{}")'.format(username, password)
|
script = 'User.find_by(username: "{}").update!(password: "{}")'.format(username, password)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user