Create users from code

Hi, I’m trying the Diaspora and I have a question. If I have a set of user parameters (for example, in a text file: first name, last name, age, etc. parameters) and I want to create them using code, without using the web interface, but getting a token, for further use for the API. Is it possible to do this and how?

There is no API endpoint to create users, and there most likely never will be, since pods can require captchas for signing up, and what would make automated user creation impossible - for good.

If you want to create users from directly inside diaspora*s code, have a look at what our signup form does and replicate that in a script that runs inside the Rails env. The build functions requires email, username, and password as a hash.

If you want to build a spam farm, I’ll make sure to have you hunted down by angry cats worldwide.

I don’t want to create spambots) I have never worked with Rails before, you can show me please an example of creating 1 user using this code, it is not very clear where to access it. The main thing for me is to create a user without a web interface, I think this method will suit me. I would be very grateful.

A good way to experiment is the rails console, bin/rails console development or bin/rails console production.

A bare bone script to create a single user follows. Please try to understand what each part is doing and write your own. Also it’s probably beneficial to get a development environment so you don’t risk burning user IDs while developing your script, as you shouldn’t delete a production database and start over ever.

# Ensure we run in the procution environment if none is set
ENV["RAILS_ENV"] ||= "production"

# Load up the Rails application environment
require_relative "config/environment"

# Ensure sign up doesn't fail by a missing captcha
AppConfig.settings.captcha.enable = false

# Minimum required fields, you can find more by typing User into the rails console
user = User.build(username: "foo", email: "foo@example.org", password: "changemealready")

# optional of course if you're confident
abort "Invalid user: #{user.errors.full_messages}" unless user.valid? 

# Create person and profile, save everything
success = user.sign_up

# optional of course if you're confident
abort "Invalid user: #{user.errors.full_messages}" unless success

# Optionally set some parameters on the profile, see Profile in the rails console for what's available
user.profile.update(first_name: "Foo Bar")
1 Like

Hi! Is there the same way to log in a social network? For example, user.sign_in.

You can’t log into an account in your browser from the CLI, no.

What are you trying to achieve?