Add user registration mix task.
authorRoger Braun <roger@rogerbraun.net>
Wed, 5 Apr 2017 10:27:25 +0000 (12:27 +0200)
committerRoger Braun <roger@rogerbraun.net>
Wed, 5 Apr 2017 10:27:25 +0000 (12:27 +0200)
lib/mix/tasks/register_user.ex [new file with mode: 0644]

diff --git a/lib/mix/tasks/register_user.ex b/lib/mix/tasks/register_user.ex
new file mode 100644 (file)
index 0000000..e2f36c3
--- /dev/null
@@ -0,0 +1,21 @@
+defmodule Mix.Tasks.RegisterUser do
+  use Mix.Task
+  import Mix.Ecto
+  alias Pleroma.{Repo, User}
+
+  @shortdoc "Register user"
+  def run([name, nickname, email, bio, password]) do
+    ensure_started(Repo, [])
+    user = %User{
+      name: name,
+      nickname: nickname,
+      email: email,
+      password_hash: Comeonin.Pbkdf2.hashpwsalt(password),
+      bio: bio
+    }
+
+    user = %{ user | ap_id: User.ap_id(user) }
+
+    Repo.insert!(user)
+  end
+end