Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
- Feat: Enkripsi User Password
  • Loading branch information
mr-atho committed Aug 26, 2022
1 parent c7d043c commit 250ec51
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ gem "jbuilder"
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"
gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0)
bcrypt (3.1.18)
bindex (0.8.1)
bootsnap (1.13.0)
msgpack (~> 1.2)
Expand Down Expand Up @@ -217,6 +218,7 @@ PLATFORMS
x64-mingw-ucrt

DEPENDENCIES
bcrypt (~> 3.1.7)
bootsnap
capybara
debug
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Yand dibutuhkan untuk menjalankan aplikasi ini:
* Database SQLite (Development) & PostgreSQL (Production)

# VERSI
v1.2.0 | 26 Agustus 2022
- Feat: Enkripsi User Password

v1.1.0 | 25 Agustus 2022
- Feat: User
- Feat: Login User
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def login_form
end

def login
if @user = User.find_by(email: params[:email], password: params[:password])
@user = User.find_by(email: params[:email])

if @user && @user.authenticate(params[:password])
session[:current_user_id] = @user.id
flash[:just_signed_up] = "Welcome to our site"
redirect_to @user
Expand Down
3 changes: 2 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class User < ApplicationRecord
has_secure_password

validates :name, presence: true
validates :email, presence: true, uniqueness: true
validates :password, presence: true

def articles
return Article.where(user_id: self.id)
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20220825145043_change_users_columns.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ChangeUsersColumns < ActiveRecord::Migration[7.0]
def change
add_column :users, :password_digest, :string
remove_column :users, :password, :string
end
end
4 changes: 2 additions & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 250ec51

Please sign in to comment.