Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into bugfix/repeated...
authordtluna <dtluna@openmailbox.org>
Sun, 16 Apr 2017 14:18:34 +0000 (17:18 +0300)
committerdtluna <dtluna@openmailbox.org>
Sun, 16 Apr 2017 14:18:34 +0000 (17:18 +0300)
1  2 
lib/pleroma/user.ex
lib/pleroma/web/twitter_api/twitter_api.ex
lib/pleroma/web/twitter_api/twitter_api_controller.ex
test/web/twitter_api/twitter_api_test.exs

index 5f5bc1c384bbc9470a033ce536050a0286bc89c6,fdcc1b7d5ba9ea103768f4830a208ff1a0add00a..418522172ddc5019cd92183cf0bb1e219b489af5
@@@ -29,19 -32,35 +32,40 @@@ defmodule Pleroma.User d
      |> validate_required([:following])
    end
  
+   def register_changeset(struct, params \\ %{}) do
+     changeset = struct
+     |> cast(params, [:bio, :email, :name, :nickname, :password, :password_confirmation])
+     |> validate_required([:bio, :email, :name, :nickname, :password, :password_confirmation])
+     |> validate_confirmation(:password)
+     |> unique_constraint(:email)
+     |> unique_constraint(:nickname)
+     if changeset.valid? do
+       hashed = Comeonin.Pbkdf2.hashpwsalt(changeset.changes[:password])
+       ap_id = User.ap_id(%User{nickname: changeset.changes[:nickname]})
+       followers = User.ap_followers(%User{nickname: changeset.changes[:nickname]})
+       changeset
+       |> put_change(:password_hash, hashed)
+       |> put_change(:ap_id, ap_id)
+       |> put_change(:following, [followers])
+     else
+       changeset
+     end
+   end
    def follow(%User{} = follower, %User{} = followed) do
      ap_followers = User.ap_followers(followed)
 -    following = [ap_followers | follower.following]
 -    |> Enum.uniq
 +    if following?(follower, followed) do
 +      { :error,
 +        "Could not follow user: #{followed.nickname} is already on your list." }
 +    else
 +      following = [ap_followers | follower.following]
 +      |> Enum.uniq
  
 -    follower
 -    |> follow_changeset(%{following: following})
 -    |> Repo.update
 +      follower
 +      |> follow_changeset(%{following: following})
 +      |> Repo.update
 +    end
    end
  
    def unfollow(%User{} = follower, %User{} = followed) do
index 405aa1221a1dfac9cb27259fb829d520f379c536,1e5204db8442955e544f1125ed65fd5c1176000a..b61f16b47fd28f9c4e1b96b9f1712963a877171c
@@@ -107,10 -113,10 +113,10 @@@ defmodule Pleroma.Web.TwitterAPI.Twitte
    end
  
    test "Follow another user" do
-     { :ok, user } = UserBuilder.insert
-     { :ok, followed } = UserBuilder.insert(%{nickname: "guy"})
+     user = insert(:user)
 -    following = insert(:user)
++    followed = insert(:user)
  
 -    {:ok, user, following, activity } = TwitterAPI.follow(user, following.id)
 +    { :ok, user, followed, activity } = TwitterAPI.follow(user, followed.id)
  
      user = Repo.get(User, user.id)
      follow = Repo.get(Activity, activity.id)
    end
  
    test "Unfollow another user" do
-     { :ok, followed } = UserBuilder.insert(%{nickname: "guy"})
-     { :ok, user } = UserBuilder.insert(%{following: [User.ap_followers(followed)]})
 -    following = insert(:user)
 -    user = insert(:user, %{following: [User.ap_followers(following)]})
++    followed = insert(:user)
++    user = insert(:user, %{following: [User.ap_followers(followed)]})
  
 -    {:ok, user, _following } = TwitterAPI.unfollow(user, following.id)
 +    { :ok, user, _followed } = TwitterAPI.unfollow(user, followed.id)
  
      user = Repo.get(User, user.id)