Use changeset in user registration mix task.
authorRoger Braun <roger@rogerbraun.net>
Sat, 15 Apr 2017 14:42:02 +0000 (16:42 +0200)
committerRoger Braun <roger@rogerbraun.net>
Sat, 15 Apr 2017 14:42:02 +0000 (16:42 +0200)
lib/mix/tasks/register_user.ex

index 17535f19011880aab7f770bb172cbc90f01604b2..48236439b2cf8c459eb72d73a6a47bccbbc52833 100644 (file)
@@ -6,15 +6,17 @@ defmodule Mix.Tasks.RegisterUser do
   @shortdoc "Register user"
   def run([name, nickname, email, bio, password]) do
     ensure_started(Repo, [])
-    user = %User{
+
+    params = %{
       name: name,
       nickname: nickname,
       email: email,
-      password_hash: Comeonin.Pbkdf2.hashpwsalt(password),
+      password: password,
+      password_confirmation: password,
       bio: bio
     }
 
-    user = %{ user | ap_id: User.ap_id(user), following: User.ap_followers(user) }
+    user = User.register_changeset(%User{}, params)
 
     Repo.insert!(user)
   end