remove "change password" in general account setting - rename "Forgot my password?" by "Reset your password" in login frame - #1918

This commit is contained in:
Laurent GAY
2025-12-30 15:49:38 +01:00
parent 6cbb3693bb
commit cf1918d2c2
14 changed files with 721 additions and 1076 deletions

View File

@@ -1336,209 +1336,6 @@ defmodule Mobilizon.GraphQL.Resolvers.UserTest do
end
end
describe "Resolver: Change password for an user" do
@email "toto@tata.tld"
@moderation_empty ""
@old_password "p4ssw0rd"
@new_password "upd4t3d"
test "change_password/3 with valid password", %{conn: conn} do
{:ok, %User{} = user} =
Users.register(%{email: @email, password: @old_password, moderation: @moderation_empty})
# Hammer time !
{:ok, %User{} = _user} =
Users.update_user(user, %{
"confirmed_at" => Timex.shift(user.confirmation_sent_at, hours: -3),
"confirmation_sent_at" => nil,
"confirmation_token" => nil
})
mutation = """
mutation {
login(
email: "#{@email}",
password: "#{@old_password}",
) {
accessToken,
refreshToken,
user {
id
}
}
}
"""
res =
conn
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
assert login = json_response(res, 200)["data"]["login"]
assert Map.has_key?(login, "accessToken") && not is_nil(login["accessToken"])
mutation = """
mutation {
changePassword(old_password: "#{@old_password}", new_password: "#{@new_password}") {
id
}
}
"""
res =
conn
|> auth_conn(user)
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
assert json_response(res, 200)["errors"] == nil
assert json_response(res, 200)["data"]["changePassword"]["id"] == to_string(user.id)
mutation = """
mutation {
login(
email: "#{@email}",
password: "#{@new_password}",
) {
accessToken,
refreshToken,
user {
id
}
}
}
"""
res =
conn
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
assert login = json_response(res, 200)["data"]["login"]
assert Map.has_key?(login, "accessToken") && not is_nil(login["accessToken"])
refute_email_sent()
end
test "change_password/3 with invalid password", %{conn: conn} do
{:ok, %User{} = user} =
Users.register(%{email: @email, password: @old_password, moderation: @moderation_empty})
# Hammer time !
{:ok, %User{} = _user} =
Users.update_user(user, %{
"confirmed_at" => Timex.shift(user.confirmation_sent_at, hours: -3),
"confirmation_sent_at" => nil,
"confirmation_token" => nil
})
mutation = """
mutation {
changePassword(old_password: "invalid password", new_password: "#{@new_password}") {
id
}
}
"""
res =
conn
|> auth_conn(user)
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
assert hd(json_response(res, 200)["errors"])["message"] == "The current password is invalid"
refute_email_sent()
end
test "change_password/3 with same password", %{conn: conn} do
{:ok, %User{} = user} =
Users.register(%{email: @email, password: @old_password, moderation: @moderation_empty})
# Hammer time !
{:ok, %User{} = _user} =
Users.update_user(user, %{
"confirmed_at" => Timex.shift(user.confirmation_sent_at, hours: -3),
"confirmation_sent_at" => nil,
"confirmation_token" => nil
})
mutation = """
mutation {
changePassword(old_password: "#{@old_password}", new_password: "#{@old_password}") {
id
}
}
"""
res =
conn
|> auth_conn(user)
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
assert hd(json_response(res, 200)["errors"])["message"] ==
"The new password must be different"
refute_email_sent()
end
test "change_password/3 with new password too short", %{conn: conn} do
{:ok, %User{} = user} =
Users.register(%{email: @email, password: @old_password, moderation: @moderation_empty})
# Hammer time !
{:ok, %User{} = _user} =
Users.update_user(user, %{
"confirmed_at" => Timex.shift(user.confirmation_sent_at, hours: -3),
"confirmation_sent_at" => nil,
"confirmation_token" => nil
})
mutation = """
mutation {
changePassword(old_password: "#{@old_password}", new_password: "new") {
id
}
}
"""
res =
conn
|> auth_conn(user)
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
assert hd(json_response(res, 200)["errors"])["message"] ==
"The password you have chosen is too short. Please make sure your password contains at least 6 characters."
refute_email_sent()
end
test "change_password/3 without being authenticated", %{conn: conn} do
{:ok, %User{} = user} =
Users.register(%{email: @email, password: @old_password, moderation: @moderation_empty})
# Hammer time !
{:ok, %User{} = _user} =
Users.update_user(user, %{
"confirmed_at" => Timex.shift(user.confirmation_sent_at, hours: -3),
"confirmation_sent_at" => nil,
"confirmation_token" => nil
})
mutation = """
mutation {
changePassword(old_password: "#{@old_password}", new_password: "#{@new_password}") {
id
}
}
"""
res =
conn
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
assert hd(json_response(res, 200)["errors"])["message"] ==
"You need to be logged in"
refute_email_sent()
end
end
describe "Resolver: Change email for an user" do
@old_email "old@domain.tld"
@new_email "new@domain.tld"
@@ -1721,7 +1518,7 @@ defmodule Mobilizon.GraphQL.Resolvers.UserTest do
refute_email_sent()
end
test "change_password/3 without being authenticated", %{conn: conn} do
test "change_email/3 without being authenticated", %{conn: conn} do
{:ok, %User{} = user} =
Users.register(%{email: @old_email, password: @password, moderation: @moderation_empty})