From a14c063ed4c0ea3a1d210c4bf87ff35e79a260ea Mon Sep 17 00:00:00 2001 From: "Billy.Zheng" Date: Sat, 25 May 2024 22:43:22 +0800 Subject: [PATCH] Update test007 pasword use migration --- ...240525130632_change_test007_password_for_user.cr | 10 ++++++++++ shard.lock | 2 +- src/operations/save_user.cr | 13 +++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 db/migrations/20240525130632_change_test007_password_for_user.cr create mode 100644 src/operations/save_user.cr diff --git a/db/migrations/20240525130632_change_test007_password_for_user.cr b/db/migrations/20240525130632_change_test007_password_for_user.cr new file mode 100644 index 0000000..3a5f980 --- /dev/null +++ b/db/migrations/20240525130632_change_test007_password_for_user.cr @@ -0,0 +1,10 @@ +class ChangeTest007PasswordForUser::V20240525130632 < Avram::Migrator::Migration::V1 + def migrate + user = UserQuery.new.email("test007@zw963.top").first + SaveUser.update!(user, password: "1234567") + end + + def rollback + # drop table_for(Thing) + end +end diff --git a/shard.lock b/shard.lock index 2096ced..57310ab 100644 --- a/shard.lock +++ b/shard.lock @@ -7,7 +7,7 @@ shards: avram: # Overridden git: https://github.com/luckyframework/avram.git - version: 1.2.0+git.commit.1326a8ea7583b91169993194802bb0875172a9c3 + version: 1.2.0+git.commit.af42b9449a8cccb21632dac3a239d5849428ff9f backtracer: git: https://github.com/sija/backtracer.cr.git diff --git a/src/operations/save_user.cr b/src/operations/save_user.cr new file mode 100644 index 0000000..38374c3 --- /dev/null +++ b/src/operations/save_user.cr @@ -0,0 +1,13 @@ +class SaveUser < User::SaveOperation + upsert_lookup_columns email + attribute password : String + + before_save do + password.value.try do |password_value| + encrypted_password.value = Crypto::Bcrypt::Password.create( + password_value, + cost: Authentic.settings.encryption_cost + ).to_s + end + end +end