diff --git a/Gemfile b/Gemfile index 2437f82..31942bc 100644 --- a/Gemfile +++ b/Gemfile @@ -34,7 +34,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 ] diff --git a/Gemfile.lock b/Gemfile.lock index 6d8e295..c716f24 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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.16.0) msgpack (~> 1.2) @@ -209,6 +210,7 @@ PLATFORMS x86_64-linux DEPENDENCIES + bcrypt (~> 3.1.7) bootsnap capybara debug diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..be2e82f --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,24 @@ +class UsersController < ApplicationController + + def new + @user = User.new + end + + def create + user_params = params.require(:user).permit( + :username, + :email, + :password, + :password_confirmation + ) + + @user = User.new(user_params) + + if @user.valid? + render 'new' + else + render 'new', status: :unprocessable_entity + end + end + +end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..17e885b --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,13 @@ +class User < ApplicationRecord + has_secure_password + + has_secure_token :email_confirmation_token + + validates :username, + format: { with: /\A[A-Za-z0-9_]{2,20}\z/ , message: 'should contain 2 to 20 alphanumeric characters' }, + uniqueness: { case_sensitive: false } + + validates :email, + format: { with: URI::MailTo::EMAIL_REGEXP }, + uniqueness: { case_sensitive: false } +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e93b05c..8ec7765 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,16 +1,39 @@
-Your registration couldn't be processed:
+