Discourse check if user exists before creating account
This commit is contained in:
parent
4aee074527
commit
7bbfb05065
|
@ -202,38 +202,42 @@ def set_discourse_password(username, password, first_name, email):
|
||||||
abort(400)
|
abort(400)
|
||||||
|
|
||||||
|
|
||||||
logger.info('Creating Discourse user for: ' + username)
|
user_exists = username in discourse_usernames
|
||||||
|
|
||||||
data = {
|
if not user_exists:
|
||||||
'name': first_name,
|
logger.info('Creating Discourse user for: ' + username)
|
||||||
'username': username,
|
|
||||||
'password': password,
|
data = {
|
||||||
'email': email,
|
'name': first_name,
|
||||||
'active': True,
|
'username': username,
|
||||||
'approved': True,
|
'password': password,
|
||||||
'user_fields[10]': 'Spaceport auth'
|
'email': email,
|
||||||
}
|
'active': True,
|
||||||
response = discourse_api_post('https://forum.protospace.ca/users.json', data)
|
'approved': True,
|
||||||
response = response.json()
|
'user_fields[10]': 'Spaceport auth',
|
||||||
logger.info('Response: %s', response)
|
'user_fields[11]': 'other',
|
||||||
|
}
|
||||||
|
response = discourse_api_post('https://forum.protospace.ca/users.json', data)
|
||||||
|
response = response.json()
|
||||||
|
logger.info('Response: %s', response)
|
||||||
|
|
||||||
if response['success']:
|
|
||||||
logger.info('Skipping set password')
|
logger.info('Skipping set password')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
logger.info('User exists, setting Discourse password for: ' + username)
|
|
||||||
|
|
||||||
script = 'User.find_by(username: "{}").update!(password: "{}")'.format(username, password)
|
|
||||||
result, output = discourse_rails_script(script)
|
|
||||||
|
|
||||||
if 'Password is the same' in result.stderr:
|
|
||||||
logger.info('Output: Password is the same as your current password. (ActiveRecord::RecordInvalid)')
|
|
||||||
return True
|
|
||||||
else:
|
else:
|
||||||
logger.info('Output: ' + output)
|
logger.info('User exists, setting Discourse password for: ' + username)
|
||||||
|
|
||||||
if result.stderr:
|
script = 'User.find_by(username: "{}").update!(password: "{}")'.format(username, password)
|
||||||
abort(400)
|
result, output = discourse_rails_script(script)
|
||||||
|
|
||||||
|
if 'Password is the same' in result.stderr:
|
||||||
|
logger.info('Output: Password is the same as your current password. (ActiveRecord::RecordInvalid)')
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
logger.info('Output: ' + output)
|
||||||
|
|
||||||
|
if result.stderr:
|
||||||
|
abort(400)
|
||||||
|
|
||||||
|
|
||||||
def add_discourse_group_members(group_name, usernames):
|
def add_discourse_group_members(group_name, usernames):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user