Use changeset in user registration mix task.

This commit is contained in:
Roger Braun 2017-04-15 16:42:02 +02:00
parent 03c6148bb3
commit 40706b4c4f

View 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