From 1d905e615e927642a021701f82f0428ad009986d Mon Sep 17 00:00:00 2001 From: notten13 <15044786+notten13@users.noreply.github.com> Date: Sat, 11 Mar 2023 19:03:08 +0000 Subject: [PATCH] feat: sign up form (wip) --- Gemfile | 2 +- Gemfile.lock | 2 + app/controllers/users_controller.rb | 24 ++++++++++ app/models/user.rb | 13 ++++++ app/views/layouts/application.html.erb | 27 +++++++++++- app/views/users/new.html.erb | 54 +++++++++++++++++++++++ config/routes.rb | 4 +- db/migrate/20230311181749_create_users.rb | 16 +++++++ db/schema.rb | 27 ++++++++++++ test/fixtures/users.yml | 21 +++++++++ test/models/user_test.rb | 7 +++ 11 files changed, 193 insertions(+), 4 deletions(-) create mode 100644 app/controllers/users_controller.rb create mode 100644 app/models/user.rb create mode 100644 app/views/users/new.html.erb create mode 100644 db/migrate/20230311181749_create_users.rb create mode 100644 db/schema.rb create mode 100644 test/fixtures/users.yml create mode 100644 test/models/user_test.rb 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:
+