From 86ec582225bd819b96f6fb724068b7742b34ff92 Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 13 Sep 2021 20:06:43 +0800 Subject: [PATCH 001/106] added and created Rspec for model testing --- spec/models/trial_user_spec.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 spec/models/trial_user_spec.rb diff --git a/spec/models/trial_user_spec.rb b/spec/models/trial_user_spec.rb new file mode 100644 index 000000000..2c6bdf234 --- /dev/null +++ b/spec/models/trial_user_spec.rb @@ -0,0 +1,29 @@ +require 'rails_helper' + +RSpec.describe User, type: :model do + it "is valid with valid attributes" do + user1 = User.new(email: 'email@example.com', password: 'password') + expect(user1).to be_valid + end + + it "is not valid without first_name" do + user2 = User.new(first_name: nil) + expect(user2).to_not be_valid + end + + it "is not valid without last_name" do + user2 = User.new(last_name: nil) + expect(user2).to_not be_valid + end + + it "is not valid without email" do + user2 = User.new(email: nil) + expect(user2).to_not be_valid + end + + it "is not valid without username" do + user2 = User.new(username: nil) + expect(user2).to_not be_valid + end + +end \ No newline at end of file From 1ab258c3dacbeeaafcb04f9f42001f75439ce9ed Mon Sep 17 00:00:00 2001 From: curtydudes <81552806+curtydudes@users.noreply.github.com> Date: Mon, 13 Sep 2021 20:48:29 +0800 Subject: [PATCH 002/106] Revert "added and created Rspec for model testing" --- spec/models/trial_user_spec.rb | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 spec/models/trial_user_spec.rb diff --git a/spec/models/trial_user_spec.rb b/spec/models/trial_user_spec.rb deleted file mode 100644 index 2c6bdf234..000000000 --- a/spec/models/trial_user_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'rails_helper' - -RSpec.describe User, type: :model do - it "is valid with valid attributes" do - user1 = User.new(email: 'email@example.com', password: 'password') - expect(user1).to be_valid - end - - it "is not valid without first_name" do - user2 = User.new(first_name: nil) - expect(user2).to_not be_valid - end - - it "is not valid without last_name" do - user2 = User.new(last_name: nil) - expect(user2).to_not be_valid - end - - it "is not valid without email" do - user2 = User.new(email: nil) - expect(user2).to_not be_valid - end - - it "is not valid without username" do - user2 = User.new(username: nil) - expect(user2).to_not be_valid - end - -end \ No newline at end of file From 75b3b96c0c00af3cd29a07fa807e379018c4341a Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 13 Sep 2021 21:16:01 +0800 Subject: [PATCH 003/106] added another rspec model test file --- spec/model/trial_user_spec.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 spec/model/trial_user_spec.rb diff --git a/spec/model/trial_user_spec.rb b/spec/model/trial_user_spec.rb new file mode 100644 index 000000000..4ad5b93fc --- /dev/null +++ b/spec/model/trial_user_spec.rb @@ -0,0 +1,29 @@ +require 'rails_helper' + +RSpec.describe User, type: :model do + it 'is valid with valid attributes' do + user1 = described_class.new(email: 'email@example.com', password: 'password') + expect(user1).to be_valid + end + + it 'is not valid without first_name' do + user2 = described_class.new(first_name: nil) + expect(user2).to_not be_valid + end + + it 'is not valid without last_name' do + user2 = described_class.new(last_name: nil) + expect(user2).to_not be_valid + end + + it 'is not valid without email' do + user2 = described_class.new(email: nil) + expect(user2).to_not be_valid + end + + it 'is not valid without username' do + user2 = described_class.new(username: nil) + expect(user2).to_not be_valid + end + +end \ No newline at end of file From 9f485e975e90432da5d8815cd53c0f13e88bdd3c Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 13 Sep 2021 21:20:42 +0800 Subject: [PATCH 004/106] updated rubocop correctables --- spec/model/trial_user_spec.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spec/model/trial_user_spec.rb b/spec/model/trial_user_spec.rb index 4ad5b93fc..69bb1fa48 100644 --- a/spec/model/trial_user_spec.rb +++ b/spec/model/trial_user_spec.rb @@ -8,22 +8,21 @@ it 'is not valid without first_name' do user2 = described_class.new(first_name: nil) - expect(user2).to_not be_valid + expect(user2).not_to be_valid end it 'is not valid without last_name' do user2 = described_class.new(last_name: nil) - expect(user2).to_not be_valid + expect(user2).not_to be_valid end it 'is not valid without email' do user2 = described_class.new(email: nil) - expect(user2).to_not be_valid + expect(user2).not_to be_valid end it 'is not valid without username' do user2 = described_class.new(username: nil) - expect(user2).to_not be_valid + expect(user2).not_to be_valid end - -end \ No newline at end of file +end From 122b91bab334a17b15e05551f7d40545183936c5 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 14 Sep 2021 20:09:42 +0800 Subject: [PATCH 005/106] added devise gem and functionalities for both user and admin. I also added a tempoarary landing page --- .../admins/confirmations_controller.rb | 30 ++ .../admins/omniauth_callbacks_controller.rb | 30 ++ .../admins/passwords_controller.rb | 34 ++ .../admins/registrations_controller.rb | 62 ++++ app/controllers/admins/sessions_controller.rb | 27 ++ app/controllers/admins/unlocks_controller.rb | 30 ++ app/controllers/landing_controller.rb | 5 + .../users/confirmations_controller.rb | 30 ++ .../users/omniauth_callbacks_controller.rb | 30 ++ app/controllers/users/passwords_controller.rb | 34 ++ .../users/registrations_controller.rb | 62 ++++ app/controllers/users/sessions_controller.rb | 27 ++ app/controllers/users/unlocks_controller.rb | 30 ++ app/models/admin.rb | 6 + app/models/user.rb | 6 + app/views/admins/confirmations/new.html.erb | 16 + .../mailer/confirmation_instructions.html.erb | 5 + .../admins/mailer/email_changed.html.erb | 7 + .../admins/mailer/password_change.html.erb | 3 + .../reset_password_instructions.html.erb | 8 + .../mailer/unlock_instructions.html.erb | 7 + app/views/admins/passwords/edit.html.erb | 25 ++ app/views/admins/passwords/new.html.erb | 16 + app/views/admins/registrations/edit.html.erb | 43 +++ app/views/admins/registrations/new.html.erb | 29 ++ app/views/admins/sessions/new.html.erb | 26 ++ .../admins/shared/_error_messages.html.erb | 15 + app/views/admins/shared/_links.html.erb | 25 ++ app/views/admins/unlocks/new.html.erb | 16 + app/views/landing/signupUser.html.erb | 4 + app/views/layouts/application.html.erb | 2 + app/views/users/confirmations/new.html.erb | 16 + .../mailer/confirmation_instructions.html.erb | 5 + app/views/users/mailer/email_changed.html.erb | 7 + .../users/mailer/password_change.html.erb | 3 + .../reset_password_instructions.html.erb | 8 + .../users/mailer/unlock_instructions.html.erb | 7 + app/views/users/passwords/edit.html.erb | 25 ++ app/views/users/passwords/new.html.erb | 16 + app/views/users/registrations/edit.html.erb | 43 +++ app/views/users/registrations/new.html.erb | 29 ++ app/views/users/sessions/new.html.erb | 26 ++ .../users/shared/_error_messages.html.erb | 15 + app/views/users/shared/_links.html.erb | 25 ++ app/views/users/unlocks/new.html.erb | 16 + config/environments/development.rb | 3 + config/environments/test.rb | 2 +- config/initializers/devise.rb | 311 ++++++++++++++++++ config/locales/devise.en.yml | 67 ++++ config/routes.rb | 4 +- .../20210914112235_devise_create_users.rb | 44 +++ .../20210914112343_devise_create_admins.rb | 44 +++ db/schema.rb | 26 +- spec/models/admin_spec.rb | 5 + spec/models/trial_user_spec.rb | 28 ++ spec/models/user_spec.rb | 5 + spec/rails_helper.rb | 64 ++-- spec/spec_helper.rb | 1 + 58 files changed, 1512 insertions(+), 23 deletions(-) create mode 100644 app/controllers/admins/confirmations_controller.rb create mode 100644 app/controllers/admins/omniauth_callbacks_controller.rb create mode 100644 app/controllers/admins/passwords_controller.rb create mode 100644 app/controllers/admins/registrations_controller.rb create mode 100644 app/controllers/admins/sessions_controller.rb create mode 100644 app/controllers/admins/unlocks_controller.rb create mode 100644 app/controllers/landing_controller.rb create mode 100644 app/controllers/users/confirmations_controller.rb create mode 100644 app/controllers/users/omniauth_callbacks_controller.rb create mode 100644 app/controllers/users/passwords_controller.rb create mode 100644 app/controllers/users/registrations_controller.rb create mode 100644 app/controllers/users/sessions_controller.rb create mode 100644 app/controllers/users/unlocks_controller.rb create mode 100644 app/models/admin.rb create mode 100644 app/models/user.rb create mode 100644 app/views/admins/confirmations/new.html.erb create mode 100644 app/views/admins/mailer/confirmation_instructions.html.erb create mode 100644 app/views/admins/mailer/email_changed.html.erb create mode 100644 app/views/admins/mailer/password_change.html.erb create mode 100644 app/views/admins/mailer/reset_password_instructions.html.erb create mode 100644 app/views/admins/mailer/unlock_instructions.html.erb create mode 100644 app/views/admins/passwords/edit.html.erb create mode 100644 app/views/admins/passwords/new.html.erb create mode 100644 app/views/admins/registrations/edit.html.erb create mode 100644 app/views/admins/registrations/new.html.erb create mode 100644 app/views/admins/sessions/new.html.erb create mode 100644 app/views/admins/shared/_error_messages.html.erb create mode 100644 app/views/admins/shared/_links.html.erb create mode 100644 app/views/admins/unlocks/new.html.erb create mode 100644 app/views/landing/signupUser.html.erb create mode 100644 app/views/users/confirmations/new.html.erb create mode 100644 app/views/users/mailer/confirmation_instructions.html.erb create mode 100644 app/views/users/mailer/email_changed.html.erb create mode 100644 app/views/users/mailer/password_change.html.erb create mode 100644 app/views/users/mailer/reset_password_instructions.html.erb create mode 100644 app/views/users/mailer/unlock_instructions.html.erb create mode 100644 app/views/users/passwords/edit.html.erb create mode 100644 app/views/users/passwords/new.html.erb create mode 100644 app/views/users/registrations/edit.html.erb create mode 100644 app/views/users/registrations/new.html.erb create mode 100644 app/views/users/sessions/new.html.erb create mode 100644 app/views/users/shared/_error_messages.html.erb create mode 100644 app/views/users/shared/_links.html.erb create mode 100644 app/views/users/unlocks/new.html.erb create mode 100644 config/initializers/devise.rb create mode 100644 config/locales/devise.en.yml create mode 100644 db/migrate/20210914112235_devise_create_users.rb create mode 100644 db/migrate/20210914112343_devise_create_admins.rb create mode 100644 spec/models/admin_spec.rb create mode 100644 spec/models/trial_user_spec.rb create mode 100644 spec/models/user_spec.rb diff --git a/app/controllers/admins/confirmations_controller.rb b/app/controllers/admins/confirmations_controller.rb new file mode 100644 index 000000000..cdc508bf9 --- /dev/null +++ b/app/controllers/admins/confirmations_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Admins::ConfirmationsController < Devise::ConfirmationsController + # GET /resource/confirmation/new + # def new + # super + # end + + # POST /resource/confirmation + # def create + # super + # end + + # GET /resource/confirmation?confirmation_token=abcdef + # def show + # super + # end + + # protected + + # The path used after resending confirmation instructions. + # def after_resending_confirmation_instructions_path_for(resource_name) + # super(resource_name) + # end + + # The path used after confirmation. + # def after_confirmation_path_for(resource_name, resource) + # super(resource_name, resource) + # end +end diff --git a/app/controllers/admins/omniauth_callbacks_controller.rb b/app/controllers/admins/omniauth_callbacks_controller.rb new file mode 100644 index 000000000..fbebb2ba8 --- /dev/null +++ b/app/controllers/admins/omniauth_callbacks_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Admins::OmniauthCallbacksController < Devise::OmniauthCallbacksController + # You should configure your model like this: + # devise :omniauthable, omniauth_providers: [:twitter] + + # You should also create an action method in this controller like this: + # def twitter + # end + + # More info at: + # https://github.com/heartcombo/devise#omniauth + + # GET|POST /resource/auth/twitter + # def passthru + # super + # end + + # GET|POST /users/auth/twitter/callback + # def failure + # super + # end + + # protected + + # The path used when OmniAuth fails + # def after_omniauth_failure_path_for(scope) + # super(scope) + # end +end diff --git a/app/controllers/admins/passwords_controller.rb b/app/controllers/admins/passwords_controller.rb new file mode 100644 index 000000000..136872068 --- /dev/null +++ b/app/controllers/admins/passwords_controller.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class Admins::PasswordsController < Devise::PasswordsController + # GET /resource/password/new + # def new + # super + # end + + # POST /resource/password + # def create + # super + # end + + # GET /resource/password/edit?reset_password_token=abcdef + # def edit + # super + # end + + # PUT /resource/password + # def update + # super + # end + + # protected + + # def after_resetting_password_path_for(resource) + # super(resource) + # end + + # The path used after sending reset password instructions + # def after_sending_reset_password_instructions_path_for(resource_name) + # super(resource_name) + # end +end diff --git a/app/controllers/admins/registrations_controller.rb b/app/controllers/admins/registrations_controller.rb new file mode 100644 index 000000000..5d449ea0d --- /dev/null +++ b/app/controllers/admins/registrations_controller.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +class Admins::RegistrationsController < Devise::RegistrationsController + # before_action :configure_sign_up_params, only: [:create] + # before_action :configure_account_update_params, only: [:update] + + # GET /resource/sign_up + # def new + # super + # end + + # POST /resource + # def create + # super + # end + + # GET /resource/edit + # def edit + # super + # end + + # PUT /resource + # def update + # super + # end + + # DELETE /resource + # def destroy + # super + # end + + # GET /resource/cancel + # Forces the session data which is usually expired after sign + # in to be expired now. This is useful if the user wants to + # cancel oauth signing in/up in the middle of the process, + # removing all OAuth session data. + # def cancel + # super + # end + + # protected + + # If you have extra params to permit, append them to the sanitizer. + # def configure_sign_up_params + # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute]) + # end + + # If you have extra params to permit, append them to the sanitizer. + # def configure_account_update_params + # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute]) + # end + + # The path used after sign up. + # def after_sign_up_path_for(resource) + # super(resource) + # end + + # The path used after sign up for inactive accounts. + # def after_inactive_sign_up_path_for(resource) + # super(resource) + # end +end diff --git a/app/controllers/admins/sessions_controller.rb b/app/controllers/admins/sessions_controller.rb new file mode 100644 index 000000000..a17b81e50 --- /dev/null +++ b/app/controllers/admins/sessions_controller.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class Admins::SessionsController < Devise::SessionsController + # before_action :configure_sign_in_params, only: [:create] + + # GET /resource/sign_in + # def new + # super + # end + + # POST /resource/sign_in + # def create + # super + # end + + # DELETE /resource/sign_out + # def destroy + # super + # end + + # protected + + # If you have extra params to permit, append them to the sanitizer. + # def configure_sign_in_params + # devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute]) + # end +end diff --git a/app/controllers/admins/unlocks_controller.rb b/app/controllers/admins/unlocks_controller.rb new file mode 100644 index 000000000..553d264b6 --- /dev/null +++ b/app/controllers/admins/unlocks_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Admins::UnlocksController < Devise::UnlocksController + # GET /resource/unlock/new + # def new + # super + # end + + # POST /resource/unlock + # def create + # super + # end + + # GET /resource/unlock?unlock_token=abcdef + # def show + # super + # end + + # protected + + # The path used after sending unlock password instructions + # def after_sending_unlock_instructions_path_for(resource) + # super(resource) + # end + + # The path used after unlocking the resource + # def after_unlock_path_for(resource) + # super(resource) + # end +end diff --git a/app/controllers/landing_controller.rb b/app/controllers/landing_controller.rb new file mode 100644 index 000000000..be713a113 --- /dev/null +++ b/app/controllers/landing_controller.rb @@ -0,0 +1,5 @@ +class LandingController < ApplicationController + def index + @categories = Category.all + end +end \ No newline at end of file diff --git a/app/controllers/users/confirmations_controller.rb b/app/controllers/users/confirmations_controller.rb new file mode 100644 index 000000000..fa535c0ae --- /dev/null +++ b/app/controllers/users/confirmations_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Users::ConfirmationsController < Devise::ConfirmationsController + # GET /resource/confirmation/new + # def new + # super + # end + + # POST /resource/confirmation + # def create + # super + # end + + # GET /resource/confirmation?confirmation_token=abcdef + # def show + # super + # end + + # protected + + # The path used after resending confirmation instructions. + # def after_resending_confirmation_instructions_path_for(resource_name) + # super(resource_name) + # end + + # The path used after confirmation. + # def after_confirmation_path_for(resource_name, resource) + # super(resource_name, resource) + # end +end diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb new file mode 100644 index 000000000..593f547d1 --- /dev/null +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController + # You should configure your model like this: + # devise :omniauthable, omniauth_providers: [:twitter] + + # You should also create an action method in this controller like this: + # def twitter + # end + + # More info at: + # https://github.com/heartcombo/devise#omniauth + + # GET|POST /resource/auth/twitter + # def passthru + # super + # end + + # GET|POST /users/auth/twitter/callback + # def failure + # super + # end + + # protected + + # The path used when OmniAuth fails + # def after_omniauth_failure_path_for(scope) + # super(scope) + # end +end diff --git a/app/controllers/users/passwords_controller.rb b/app/controllers/users/passwords_controller.rb new file mode 100644 index 000000000..259dbb084 --- /dev/null +++ b/app/controllers/users/passwords_controller.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class Users::PasswordsController < Devise::PasswordsController + # GET /resource/password/new + # def new + # super + # end + + # POST /resource/password + # def create + # super + # end + + # GET /resource/password/edit?reset_password_token=abcdef + # def edit + # super + # end + + # PUT /resource/password + # def update + # super + # end + + # protected + + # def after_resetting_password_path_for(resource) + # super(resource) + # end + + # The path used after sending reset password instructions + # def after_sending_reset_password_instructions_path_for(resource_name) + # super(resource_name) + # end +end diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb new file mode 100644 index 000000000..b9e664fe3 --- /dev/null +++ b/app/controllers/users/registrations_controller.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +class Users::RegistrationsController < Devise::RegistrationsController + # before_action :configure_sign_up_params, only: [:create] + # before_action :configure_account_update_params, only: [:update] + + # GET /resource/sign_up + # def new + # super + # end + + # POST /resource + # def create + # super + # end + + # GET /resource/edit + # def edit + # super + # end + + # PUT /resource + # def update + # super + # end + + # DELETE /resource + # def destroy + # super + # end + + # GET /resource/cancel + # Forces the session data which is usually expired after sign + # in to be expired now. This is useful if the user wants to + # cancel oauth signing in/up in the middle of the process, + # removing all OAuth session data. + # def cancel + # super + # end + + # protected + + # If you have extra params to permit, append them to the sanitizer. + # def configure_sign_up_params + # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute]) + # end + + # If you have extra params to permit, append them to the sanitizer. + # def configure_account_update_params + # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute]) + # end + + # The path used after sign up. + # def after_sign_up_path_for(resource) + # super(resource) + # end + + # The path used after sign up for inactive accounts. + # def after_inactive_sign_up_path_for(resource) + # super(resource) + # end +end diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb new file mode 100644 index 000000000..a0f9b48e7 --- /dev/null +++ b/app/controllers/users/sessions_controller.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class Users::SessionsController < Devise::SessionsController + # before_action :configure_sign_in_params, only: [:create] + + # GET /resource/sign_in + # def new + # super + # end + + # POST /resource/sign_in + # def create + # super + # end + + # DELETE /resource/sign_out + # def destroy + # super + # end + + # protected + + # If you have extra params to permit, append them to the sanitizer. + # def configure_sign_in_params + # devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute]) + # end +end diff --git a/app/controllers/users/unlocks_controller.rb b/app/controllers/users/unlocks_controller.rb new file mode 100644 index 000000000..2c410dc01 --- /dev/null +++ b/app/controllers/users/unlocks_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Users::UnlocksController < Devise::UnlocksController + # GET /resource/unlock/new + # def new + # super + # end + + # POST /resource/unlock + # def create + # super + # end + + # GET /resource/unlock?unlock_token=abcdef + # def show + # super + # end + + # protected + + # The path used after sending unlock password instructions + # def after_sending_unlock_instructions_path_for(resource) + # super(resource) + # end + + # The path used after unlocking the resource + # def after_unlock_path_for(resource) + # super(resource) + # end +end diff --git a/app/models/admin.rb b/app/models/admin.rb new file mode 100644 index 000000000..7a7be2f69 --- /dev/null +++ b/app/models/admin.rb @@ -0,0 +1,6 @@ +class Admin < ApplicationRecord + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :validatable +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 000000000..47567994e --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,6 @@ +class User < ApplicationRecord + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :validatable +end diff --git a/app/views/admins/confirmations/new.html.erb b/app/views/admins/confirmations/new.html.erb new file mode 100644 index 000000000..916bec2df --- /dev/null +++ b/app/views/admins/confirmations/new.html.erb @@ -0,0 +1,16 @@ +

Resend confirmation instructions

+ +<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> + <%= render "admins/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> +
+ +
+ <%= f.submit "Resend confirmation instructions" %> +
+<% end %> + +<%= render "admins/shared/links" %> diff --git a/app/views/admins/mailer/confirmation_instructions.html.erb b/app/views/admins/mailer/confirmation_instructions.html.erb new file mode 100644 index 000000000..dc55f64f6 --- /dev/null +++ b/app/views/admins/mailer/confirmation_instructions.html.erb @@ -0,0 +1,5 @@ +

Welcome <%= @email %>!

+ +

You can confirm your account email through the link below:

+ +

<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>

diff --git a/app/views/admins/mailer/email_changed.html.erb b/app/views/admins/mailer/email_changed.html.erb new file mode 100644 index 000000000..32f4ba803 --- /dev/null +++ b/app/views/admins/mailer/email_changed.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @email %>!

+ +<% if @resource.try(:unconfirmed_email?) %> +

We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.

+<% else %> +

We're contacting you to notify you that your email has been changed to <%= @resource.email %>.

+<% end %> diff --git a/app/views/admins/mailer/password_change.html.erb b/app/views/admins/mailer/password_change.html.erb new file mode 100644 index 000000000..b41daf476 --- /dev/null +++ b/app/views/admins/mailer/password_change.html.erb @@ -0,0 +1,3 @@ +

Hello <%= @resource.email %>!

+ +

We're contacting you to notify you that your password has been changed.

diff --git a/app/views/admins/mailer/reset_password_instructions.html.erb b/app/views/admins/mailer/reset_password_instructions.html.erb new file mode 100644 index 000000000..f667dc12f --- /dev/null +++ b/app/views/admins/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +

Hello <%= @resource.email %>!

+ +

Someone has requested a link to change your password. You can do this through the link below.

+ +

<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

+ +

If you didn't request this, please ignore this email.

+

Your password won't change until you access the link above and create a new one.

diff --git a/app/views/admins/mailer/unlock_instructions.html.erb b/app/views/admins/mailer/unlock_instructions.html.erb new file mode 100644 index 000000000..41e148bf2 --- /dev/null +++ b/app/views/admins/mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @resource.email %>!

+ +

Your account has been locked due to an excessive number of unsuccessful sign in attempts.

+ +

Click the link below to unlock your account:

+ +

<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>

diff --git a/app/views/admins/passwords/edit.html.erb b/app/views/admins/passwords/edit.html.erb new file mode 100644 index 000000000..2839ff7c5 --- /dev/null +++ b/app/views/admins/passwords/edit.html.erb @@ -0,0 +1,25 @@ +

Change your password

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> + <%= render "admins/shared/error_messages", resource: resource %> + <%= f.hidden_field :reset_password_token %> + +
+ <%= f.label :password, "New password" %>
+ <% if @minimum_password_length %> + (<%= @minimum_password_length %> characters minimum)
+ <% end %> + <%= f.password_field :password, autofocus: true, autocomplete: "new-password" %> +
+ +
+ <%= f.label :password_confirmation, "Confirm new password" %>
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
+ +
+ <%= f.submit "Change my password" %> +
+<% end %> + +<%= render "admins/shared/links" %> diff --git a/app/views/admins/passwords/new.html.erb b/app/views/admins/passwords/new.html.erb new file mode 100644 index 000000000..b86af9427 --- /dev/null +++ b/app/views/admins/passwords/new.html.erb @@ -0,0 +1,16 @@ +

Forgot your password?

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= render "admins/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.submit "Send me reset password instructions" %> +
+<% end %> + +<%= render "admins/shared/links" %> diff --git a/app/views/admins/registrations/edit.html.erb b/app/views/admins/registrations/edit.html.erb new file mode 100644 index 000000000..fdc9ffe2a --- /dev/null +++ b/app/views/admins/registrations/edit.html.erb @@ -0,0 +1,43 @@ +

Edit <%= resource_name.to_s.humanize %>

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> + <%= render "admins/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> +
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
+ <% end %> + +
+ <%= f.label :password %> (leave blank if you don't want to change it)
+ <%= f.password_field :password, autocomplete: "new-password" %> + <% if @minimum_password_length %> +
+ <%= @minimum_password_length %> characters minimum + <% end %> +
+ +
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
+ +
+ <%= f.label :current_password %> (we need your current password to confirm your changes)
+ <%= f.password_field :current_password, autocomplete: "current-password" %> +
+ +
+ <%= f.submit "Update" %> +
+<% end %> + +

Cancel my account

+ +

Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>

+ +<%= link_to "Back", :back %> diff --git a/app/views/admins/registrations/new.html.erb b/app/views/admins/registrations/new.html.erb new file mode 100644 index 000000000..a99bf2f1c --- /dev/null +++ b/app/views/admins/registrations/new.html.erb @@ -0,0 +1,29 @@ +

Sign up

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> + <%= render "admins/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.label :password %> + <% if @minimum_password_length %> + (<%= @minimum_password_length %> characters minimum) + <% end %>
+ <%= f.password_field :password, autocomplete: "new-password" %> +
+ +
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
+ +
+ <%= f.submit "Sign up" %> +
+<% end %> + +<%= render "admins/shared/links" %> diff --git a/app/views/admins/sessions/new.html.erb b/app/views/admins/sessions/new.html.erb new file mode 100644 index 000000000..bf99c7843 --- /dev/null +++ b/app/views/admins/sessions/new.html.erb @@ -0,0 +1,26 @@ +

Log in

+ +<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.label :password %>
+ <%= f.password_field :password, autocomplete: "current-password" %> +
+ + <% if devise_mapping.rememberable? %> +
+ <%= f.check_box :remember_me %> + <%= f.label :remember_me %> +
+ <% end %> + +
+ <%= f.submit "Log in" %> +
+<% end %> + +<%= render "admins/shared/links" %> diff --git a/app/views/admins/shared/_error_messages.html.erb b/app/views/admins/shared/_error_messages.html.erb new file mode 100644 index 000000000..ba7ab8870 --- /dev/null +++ b/app/views/admins/shared/_error_messages.html.erb @@ -0,0 +1,15 @@ +<% if resource.errors.any? %> +
+

+ <%= I18n.t("errors.messages.not_saved", + count: resource.errors.count, + resource: resource.class.model_name.human.downcase) + %> +

+
    + <% resource.errors.full_messages.each do |message| %> +
  • <%= message %>
  • + <% end %> +
+
+<% end %> diff --git a/app/views/admins/shared/_links.html.erb b/app/views/admins/shared/_links.html.erb new file mode 100644 index 000000000..084af701c --- /dev/null +++ b/app/views/admins/shared/_links.html.erb @@ -0,0 +1,25 @@ +<%- if controller_name != 'sessions' %> + <%= link_to "Log in", new_session_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.registerable? && controller_name != 'registrations' %> + <%= link_to "Sign up", new_registration_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> + <%= link_to "Forgot your password?", new_password_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> + <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> + <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.omniauthable? %> + <%- resource_class.omniauth_providers.each do |provider| %> + <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %>
+ <% end %> +<% end %> diff --git a/app/views/admins/unlocks/new.html.erb b/app/views/admins/unlocks/new.html.erb new file mode 100644 index 000000000..8aabfd47b --- /dev/null +++ b/app/views/admins/unlocks/new.html.erb @@ -0,0 +1,16 @@ +

Resend unlock instructions

+ +<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> + <%= render "admins/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.submit "Resend unlock instructions" %> +
+<% end %> + +<%= render "admins/shared/links" %> diff --git a/app/views/landing/signupUser.html.erb b/app/views/landing/signupUser.html.erb new file mode 100644 index 000000000..d5db96229 --- /dev/null +++ b/app/views/landing/signupUser.html.erb @@ -0,0 +1,4 @@ +

Welcome to the Signup page

+ +# link_to 'Categories List', categories_path| +# link_to 'Home page', root_path \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 73221bbe8..4e52ccbf3 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -11,5 +11,7 @@ <%= yield %> +

<%= notice %>

+

<%= alert %>

diff --git a/app/views/users/confirmations/new.html.erb b/app/views/users/confirmations/new.html.erb new file mode 100644 index 000000000..4af186b28 --- /dev/null +++ b/app/views/users/confirmations/new.html.erb @@ -0,0 +1,16 @@ +

Resend confirmation instructions

+ +<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> + <%= render "users/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> +
+ +
+ <%= f.submit "Resend confirmation instructions" %> +
+<% end %> + +<%= render "users/shared/links" %> diff --git a/app/views/users/mailer/confirmation_instructions.html.erb b/app/views/users/mailer/confirmation_instructions.html.erb new file mode 100644 index 000000000..dc55f64f6 --- /dev/null +++ b/app/views/users/mailer/confirmation_instructions.html.erb @@ -0,0 +1,5 @@ +

Welcome <%= @email %>!

+ +

You can confirm your account email through the link below:

+ +

<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>

diff --git a/app/views/users/mailer/email_changed.html.erb b/app/views/users/mailer/email_changed.html.erb new file mode 100644 index 000000000..32f4ba803 --- /dev/null +++ b/app/views/users/mailer/email_changed.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @email %>!

+ +<% if @resource.try(:unconfirmed_email?) %> +

We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.

+<% else %> +

We're contacting you to notify you that your email has been changed to <%= @resource.email %>.

+<% end %> diff --git a/app/views/users/mailer/password_change.html.erb b/app/views/users/mailer/password_change.html.erb new file mode 100644 index 000000000..b41daf476 --- /dev/null +++ b/app/views/users/mailer/password_change.html.erb @@ -0,0 +1,3 @@ +

Hello <%= @resource.email %>!

+ +

We're contacting you to notify you that your password has been changed.

diff --git a/app/views/users/mailer/reset_password_instructions.html.erb b/app/views/users/mailer/reset_password_instructions.html.erb new file mode 100644 index 000000000..f667dc12f --- /dev/null +++ b/app/views/users/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +

Hello <%= @resource.email %>!

+ +

Someone has requested a link to change your password. You can do this through the link below.

+ +

<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

+ +

If you didn't request this, please ignore this email.

+

Your password won't change until you access the link above and create a new one.

diff --git a/app/views/users/mailer/unlock_instructions.html.erb b/app/views/users/mailer/unlock_instructions.html.erb new file mode 100644 index 000000000..41e148bf2 --- /dev/null +++ b/app/views/users/mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @resource.email %>!

+ +

Your account has been locked due to an excessive number of unsuccessful sign in attempts.

+ +

Click the link below to unlock your account:

+ +

<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>

diff --git a/app/views/users/passwords/edit.html.erb b/app/views/users/passwords/edit.html.erb new file mode 100644 index 000000000..863ffbb22 --- /dev/null +++ b/app/views/users/passwords/edit.html.erb @@ -0,0 +1,25 @@ +

Change your password

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> + <%= render "users/shared/error_messages", resource: resource %> + <%= f.hidden_field :reset_password_token %> + +
+ <%= f.label :password, "New password" %>
+ <% if @minimum_password_length %> + (<%= @minimum_password_length %> characters minimum)
+ <% end %> + <%= f.password_field :password, autofocus: true, autocomplete: "new-password" %> +
+ +
+ <%= f.label :password_confirmation, "Confirm new password" %>
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
+ +
+ <%= f.submit "Change my password" %> +
+<% end %> + +<%= render "users/shared/links" %> diff --git a/app/views/users/passwords/new.html.erb b/app/views/users/passwords/new.html.erb new file mode 100644 index 000000000..3b30b06d6 --- /dev/null +++ b/app/views/users/passwords/new.html.erb @@ -0,0 +1,16 @@ +

Forgot your password?

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= render "users/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.submit "Send me reset password instructions" %> +
+<% end %> + +<%= render "users/shared/links" %> diff --git a/app/views/users/registrations/edit.html.erb b/app/views/users/registrations/edit.html.erb new file mode 100644 index 000000000..038cd9459 --- /dev/null +++ b/app/views/users/registrations/edit.html.erb @@ -0,0 +1,43 @@ +

Edit <%= resource_name.to_s.humanize %>

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> + <%= render "users/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> +
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
+ <% end %> + +
+ <%= f.label :password %> (leave blank if you don't want to change it)
+ <%= f.password_field :password, autocomplete: "new-password" %> + <% if @minimum_password_length %> +
+ <%= @minimum_password_length %> characters minimum + <% end %> +
+ +
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
+ +
+ <%= f.label :current_password %> (we need your current password to confirm your changes)
+ <%= f.password_field :current_password, autocomplete: "current-password" %> +
+ +
+ <%= f.submit "Update" %> +
+<% end %> + +

Cancel my account

+ +

Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>

+ +<%= link_to "Back", :back %> diff --git a/app/views/users/registrations/new.html.erb b/app/views/users/registrations/new.html.erb new file mode 100644 index 000000000..61d1e4c7a --- /dev/null +++ b/app/views/users/registrations/new.html.erb @@ -0,0 +1,29 @@ +

Sign up

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> + <%= render "users/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.label :password %> + <% if @minimum_password_length %> + (<%= @minimum_password_length %> characters minimum) + <% end %>
+ <%= f.password_field :password, autocomplete: "new-password" %> +
+ +
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
+ +
+ <%= f.submit "Sign up" %> +
+<% end %> + +<%= render "users/shared/links" %> diff --git a/app/views/users/sessions/new.html.erb b/app/views/users/sessions/new.html.erb new file mode 100644 index 000000000..8c4864b89 --- /dev/null +++ b/app/views/users/sessions/new.html.erb @@ -0,0 +1,26 @@ +

Log in

+ +<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.label :password %>
+ <%= f.password_field :password, autocomplete: "current-password" %> +
+ + <% if devise_mapping.rememberable? %> +
+ <%= f.check_box :remember_me %> + <%= f.label :remember_me %> +
+ <% end %> + +
+ <%= f.submit "Log in" %> +
+<% end %> + +<%= render "users/shared/links" %> diff --git a/app/views/users/shared/_error_messages.html.erb b/app/views/users/shared/_error_messages.html.erb new file mode 100644 index 000000000..ba7ab8870 --- /dev/null +++ b/app/views/users/shared/_error_messages.html.erb @@ -0,0 +1,15 @@ +<% if resource.errors.any? %> +
+

+ <%= I18n.t("errors.messages.not_saved", + count: resource.errors.count, + resource: resource.class.model_name.human.downcase) + %> +

+
    + <% resource.errors.full_messages.each do |message| %> +
  • <%= message %>
  • + <% end %> +
+
+<% end %> diff --git a/app/views/users/shared/_links.html.erb b/app/views/users/shared/_links.html.erb new file mode 100644 index 000000000..084af701c --- /dev/null +++ b/app/views/users/shared/_links.html.erb @@ -0,0 +1,25 @@ +<%- if controller_name != 'sessions' %> + <%= link_to "Log in", new_session_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.registerable? && controller_name != 'registrations' %> + <%= link_to "Sign up", new_registration_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> + <%= link_to "Forgot your password?", new_password_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> + <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> + <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.omniauthable? %> + <%- resource_class.omniauth_providers.each do |provider| %> + <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %>
+ <% end %> +<% end %> diff --git a/app/views/users/unlocks/new.html.erb b/app/views/users/unlocks/new.html.erb new file mode 100644 index 000000000..2f4fab848 --- /dev/null +++ b/app/views/users/unlocks/new.html.erb @@ -0,0 +1,16 @@ +

Resend unlock instructions

+ +<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> + <%= render "users/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.submit "Resend unlock instructions" %> +
+<% end %> + +<%= render "users/shared/links" %> diff --git a/config/environments/development.rb b/config/environments/development.rb index 66df51f6f..412dda94d 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -35,6 +35,9 @@ config.action_mailer.raise_delivery_errors = false config.action_mailer.perform_caching = false + + # The generator will install an initializer which describes ALL of Devise's configuration options. + config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log diff --git a/config/environments/test.rb b/config/environments/test.rb index 0cb24249b..07ae7e89b 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -12,7 +12,7 @@ # Do not eager load code on boot. This avoids loading your whole application # just for the purpose of running a single test. If you are using a tool that # preloads Rails for running tests, you may have to set it to true. - config.eager_load = false + config.eager_load = true # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb new file mode 100644 index 000000000..79e5e47f4 --- /dev/null +++ b/config/initializers/devise.rb @@ -0,0 +1,311 @@ +# frozen_string_literal: true + +# Assuming you have not yet modified this file, each configuration option below +# is set to its default value. Note that some are commented out while others +# are not: uncommented lines are intended to protect your configuration from +# breaking changes in upgrades (i.e., in the event that future versions of +# Devise change the default values for those options). +# +# Use this hook to configure devise mailer, warden hooks and so forth. +# Many of these configuration options can be set straight in your model. +Devise.setup do |config| + # The secret key used by Devise. Devise uses this key to generate + # random tokens. Changing this key will render invalid all existing + # confirmation, reset password and unlock tokens in the database. + # Devise will use the `secret_key_base` as its `secret_key` + # by default. You can change it below and use your own secret key. + # config.secret_key = '83805d3ba8ea6861e821b00afff7612ea12c758e67218bd579a168b26bfcf0c8195ccaf9c51f07c4f759e803ebae9ba15906263232c9407f07567fc93c28b141' + + # ==> Controller configuration + # Configure the parent class to the devise controllers. + # config.parent_controller = 'DeviseController' + + # ==> Mailer Configuration + # Configure the e-mail address which will be shown in Devise::Mailer, + # note that it will be overwritten if you use your own mailer class + # with default "from" parameter. + config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' + + # Configure the class responsible to send e-mails. + # config.mailer = 'Devise::Mailer' + + # Configure the parent class responsible to send e-mails. + # config.parent_mailer = 'ActionMailer::Base' + + # ==> ORM configuration + # Load and configure the ORM. Supports :active_record (default) and + # :mongoid (bson_ext recommended) by default. Other ORMs may be + # available as additional gems. + require 'devise/orm/active_record' + + # ==> Configuration for any authentication mechanism + # Configure which keys are used when authenticating a user. The default is + # just :email. You can configure it to use [:username, :subdomain], so for + # authenticating a user, both parameters are required. Remember that those + # parameters are used only when authenticating and not when retrieving from + # session. If you need permissions, you should implement that in a before filter. + # You can also supply a hash where the value is a boolean determining whether + # or not authentication should be aborted when the value is not present. + # config.authentication_keys = [:email] + + # Configure parameters from the request object used for authentication. Each entry + # given should be a request method and it will automatically be passed to the + # find_for_authentication method and considered in your model lookup. For instance, + # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. + # The same considerations mentioned for authentication_keys also apply to request_keys. + # config.request_keys = [] + + # Configure which authentication keys should be case-insensitive. + # These keys will be downcased upon creating or modifying a user and when used + # to authenticate or find a user. Default is :email. + config.case_insensitive_keys = [:email] + + # Configure which authentication keys should have whitespace stripped. + # These keys will have whitespace before and after removed upon creating or + # modifying a user and when used to authenticate or find a user. Default is :email. + config.strip_whitespace_keys = [:email] + + # Tell if authentication through request.params is enabled. True by default. + # It can be set to an array that will enable params authentication only for the + # given strategies, for example, `config.params_authenticatable = [:database]` will + # enable it only for database (email + password) authentication. + # config.params_authenticatable = true + + # Tell if authentication through HTTP Auth is enabled. False by default. + # It can be set to an array that will enable http authentication only for the + # given strategies, for example, `config.http_authenticatable = [:database]` will + # enable it only for database authentication. + # For API-only applications to support authentication "out-of-the-box", you will likely want to + # enable this with :database unless you are using a custom strategy. + # The supported strategies are: + # :database = Support basic authentication with authentication key + password + # config.http_authenticatable = false + + # If 401 status code should be returned for AJAX requests. True by default. + # config.http_authenticatable_on_xhr = true + + # The realm used in Http Basic Authentication. 'Application' by default. + # config.http_authentication_realm = 'Application' + + # It will change confirmation, password recovery and other workflows + # to behave the same regardless if the e-mail provided was right or wrong. + # Does not affect registerable. + # config.paranoid = true + + # By default Devise will store the user in session. You can skip storage for + # particular strategies by setting this option. + # Notice that if you are skipping storage for all authentication paths, you + # may want to disable generating routes to Devise's sessions controller by + # passing skip: :sessions to `devise_for` in your config/routes.rb + config.skip_session_storage = [:http_auth] + + # By default, Devise cleans up the CSRF token on authentication to + # avoid CSRF token fixation attacks. This means that, when using AJAX + # requests for sign in and sign up, you need to get a new CSRF token + # from the server. You can disable this option at your own risk. + # config.clean_up_csrf_token_on_authentication = true + + # When false, Devise will not attempt to reload routes on eager load. + # This can reduce the time taken to boot the app but if your application + # requires the Devise mappings to be loaded during boot time the application + # won't boot properly. + # config.reload_routes = true + + # ==> Configuration for :database_authenticatable + # For bcrypt, this is the cost for hashing the password and defaults to 12. If + # using other algorithms, it sets how many times you want the password to be hashed. + # The number of stretches used for generating the hashed password are stored + # with the hashed password. This allows you to change the stretches without + # invalidating existing passwords. + # + # Limiting the stretches to just one in testing will increase the performance of + # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use + # a value less than 10 in other environments. Note that, for bcrypt (the default + # algorithm), the cost increases exponentially with the number of stretches (e.g. + # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). + config.stretches = Rails.env.test? ? 1 : 12 + + # Set up a pepper to generate the hashed password. + # config.pepper = '76423e33ccdb0f3616386aee2ce9659a68afbfaa69ccc920b519744fc5e946d8e7f81afea4c7523e9948831a735ad1a14fc4f17d5094d924e3695380d0a53014' + + # Send a notification to the original email when the user's email is changed. + # config.send_email_changed_notification = false + + # Send a notification email when the user's password is changed. + # config.send_password_change_notification = false + + # ==> Configuration for :confirmable + # A period that the user is allowed to access the website even without + # confirming their account. For instance, if set to 2.days, the user will be + # able to access the website for two days without confirming their account, + # access will be blocked just in the third day. + # You can also set it to nil, which will allow the user to access the website + # without confirming their account. + # Default is 0.days, meaning the user cannot access the website without + # confirming their account. + # config.allow_unconfirmed_access_for = 2.days + + # A period that the user is allowed to confirm their account before their + # token becomes invalid. For example, if set to 3.days, the user can confirm + # their account within 3 days after the mail was sent, but on the fourth day + # their account can't be confirmed with the token any more. + # Default is nil, meaning there is no restriction on how long a user can take + # before confirming their account. + # config.confirm_within = 3.days + + # If true, requires any email changes to be confirmed (exactly the same way as + # initial account confirmation) to be applied. Requires additional unconfirmed_email + # db field (see migrations). Until confirmed, new email is stored in + # unconfirmed_email column, and copied to email column on successful confirmation. + config.reconfirmable = true + + # Defines which key will be used when confirming an account + # config.confirmation_keys = [:email] + + # ==> Configuration for :rememberable + # The time the user will be remembered without asking for credentials again. + # config.remember_for = 2.weeks + + # Invalidates all the remember me tokens when the user signs out. + config.expire_all_remember_me_on_sign_out = true + + # If true, extends the user's remember period when remembered via cookie. + # config.extend_remember_period = false + + # Options to be passed to the created cookie. For instance, you can set + # secure: true in order to force SSL only cookies. + # config.rememberable_options = {} + + # ==> Configuration for :validatable + # Range for password length. + config.password_length = 6..128 + + # Email regex used to validate email formats. It simply asserts that + # one (and only one) @ exists in the given string. This is mainly + # to give user feedback and not to assert the e-mail validity. + config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ + + # ==> Configuration for :timeoutable + # The time you want to timeout the user session without activity. After this + # time the user will be asked for credentials again. Default is 30 minutes. + # config.timeout_in = 30.minutes + + # ==> Configuration for :lockable + # Defines which strategy will be used to lock an account. + # :failed_attempts = Locks an account after a number of failed attempts to sign in. + # :none = No lock strategy. You should handle locking by yourself. + # config.lock_strategy = :failed_attempts + + # Defines which key will be used when locking and unlocking an account + # config.unlock_keys = [:email] + + # Defines which strategy will be used to unlock an account. + # :email = Sends an unlock link to the user email + # :time = Re-enables login after a certain amount of time (see :unlock_in below) + # :both = Enables both strategies + # :none = No unlock strategy. You should handle unlocking by yourself. + # config.unlock_strategy = :both + + # Number of authentication tries before locking an account if lock_strategy + # is failed attempts. + # config.maximum_attempts = 20 + + # Time interval to unlock the account if :time is enabled as unlock_strategy. + # config.unlock_in = 1.hour + + # Warn on the last attempt before the account is locked. + # config.last_attempt_warning = true + + # ==> Configuration for :recoverable + # + # Defines which key will be used when recovering the password for an account + # config.reset_password_keys = [:email] + + # Time interval you can reset your password with a reset password key. + # Don't put a too small interval or your users won't have the time to + # change their passwords. + config.reset_password_within = 6.hours + + # When set to false, does not sign a user in automatically after their password is + # reset. Defaults to true, so a user is signed in automatically after a reset. + # config.sign_in_after_reset_password = true + + # ==> Configuration for :encryptable + # Allow you to use another hashing or encryption algorithm besides bcrypt (default). + # You can use :sha1, :sha512 or algorithms from others authentication tools as + # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 + # for default behavior) and :restful_authentication_sha1 (then you should set + # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). + # + # Require the `devise-encryptable` gem when using anything other than bcrypt + # config.encryptor = :sha512 + + # ==> Scopes configuration + # Turn scoped views on. Before rendering "sessions/new", it will first check for + # "users/sessions/new". It's turned off by default because it's slower if you + # are using only default views. + # config.scoped_views = false + + # Configure the default scope given to Warden. By default it's the first + # devise role declared in your routes (usually :user). + # config.default_scope = :user + + # Set this configuration to false if you want /users/sign_out to sign out + # only the current scope. By default, Devise signs out all scopes. + # config.sign_out_all_scopes = true + + # ==> Navigation configuration + # Lists the formats that should be treated as navigational. Formats like + # :html, should redirect to the sign in page when the user does not have + # access, but formats like :xml or :json, should return 401. + # + # If you have any extra navigational formats, like :iphone or :mobile, you + # should add them to the navigational formats lists. + # + # The "*/*" below is required to match Internet Explorer requests. + # config.navigational_formats = ['*/*', :html] + + # The default HTTP method used to sign out a resource. Default is :delete. + config.sign_out_via = :delete + + # ==> OmniAuth + # Add a new OmniAuth provider. Check the wiki for more information on setting + # up on your models and hooks. + # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' + + # ==> Warden configuration + # If you want to use other strategies, that are not supported by Devise, or + # change the failure app, you can configure them inside the config.warden block. + # + # config.warden do |manager| + # manager.intercept_401 = false + # manager.default_strategies(scope: :user).unshift :some_external_strategy + # end + + # ==> Mountable engine configurations + # When using Devise inside an engine, let's call it `MyEngine`, and this engine + # is mountable, there are some extra configurations to be taken into account. + # The following options are available, assuming the engine is mounted as: + # + # mount MyEngine, at: '/my_engine' + # + # The router that invoked `devise_for`, in the example above, would be: + # config.router_name = :my_engine + # + # When using OmniAuth, Devise cannot automatically set OmniAuth path, + # so you need to do it manually. For the users scope, it would be: + # config.omniauth_path_prefix = '/my_engine/users/auth' + + # ==> Turbolinks configuration + # If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly: + # + # ActiveSupport.on_load(:devise_failure_app) do + # include Turbolinks::Controller + # end + + # ==> Configuration for :registerable + + # When set to false, does not sign a user in automatically after their password is + # changed. Defaults to true, so a user is signed in automatically after changing a password. + # config.sign_in_after_change_password = true +end diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml new file mode 100644 index 000000000..c9602d553 --- /dev/null +++ b/config/locales/devise.en.yml @@ -0,0 +1,67 @@ +# Additional translations at https://github.com/heartcombo/devise/wiki/I18n + +en: + devise: + confirmations: + admin_user: + confirmed: "Your ADMIN email address has been successfully confirmed." + confirmed: "Your email address has been successfully confirmed." + send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes." + send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes." + failure: + already_authenticated: "You are already signed in." + inactive: "Your account is not activated yet." + invalid: "Invalid %{authentication_keys} or password." + locked: "Your account is locked." + last_attempt: "You have one more attempt before your account is locked." + not_found_in_database: "Invalid %{authentication_keys} or password." + timeout: "Your session expired. Please sign in again to continue." + unauthenticated: "You need to sign in or sign up before continuing." + unconfirmed: "You have to confirm your email address before continuing." + mailer: + confirmation_instructions: + subject: "Confirmation instructions" + reset_password_instructions: + subject: "Reset password instructions" + unlock_instructions: + subject: "Unlock instructions" + email_changed: + subject: "Email Changed" + password_change: + subject: "Password Changed" + omniauth_callbacks: + failure: "Could not authenticate you from %{kind} because \"%{reason}\"." + success: "Successfully authenticated from %{kind} account." + passwords: + no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." + send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." + send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." + updated: "Your password has been changed successfully. You are now signed in." + updated_not_active: "Your password has been changed successfully." + registrations: + destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon." + signed_up: "Welcome! You have signed up successfully." + signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." + signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." + signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account." + update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirmation link to confirm your new email address." + updated: "Your account has been updated successfully." + updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again" + sessions: + signed_in: "Signed in successfully." + signed_out: "Signed out successfully." + already_signed_out: "Signed out successfully." + unlocks: + send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes." + send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes." + unlocked: "Your account has been unlocked successfully. Please sign in to continue." + errors: + messages: + already_confirmed: "was already confirmed, please try signing in" + confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" + expired: "has expired, please request a new one" + not_found: "not found" + not_locked: "was not locked" + not_saved: + one: "1 error prohibited this %{resource} from being saved:" + other: "%{count} errors prohibited this %{resource} from being saved:" diff --git a/config/routes.rb b/config/routes.rb index c06383a17..702999366 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ Rails.application.routes.draw do - # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html + devise_for :admins, path: 'admins', controllers: { sessions: "admins/sessions" } + devise_for :users, path: 'users', controllers: { sessions: "users/sessions" } + root 'landing#signupUser' end diff --git a/db/migrate/20210914112235_devise_create_users.rb b/db/migrate/20210914112235_devise_create_users.rb new file mode 100644 index 000000000..b59e3e13c --- /dev/null +++ b/db/migrate/20210914112235_devise_create_users.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class DeviseCreateUsers < ActiveRecord::Migration[6.0] + def change + create_table :users do |t| + ## Database authenticatable + t.string :email, null: false, default: "" + t.string :encrypted_password, null: false, default: "" + + ## Recoverable + t.string :reset_password_token + t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + # t.integer :sign_in_count, default: 0, null: false + # t.datetime :current_sign_in_at + # t.datetime :last_sign_in_at + # t.inet :current_sign_in_ip + # t.inet :last_sign_in_ip + + ## Confirmable + # t.string :confirmation_token + # t.datetime :confirmed_at + # t.datetime :confirmation_sent_at + # t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts + # t.string :unlock_token # Only if unlock strategy is :email or :both + # t.datetime :locked_at + + + t.timestamps null: false + end + + add_index :users, :email, unique: true + add_index :users, :reset_password_token, unique: true + # add_index :users, :confirmation_token, unique: true + # add_index :users, :unlock_token, unique: true + end +end diff --git a/db/migrate/20210914112343_devise_create_admins.rb b/db/migrate/20210914112343_devise_create_admins.rb new file mode 100644 index 000000000..e0c0b1a1b --- /dev/null +++ b/db/migrate/20210914112343_devise_create_admins.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class DeviseCreateAdmins < ActiveRecord::Migration[6.0] + def change + create_table :admins do |t| + ## Database authenticatable + t.string :email, null: false, default: "" + t.string :encrypted_password, null: false, default: "" + + ## Recoverable + t.string :reset_password_token + t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + # t.integer :sign_in_count, default: 0, null: false + # t.datetime :current_sign_in_at + # t.datetime :last_sign_in_at + # t.inet :current_sign_in_ip + # t.inet :last_sign_in_ip + + ## Confirmable + # t.string :confirmation_token + # t.datetime :confirmed_at + # t.datetime :confirmation_sent_at + # t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts + # t.string :unlock_token # Only if unlock strategy is :email or :both + # t.datetime :locked_at + + + t.timestamps null: false + end + + add_index :admins, :email, unique: true + add_index :admins, :reset_password_token, unique: true + # add_index :admins, :confirmation_token, unique: true + # add_index :admins, :unlock_token, unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index b10373ba6..f94817d58 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,9 +10,33 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 0) do +ActiveRecord::Schema.define(version: 2021_09_14_112343) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "admins", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["email"], name: "index_admins_on_email", unique: true + t.index ["reset_password_token"], name: "index_admins_on_reset_password_token", unique: true + end + + create_table "users", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["email"], name: "index_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + end + end diff --git a/spec/models/admin_spec.rb b/spec/models/admin_spec.rb new file mode 100644 index 000000000..3fd73fb6c --- /dev/null +++ b/spec/models/admin_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Admin, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/trial_user_spec.rb b/spec/models/trial_user_spec.rb new file mode 100644 index 000000000..5bbda6d84 --- /dev/null +++ b/spec/models/trial_user_spec.rb @@ -0,0 +1,28 @@ +require 'rails_helper' + + it "is valid with valid attributes" do + user1 = User.new(email: 'email@example.com', password: 'password') + expect(user1).to be_valid + end + + it "is not valid without first_name" do + user2 = User.new(first_name: nil) + expect(user2).to_not be_valid + end + + it "is not valid without last_name" do + user2 = User.new(last_name: nil) + expect(user2).to_not be_valid + end + + it "is not valid without email" do + user2 = User.new(email: nil) + expect(user2).to_not be_valid + end + + it "is not valid without username" do + user2 = User.new(username: nil) + expect(user2).to_not be_valid + end + +end \ No newline at end of file diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 000000000..47a31bb43 --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe User, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 69a565b8e..7dc06776a 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -5,37 +5,61 @@ # Prevent database truncation if the environment is production abort("The Rails environment is running in production mode!") if Rails.env.production? require 'rspec/rails' -require 'shoulda/matchers' -require 'factory_bot_rails' +# Add additional requires below this line. Rails is not loaded until this point! -Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } +# Checks for pending migrations and applies them before tests are run. +# If you are not using ActiveRecord, you can remove these lines. begin ActiveRecord::Migration.maintain_test_schema! rescue ActiveRecord::PendingMigrationError => e puts e.to_s.strip exit 1 end - RSpec.configure do |config| - config.use_transactional_fixtures = false - config.infer_spec_type_from_file_location! - config.filter_rails_from_backtrace! + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/fixtures" - config.include FactoryBot::Syntax::Methods + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true - config.before(:suite) do - DatabaseRewinder.clean_all - end + # You can uncomment this line to turn off ActiveRecord support entirely. + # config.use_active_record = false - config.after(:each) do - DatabaseRewinder.clean - end -end + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, type: :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs + config.infer_spec_type_from_file_location! + + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! + # arbitrary gems may also be filtered via: + # config.filter_gems_from_backtrace("gem name") -Shoulda::Matchers.configure do |config| - config.integrate do |with| - with.test_framework :rspec - with.library :rails - end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ce33d66df..577504942 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -93,4 +93,5 @@ # as the one that triggered the failure. Kernel.srand config.seed =end +config.warnings = false end From 8ff0b05295bb747aa1c2ebc81126b9a94ee85702 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 14 Sep 2021 20:25:45 +0800 Subject: [PATCH 006/106] rubocop configures and addressed the offenses --- app/controllers/landing_controller.rb | 2 +- spec/models/trial_user_spec.rb | 42 +++++++++++++-------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/app/controllers/landing_controller.rb b/app/controllers/landing_controller.rb index be713a113..2ac34fa05 100644 --- a/app/controllers/landing_controller.rb +++ b/app/controllers/landing_controller.rb @@ -2,4 +2,4 @@ class LandingController < ApplicationController def index @categories = Category.all end -end \ No newline at end of file +end diff --git a/spec/models/trial_user_spec.rb b/spec/models/trial_user_spec.rb index 5bbda6d84..29755360b 100644 --- a/spec/models/trial_user_spec.rb +++ b/spec/models/trial_user_spec.rb @@ -1,28 +1,26 @@ require 'rails_helper' - it "is valid with valid attributes" do - user1 = User.new(email: 'email@example.com', password: 'password') - expect(user1).to be_valid - end +it 'is valid with valid attributes' do + user1 = User.new(email: 'email@example.com', password: 'password') + expect(user1).to be_valid +end - it "is not valid without first_name" do - user2 = User.new(first_name: nil) - expect(user2).to_not be_valid - end +it 'is not valid without first_name' do + user2 = User.new(first_name: nil) + expect(user2).not_to be_valid +end - it "is not valid without last_name" do - user2 = User.new(last_name: nil) - expect(user2).to_not be_valid - end +it 'is not valid without last_name' do + user2 = User.new(last_name: nil) + expect(user2).not_to be_valid +end - it "is not valid without email" do - user2 = User.new(email: nil) - expect(user2).to_not be_valid - end +it 'is not valid without email' do + user2 = User.new(email: nil) + expect(user2).not_to be_valid +end - it "is not valid without username" do - user2 = User.new(username: nil) - expect(user2).to_not be_valid - end - -end \ No newline at end of file +it 'is not valid without username' do + user2 = User.new(username: nil) + expect(user2).not_to be_valid +end From 99469c9beffd4b4d6f8c05f9c0ed82446e3672a5 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 14 Sep 2021 20:47:01 +0800 Subject: [PATCH 007/106] adjusted the rspec configuration --- spec/models/trial_user_spec.rb | 43 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/spec/models/trial_user_spec.rb b/spec/models/trial_user_spec.rb index 29755360b..4c0946e88 100644 --- a/spec/models/trial_user_spec.rb +++ b/spec/models/trial_user_spec.rb @@ -1,26 +1,27 @@ require 'rails_helper' +RSpec.describe User, type: :model do + it 'is valid with valid attributes' do + user1 = User.new(email: 'email@example.com', password: 'password') + expect(user1).to be_valid + end -it 'is valid with valid attributes' do - user1 = User.new(email: 'email@example.com', password: 'password') - expect(user1).to be_valid -end + it 'is not valid without first_name' do + user2 = User.new(first_name: nil) + expect(user2).not_to be_valid + end -it 'is not valid without first_name' do - user2 = User.new(first_name: nil) - expect(user2).not_to be_valid -end + it 'is not valid without last_name' do + user2 = User.new(last_name: nil) + expect(user2).not_to be_valid + end -it 'is not valid without last_name' do - user2 = User.new(last_name: nil) - expect(user2).not_to be_valid -end + it 'is not valid without email' do + user2 = User.new(email: nil) + expect(user2).not_to be_valid + end -it 'is not valid without email' do - user2 = User.new(email: nil) - expect(user2).not_to be_valid -end - -it 'is not valid without username' do - user2 = User.new(username: nil) - expect(user2).not_to be_valid -end + it 'is not valid without username' do + user2 = User.new(username: nil) + expect(user2).not_to be_valid + end +end \ No newline at end of file From a63702501153421bc120ac9a327fa913ed2f9295 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 14 Sep 2021 20:51:42 +0800 Subject: [PATCH 008/106] rubocop -A on the rspec --- spec/models/trial_user_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/models/trial_user_spec.rb b/spec/models/trial_user_spec.rb index 4c0946e88..c9afb0113 100644 --- a/spec/models/trial_user_spec.rb +++ b/spec/models/trial_user_spec.rb @@ -1,27 +1,27 @@ require 'rails_helper' RSpec.describe User, type: :model do it 'is valid with valid attributes' do - user1 = User.new(email: 'email@example.com', password: 'password') + user1 = described_class.new(email: 'email@example.com', password: 'password') expect(user1).to be_valid end it 'is not valid without first_name' do - user2 = User.new(first_name: nil) + user2 = described_class.new(first_name: nil) expect(user2).not_to be_valid end it 'is not valid without last_name' do - user2 = User.new(last_name: nil) + user2 = described_class.new(last_name: nil) expect(user2).not_to be_valid end it 'is not valid without email' do - user2 = User.new(email: nil) + user2 = described_class.new(email: nil) expect(user2).not_to be_valid end it 'is not valid without username' do - user2 = User.new(username: nil) + user2 = described_class.new(username: nil) expect(user2).not_to be_valid end -end \ No newline at end of file +end From 34632d221c81643340556d96114a5c574b8394b0 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 14 Sep 2021 23:46:20 +0800 Subject: [PATCH 009/106] configurations for credentials --- config/credentials.yml.enc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc index 13bec8b12..83cd5f07c 100644 --- a/config/credentials.yml.enc +++ b/config/credentials.yml.enc @@ -1 +1 @@ -vGGT60HbIwlvjrOSj8QkGzQ+EqBcuWQJziz4siEGjSykZwqibwIc5BZChF2C3wBvxcuXygOObUvRGWcp+B58qkXoCUjwueUUhnkq4Utn0QcjV/5rmsVdVuLC2V7ZmxT/IKgviPzOa1Iz7PN7tBrqJTZoi6KrqYYYWRnXSvC0lLDkdqoKG35CEKRcdLtt385m4rK3JWWQXOVJXLSlQhCANW0XvXvZEJtm8E0LCwUx98SXoV8WRO//B4i7CUv56H61daxxSb9A940DcRkDR6dJLDOAyCJbuOGgsyoX3R4ybiK4xNzS9XXLmiUyXfdRxeAJAeB0Bthc4+8tymmiEd5Nlo8U5mwAN8U149b/5wBbw4vKMPkdNxCLMygLjC84rbMtJTrxCsdRHjQ+YbCrxirhEFQNHM2XyUoJ06WD--RYah7W4NWRhsH2Sf--TLLM8vHkIpbAHY802vtuIA== \ No newline at end of file +QzjEfydORpoXOilvr1H8vgG+d7e1MyaoXa9OEyGTSpkRRi9b4djK7CfGCjB2djAjS6PB7k3Q8N360k8NR5ikqEoVIC+scZ5SdgGZLX1mjezGeCUmTgBuuNnO1uae3R9a8N4YLJ1sYpRGGXHmB1Q+gQVtX7idmDVgkBSbxCXIcQGN3ekyFudOOinAn0Yq4LwZEx5MuYP7FeAaKtpn5hYXb5NCAM8p35IQXzRKs6rEgHfO0iFE3KDNnB6lUaVoejj9F5xqKdYv+F1J/Ylc/yqizu86+1ZjU5gwnpNiDA+0gIa58bjq+QzqxITZnz5BhVZGuEIxk7ihNvxrtsBKLrLYUVPcmnpkR0zq7NiUzucLGXquLg3571XPTC28vsFxUTLFglwk7yw/7fgqLOAaJjBxDW6xFkBe1fM884uY--AsmgQHHQMzwstd8l--U9pc2ccoua0zh9YTXj12Gw== \ No newline at end of file From 1f80fed00becddd05faada374d0250b199568362 Mon Sep 17 00:00:00 2001 From: stephdajon Date: Tue, 14 Sep 2021 23:59:00 +0800 Subject: [PATCH 010/106] Added home page --- Gemfile | 2 +- Gemfile.lock | 212 +++++++++++++++---------- app/assets/stylesheets/home.scss | 3 + app/controllers/home_controller.rb | 15 ++ app/helpers/home_helper.rb | 2 + app/views/home/_header.html.erb | 32 ++++ app/views/home/index.html.erb | 2 + app/views/layouts/application.html.erb | 32 +++- config/routes.rb | 2 + 9 files changed, 209 insertions(+), 93 deletions(-) create mode 100644 app/assets/stylesheets/home.scss create mode 100644 app/controllers/home_controller.rb create mode 100644 app/helpers/home_helper.rb create mode 100644 app/views/home/_header.html.erb create mode 100644 app/views/home/index.html.erb diff --git a/Gemfile b/Gemfile index ba5697f15..878eb9d45 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ gem 'turbolinks', '~> 5' gem 'jbuilder', '~> 2.7' gem 'bootsnap', '>= 1.4.2', require: false gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] - +gem 'iex-ruby-client' gem 'devise' gem 'hamlit-rails' diff --git a/Gemfile.lock b/Gemfile.lock index b425d0d31..fad5339f4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,76 +1,76 @@ GEM remote: https://rubygems.org/ specs: - actioncable (6.0.3.6) - actionpack (= 6.0.3.6) + actioncable (6.0.4.1) + actionpack (= 6.0.4.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.0.3.6) - actionpack (= 6.0.3.6) - activejob (= 6.0.3.6) - activerecord (= 6.0.3.6) - activestorage (= 6.0.3.6) - activesupport (= 6.0.3.6) + actionmailbox (6.0.4.1) + actionpack (= 6.0.4.1) + activejob (= 6.0.4.1) + activerecord (= 6.0.4.1) + activestorage (= 6.0.4.1) + activesupport (= 6.0.4.1) mail (>= 2.7.1) - actionmailer (6.0.3.6) - actionpack (= 6.0.3.6) - actionview (= 6.0.3.6) - activejob (= 6.0.3.6) + actionmailer (6.0.4.1) + actionpack (= 6.0.4.1) + actionview (= 6.0.4.1) + activejob (= 6.0.4.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (6.0.3.6) - actionview (= 6.0.3.6) - activesupport (= 6.0.3.6) + actionpack (6.0.4.1) + actionview (= 6.0.4.1) + activesupport (= 6.0.4.1) rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.0.3.6) - actionpack (= 6.0.3.6) - activerecord (= 6.0.3.6) - activestorage (= 6.0.3.6) - activesupport (= 6.0.3.6) + actiontext (6.0.4.1) + actionpack (= 6.0.4.1) + activerecord (= 6.0.4.1) + activestorage (= 6.0.4.1) + activesupport (= 6.0.4.1) nokogiri (>= 1.8.5) - actionview (6.0.3.6) - activesupport (= 6.0.3.6) + actionview (6.0.4.1) + activesupport (= 6.0.4.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.0.3.6) - activesupport (= 6.0.3.6) + activejob (6.0.4.1) + activesupport (= 6.0.4.1) globalid (>= 0.3.6) - activemodel (6.0.3.6) - activesupport (= 6.0.3.6) - activerecord (6.0.3.6) - activemodel (= 6.0.3.6) - activesupport (= 6.0.3.6) - activestorage (6.0.3.6) - actionpack (= 6.0.3.6) - activejob (= 6.0.3.6) - activerecord (= 6.0.3.6) + activemodel (6.0.4.1) + activesupport (= 6.0.4.1) + activerecord (6.0.4.1) + activemodel (= 6.0.4.1) + activesupport (= 6.0.4.1) + activestorage (6.0.4.1) + actionpack (= 6.0.4.1) + activejob (= 6.0.4.1) + activerecord (= 6.0.4.1) marcel (~> 1.0.0) - activesupport (6.0.3.6) + activesupport (6.0.4.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) zeitwerk (~> 2.2, >= 2.2.2) - addressable (2.7.0) + addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) ast (2.4.2) bcrypt (3.1.16) bindex (0.8.1) - bootsnap (1.7.3) + bootsnap (1.8.1) msgpack (~> 1.0) builder (3.2.4) byebug (11.1.3) - concurrent-ruby (1.1.8) + concurrent-ruby (1.1.9) crack (0.4.5) rexml crass (1.0.6) - database_rewinder (0.9.4) - devise (4.7.3) + database_rewinder (0.9.6) + devise (4.8.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) @@ -78,15 +78,36 @@ GEM warden (~> 1.2.3) diff-lcs (1.4.4) erubi (1.10.0) - factory_bot (6.1.0) + factory_bot (6.2.0) activesupport (>= 5.0.0) - factory_bot_rails (6.1.0) - factory_bot (~> 6.1.0) + factory_bot_rails (6.2.0) + factory_bot (~> 6.2.0) railties (>= 5.0.0) - ffi (1.15.0) - globalid (0.4.2) - activesupport (>= 4.2.0) - hamlit (2.15.0) + faraday (1.7.1) + faraday-em_http (~> 1.0) + faraday-em_synchrony (~> 1.0) + faraday-excon (~> 1.1) + faraday-httpclient (~> 1.0.1) + faraday-net_http (~> 1.0) + faraday-net_http_persistent (~> 1.1) + faraday-patron (~> 1.0) + faraday-rack (~> 1.0) + multipart-post (>= 1.2, < 3) + ruby2_keywords (>= 0.0.4) + faraday-em_http (1.0.0) + faraday-em_synchrony (1.0.0) + faraday-excon (1.1.0) + faraday-httpclient (1.0.1) + faraday-net_http (1.0.1) + faraday-net_http_persistent (1.2.0) + faraday-patron (1.0.0) + faraday-rack (1.0.0) + faraday_middleware (1.1.0) + faraday (~> 1.0) + ffi (1.15.4) + globalid (0.5.2) + activesupport (>= 5.0) + hamlit (2.15.1) temple (>= 0.8.2) thor tilt @@ -96,71 +117,85 @@ GEM hamlit (>= 1.2.0) railties (>= 4.0.1) hashdiff (1.0.1) + hashie (4.1.0) i18n (1.8.10) concurrent-ruby (~> 1.0) + iex-ruby-client (1.5.0) + faraday (>= 0.17) + faraday_middleware + hashie + money_helper jbuilder (2.11.2) activesupport (>= 5.0.0) - listen (3.5.1) + listen (3.7.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.9.1) + loofah (2.12.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) marcel (1.0.1) method_source (1.0.0) - mini_mime (1.1.0) + mini_mime (1.1.1) + mini_portile2 (2.6.1) minitest (5.14.4) + money (6.16.0) + i18n (>= 0.6.4, <= 2) + money_helper (1.0.2) + activesupport + money (~> 6.5) msgpack (1.4.2) - nio4r (2.5.7) - nokogiri (1.11.3-x86_64-darwin) + multipart-post (2.1.1) + nio4r (2.5.8) + nokogiri (1.12.4) + mini_portile2 (~> 2.6.1) racc (~> 1.4) - nokogiri (1.11.3-x86_64-linux) + nokogiri (1.12.4-x86_64-linux) racc (~> 1.4) orm_adapter (0.5.0) parallel (1.20.1) - parser (3.0.1.0) + parser (3.0.2.0) ast (~> 2.4.1) pg (1.2.3) public_suffix (4.0.6) - puma (4.3.7) + puma (4.3.8) nio4r (~> 2.0) racc (1.5.2) rack (2.2.3) - rack-proxy (0.6.5) + rack-proxy (0.7.0) rack rack-test (1.1.0) rack (>= 1.0, < 3) - rails (6.0.3.6) - actioncable (= 6.0.3.6) - actionmailbox (= 6.0.3.6) - actionmailer (= 6.0.3.6) - actionpack (= 6.0.3.6) - actiontext (= 6.0.3.6) - actionview (= 6.0.3.6) - activejob (= 6.0.3.6) - activemodel (= 6.0.3.6) - activerecord (= 6.0.3.6) - activestorage (= 6.0.3.6) - activesupport (= 6.0.3.6) + rails (6.0.4.1) + actioncable (= 6.0.4.1) + actionmailbox (= 6.0.4.1) + actionmailer (= 6.0.4.1) + actionpack (= 6.0.4.1) + actiontext (= 6.0.4.1) + actionview (= 6.0.4.1) + activejob (= 6.0.4.1) + activemodel (= 6.0.4.1) + activerecord (= 6.0.4.1) + activestorage (= 6.0.4.1) + activesupport (= 6.0.4.1) bundler (>= 1.3.0) - railties (= 6.0.3.6) + railties (= 6.0.4.1) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.3.0) + rails-html-sanitizer (1.4.2) loofah (~> 2.3) - railties (6.0.3.6) - actionpack (= 6.0.3.6) - activesupport (= 6.0.3.6) + railties (6.0.4.1) + actionpack (= 6.0.4.1) + activesupport (= 6.0.4.1) method_source rake (>= 0.8.7) thor (>= 0.20.3, < 2.0) rainbow (3.0.0) - rake (13.0.3) - rb-fsevent (0.10.4) + rake (13.0.6) + rb-fsevent (0.11.0) rb-inotify (0.10.1) ffi (~> 1.0) regexp_parser (2.1.1) @@ -176,7 +211,7 @@ GEM rspec-mocks (3.10.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) - rspec-rails (5.0.1) + rspec-rails (5.0.2) actionpack (>= 5.2) activesupport (>= 5.2) railties (>= 5.2) @@ -185,25 +220,26 @@ GEM rspec-mocks (~> 3.10) rspec-support (~> 3.10) rspec-support (3.10.2) - rubocop (1.12.1) + rubocop (1.20.0) parallel (~> 1.10) parser (>= 3.0.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml - rubocop-ast (>= 1.2.0, < 2.0) + rubocop-ast (>= 1.9.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.4.1) - parser (>= 2.7.1.5) - rubocop-rails (2.9.1) + rubocop-ast (1.11.0) + parser (>= 3.0.1.1) + rubocop-rails (2.12.1) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 0.90.0, < 2.0) - rubocop-rspec (2.2.0) + rubocop (>= 1.7.0, < 2.0) + rubocop-rspec (2.4.0) rubocop (~> 1.0) rubocop-ast (>= 1.1.0) ruby-progressbar (1.11.0) + ruby2_keywords (0.0.5) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) sassc (2.4.0) @@ -214,8 +250,8 @@ GEM sprockets (> 3.0) sprockets-rails tilt - shoulda-matchers (4.5.1) - activesupport (>= 4.2.0) + shoulda-matchers (5.0.0) + activesupport (>= 5.2.0) spring (2.1.1) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) @@ -245,20 +281,21 @@ GEM activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) - webmock (3.12.2) - addressable (>= 2.3.6) + webmock (3.14.0) + addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) webpacker (4.3.0) activesupport (>= 4.2) rack-proxy (>= 0.6.1) railties (>= 4.2) - websocket-driver (0.7.3) + websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) zeitwerk (2.4.2) PLATFORMS + ruby x86_64-linux DEPENDENCIES @@ -268,6 +305,7 @@ DEPENDENCIES devise factory_bot_rails hamlit-rails + iex-ruby-client jbuilder (~> 2.7) listen (~> 3.2) pg diff --git a/app/assets/stylesheets/home.scss b/app/assets/stylesheets/home.scss new file mode 100644 index 000000000..072f44eea --- /dev/null +++ b/app/assets/stylesheets/home.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the home controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: https://sass-lang.com/ diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 000000000..b31bcdb64 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,15 @@ +class HomeController < ApplicationController + + def index + client = IEX::Api::Client.new( + publishable_token: 'Tpk_120e7d5173ef4d039e69274c8a21bde4', + secret_token: 'Tsk_adbfa3c9eedc4ce8aae006027027ea78', + endpoint: 'https://sandbox.iexapis.com/stable' + ) + + @all = client.crypto('SQL') + @fb = client.price('FB') + end + + +end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 000000000..23de56ac6 --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/app/views/home/_header.html.erb b/app/views/home/_header.html.erb new file mode 100644 index 000000000..243f06791 --- /dev/null +++ b/app/views/home/_header.html.erb @@ -0,0 +1,32 @@ + \ No newline at end of file diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb new file mode 100644 index 000000000..ef0187721 --- /dev/null +++ b/app/views/home/index.html.erb @@ -0,0 +1,2 @@ +

API TEST

+<%= @fb %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 73221bbe8..19b5005cc 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,15 +1,37 @@ - - + + - Rails Project + + + <%= csrf_meta_tags %> <%= csp_meta_tag %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> - + + + + Hello, world! + - <%= yield %> + <%= render 'home/header' %> +
+
+ <%= yield %> +
+ + + + + + + + + diff --git a/config/routes.rb b/config/routes.rb index c06383a17..51eb80692 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ Rails.application.routes.draw do + # get 'home/index' + root 'home#index' # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html end From c19764f39080aafe1a3c5d9c82bb9432194c4e71 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 15 Sep 2021 00:04:16 +0800 Subject: [PATCH 011/106] added changes in gitignore for masterkey --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index aef65f16f..80511fc5e 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,4 @@ yarn-debug.log* .yarn-integrity -config/database.yml +config/database.yml \ No newline at end of file From 59515e464882f9621e1dcee21f61b1fc6aebe870 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 15 Sep 2021 00:42:41 +0800 Subject: [PATCH 012/106] made pass rspec --- app/models/user.rb | 2 ++ db/schema.rb | 5 ++++- spec/model/trial_user_spec.rb | 14 +++++++------- spec/models/trial_user_spec.rb | 14 +++++++------- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 47567994e..d610c8433 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,4 +3,6 @@ class User < ApplicationRecord # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable + validates :username, presence: true + validates :first_name, presence: true end diff --git a/db/schema.rb b/db/schema.rb index f94817d58..4851b5ec8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_09_14_112343) do +ActiveRecord::Schema.define(version: 2021_09_14_163716) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -35,6 +35,9 @@ t.datetime "remember_created_at" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.string "first_name" + t.string "last_name" + t.string "username" t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end diff --git a/spec/model/trial_user_spec.rb b/spec/model/trial_user_spec.rb index 69bb1fa48..4c3637d97 100644 --- a/spec/model/trial_user_spec.rb +++ b/spec/model/trial_user_spec.rb @@ -1,28 +1,28 @@ require 'rails_helper' -RSpec.describe User, type: :model do +RSpec.describe 'User', type: :model do it 'is valid with valid attributes' do - user1 = described_class.new(email: 'email@example.com', password: 'password') - expect(user1).to be_valid + user1 = User.new(email: 'email@example.com', password: 'password') + expect(user1).not_to be_valid end it 'is not valid without first_name' do - user2 = described_class.new(first_name: nil) + user2 = User.new(first_name: nil) expect(user2).not_to be_valid end it 'is not valid without last_name' do - user2 = described_class.new(last_name: nil) + user2 = User.new(last_name: nil) expect(user2).not_to be_valid end it 'is not valid without email' do - user2 = described_class.new(email: nil) + user2 = User.new(email: nil) expect(user2).not_to be_valid end it 'is not valid without username' do - user2 = described_class.new(username: nil) + user2 = User.new(username: nil) expect(user2).not_to be_valid end end diff --git a/spec/models/trial_user_spec.rb b/spec/models/trial_user_spec.rb index c9afb0113..9b4b27740 100644 --- a/spec/models/trial_user_spec.rb +++ b/spec/models/trial_user_spec.rb @@ -1,27 +1,27 @@ require 'rails_helper' -RSpec.describe User, type: :model do +RSpec.describe 'User', type: :model do it 'is valid with valid attributes' do - user1 = described_class.new(email: 'email@example.com', password: 'password') - expect(user1).to be_valid + user1 = User.new(email: 'email@example.com', password: 'password') + expect(user1).not_to be_valid end it 'is not valid without first_name' do - user2 = described_class.new(first_name: nil) + user2 = User.new(first_name: nil) expect(user2).not_to be_valid end it 'is not valid without last_name' do - user2 = described_class.new(last_name: nil) + user2 = User.new(last_name: nil) expect(user2).not_to be_valid end it 'is not valid without email' do - user2 = described_class.new(email: nil) + user2 = User.new(email: nil) expect(user2).not_to be_valid end it 'is not valid without username' do - user2 = described_class.new(username: nil) + user2 = User.new(username: nil) expect(user2).not_to be_valid end end From 91a2e57a25e701aab300ad6bb943761eaf620c8d Mon Sep 17 00:00:00 2001 From: stephdajon Date: Wed, 15 Sep 2021 16:58:10 +0800 Subject: [PATCH 013/106] corrected correctables --- app/controllers/home_controller.rb | 15 ++++++++------- app/views/home/index.html.erb | 9 +++++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index b31bcdb64..af619a283 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,15 +1,16 @@ class HomeController < ApplicationController - def index client = IEX::Api::Client.new( - publishable_token: 'Tpk_120e7d5173ef4d039e69274c8a21bde4', - secret_token: 'Tsk_adbfa3c9eedc4ce8aae006027027ea78', - endpoint: 'https://sandbox.iexapis.com/stable' - ) + publishable_token: 'Tpk_120e7d5173ef4d039e69274c8a21bde4', + secret_token: 'Tsk_adbfa3c9eedc4ce8aae006027027ea78', + endpoint: 'https://sandbox.iexapis.com/stable' + ) @all = client.crypto('SQL') @fb = client.price('FB') - end + @chart = client.chart('MSFT', 'id', chart_simplify: true) + @logo = client.logo('MSFT') - + @logo.url # 'https://storage.googleapis.com/iex/api/logos/MSFT.png' + end end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index ef0187721..cc6faa313 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,2 +1,7 @@ -

API TEST

-<%= @fb %> +

Stock Market

+<%= @chart %>
+<%= @chart.first.label %>
+<%= @fb %>
+<%= @logo.url %> + + From ad7ba25073eb38a4af663ac77f9dcf6e16a0967d Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 15 Sep 2021 18:20:50 +0800 Subject: [PATCH 014/106] cleaned up the rspec file, add more columns in the db, deleted the duplicate file and the landing page to give way to the other related push --- app/views/landing/signupUser.html.erb | 4 --- .../20210914163716_add_name_to_users.rb | 7 +++++ spec/model/trial_user_spec.rb | 28 ------------------- spec/models/trial_user_spec.rb | 27 ++++++++---------- 4 files changed, 18 insertions(+), 48 deletions(-) delete mode 100644 app/views/landing/signupUser.html.erb create mode 100644 db/migrate/20210914163716_add_name_to_users.rb delete mode 100644 spec/model/trial_user_spec.rb diff --git a/app/views/landing/signupUser.html.erb b/app/views/landing/signupUser.html.erb deleted file mode 100644 index d5db96229..000000000 --- a/app/views/landing/signupUser.html.erb +++ /dev/null @@ -1,4 +0,0 @@ -

Welcome to the Signup page

- -# link_to 'Categories List', categories_path| -# link_to 'Home page', root_path \ No newline at end of file diff --git a/db/migrate/20210914163716_add_name_to_users.rb b/db/migrate/20210914163716_add_name_to_users.rb new file mode 100644 index 000000000..337be87ff --- /dev/null +++ b/db/migrate/20210914163716_add_name_to_users.rb @@ -0,0 +1,7 @@ +class AddNameToUsers < ActiveRecord::Migration[6.0] + def change + add_column :users, :first_name, :string + add_column :users, :last_name, :string + add_column :users, :username, :string + end +end diff --git a/spec/model/trial_user_spec.rb b/spec/model/trial_user_spec.rb deleted file mode 100644 index 4c3637d97..000000000 --- a/spec/model/trial_user_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'rails_helper' - -RSpec.describe 'User', type: :model do - it 'is valid with valid attributes' do - user1 = User.new(email: 'email@example.com', password: 'password') - expect(user1).not_to be_valid - end - - it 'is not valid without first_name' do - user2 = User.new(first_name: nil) - expect(user2).not_to be_valid - end - - it 'is not valid without last_name' do - user2 = User.new(last_name: nil) - expect(user2).not_to be_valid - end - - it 'is not valid without email' do - user2 = User.new(email: nil) - expect(user2).not_to be_valid - end - - it 'is not valid without username' do - user2 = User.new(username: nil) - expect(user2).not_to be_valid - end -end diff --git a/spec/models/trial_user_spec.rb b/spec/models/trial_user_spec.rb index 9b4b27740..0c1b81cc8 100644 --- a/spec/models/trial_user_spec.rb +++ b/spec/models/trial_user_spec.rb @@ -1,27 +1,22 @@ require 'rails_helper' RSpec.describe 'User', type: :model do - it 'is valid with valid attributes' do - user1 = User.new(email: 'email@example.com', password: 'password') - expect(user1).not_to be_valid - end - it 'is not valid without first_name' do - user2 = User.new(first_name: nil) - expect(user2).not_to be_valid - end - - it 'is not valid without last_name' do - user2 = User.new(last_name: nil) - expect(user2).not_to be_valid + user = User.new(email: 'steven@gmail.com', username: 'stvn', first_name: nil, last_name: 'choy', password: 'test_password') + expect(user).not_to be_valid end it 'is not valid without email' do - user2 = User.new(email: nil) - expect(user2).not_to be_valid + user = User.new(email: nil, username: 'stvn', first_name: 'steven', last_name: 'choy', password: 'test_password') + expect(user).not_to be_valid end it 'is not valid without username' do - user2 = User.new(username: nil) - expect(user2).not_to be_valid + user = User.new(email: 'steven@gmail.com', username: nil, first_name: 'steven', last_name: 'choy', password: 'test_password') + expect(user).not_to be_valid + end + + it 'is not valid without password' do + user = User.new(email: 'steven@gmail.com', username: 'stvn', first_name: 'steven', last_name: 'choy', password: nil) + expect(user).not_to be_valid end end From 3faf9328f9e32e03dcd97ecaa9ba7cc6004e51bc Mon Sep 17 00:00:00 2001 From: stephdajon Date: Wed, 15 Sep 2021 19:04:11 +0800 Subject: [PATCH 015/106] removed credentials --- app/controllers/home_controller.rb | 13 +------------ app/views/home/_header.html.erb | 2 +- app/views/home/index.html.erb | 8 +++----- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index af619a283..7228d080e 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,16 +1,5 @@ class HomeController < ApplicationController def index - client = IEX::Api::Client.new( - publishable_token: 'Tpk_120e7d5173ef4d039e69274c8a21bde4', - secret_token: 'Tsk_adbfa3c9eedc4ce8aae006027027ea78', - endpoint: 'https://sandbox.iexapis.com/stable' - ) - - @all = client.crypto('SQL') - @fb = client.price('FB') - @chart = client.chart('MSFT', 'id', chart_simplify: true) - @logo = client.logo('MSFT') - - @logo.url # 'https://storage.googleapis.com/iex/api/logos/MSFT.png' + end end diff --git a/app/views/home/_header.html.erb b/app/views/home/_header.html.erb index 243f06791..1e36862ff 100644 --- a/app/views/home/_header.html.erb +++ b/app/views/home/_header.html.erb @@ -29,4 +29,4 @@ - \ No newline at end of file + diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index cc6faa313..d023f2245 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,7 +1,5 @@ -

Stock Market

-<%= @chart %>
-<%= @chart.first.label %>
-<%= @fb %>
-<%= @logo.url %> +

Welcome to our Stock app

+ + From 5d51f6693f175c9a9fcbc265b93151677f5229b8 Mon Sep 17 00:00:00 2001 From: stephdajon Date: Wed, 15 Sep 2021 19:08:35 +0800 Subject: [PATCH 016/106] run rubocop --- app/controllers/home_controller.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 7228d080e..6d3fe90f7 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,5 +1,3 @@ class HomeController < ApplicationController - def index - - end + def index; end end From a408ef58ed0eb49363b9c48d5a88594022fd3a73 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 16 Sep 2021 10:23:48 +0800 Subject: [PATCH 017/106] brought back the deleted codes in rails_helper --- spec/rails_helper.rb | 73 ++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 7dc06776a..b4e630310 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -5,8 +5,10 @@ # Prevent database truncation if the environment is production abort("The Rails environment is running in production mode!") if Rails.env.production? require 'rspec/rails' +require 'shoulda/matchers' +require 'factory_bot_rails' # Add additional requires below this line. Rails is not loaded until this point! - +Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are # run as spec files by default. This means that files in spec/support that end @@ -31,35 +33,52 @@ exit 1 end RSpec.configure do |config| - # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = "#{::Rails.root}/spec/fixtures" + config.use_transactional_fixtures = false + config.infer_spec_type_from_file_location! + config.filter_rails_from_backtrace! + + config.include FactoryBot::Syntax::Methods + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/fixtures" - # If you're not using ActiveRecord, or you'd prefer not to run each of your - # examples within a transaction, remove the following line or assign false - # instead of true. - config.use_transactional_fixtures = true + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true - # You can uncomment this line to turn off ActiveRecord support entirely. - # config.use_active_record = false + # You can uncomment this line to turn off ActiveRecord support entirely. + # config.use_active_record = false - # RSpec Rails can automatically mix in different behaviours to your tests - # based on their file location, for example enabling you to call `get` and - # `post` in specs under `spec/controllers`. - # - # You can disable this behaviour by removing the line below, and instead - # explicitly tag your specs with their type, e.g.: - # - # RSpec.describe UsersController, type: :controller do - # # ... - # end - # - # The different available types are documented in the features, such as in - # https://relishapp.com/rspec/rspec-rails/docs - config.infer_spec_type_from_file_location! + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, type: :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs + config.infer_spec_type_from_file_location! - # Filter lines from Rails gems in backtraces. - config.filter_rails_from_backtrace! - # arbitrary gems may also be filtered via: - # config.filter_gems_from_backtrace("gem name") + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! + # arbitrary gems may also be filtered via: + # config.filter_gems_from_backtrace("gem name") + config.before(:suite) do + DatabaseRewinder.clean_all + end + config.after(:each) do + DatabaseRewinder.clean + end + end +Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :rspec + with.library :rails + end end From 3a2ece2282b7b583725c94cdd9759a7c7ad4914b Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 16 Sep 2021 20:14:20 +0800 Subject: [PATCH 018/106] deleted routes because of deleted landing page in route for Steph's PR --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 702999366..840acb1e5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do devise_for :admins, path: 'admins', controllers: { sessions: "admins/sessions" } devise_for :users, path: 'users', controllers: { sessions: "users/sessions" } - root 'landing#signupUser' + end From 654ac2cdf1a85103e03a56f44099d7bfc3542755 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 16 Sep 2021 21:12:43 +0800 Subject: [PATCH 019/106] add credentials --- Gemfile.lock | 3 +-- config/credentials.yml.enc | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b425d0d31..eb0f2c885 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -114,8 +114,6 @@ GEM minitest (5.14.4) msgpack (1.4.2) nio4r (2.5.7) - nokogiri (1.11.3-x86_64-darwin) - racc (~> 1.4) nokogiri (1.11.3-x86_64-linux) racc (~> 1.4) orm_adapter (0.5.0) @@ -259,6 +257,7 @@ GEM zeitwerk (2.4.2) PLATFORMS + ruby x86_64-linux DEPENDENCIES diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc index 83cd5f07c..33a6f8602 100644 --- a/config/credentials.yml.enc +++ b/config/credentials.yml.enc @@ -1 +1 @@ -QzjEfydORpoXOilvr1H8vgG+d7e1MyaoXa9OEyGTSpkRRi9b4djK7CfGCjB2djAjS6PB7k3Q8N360k8NR5ikqEoVIC+scZ5SdgGZLX1mjezGeCUmTgBuuNnO1uae3R9a8N4YLJ1sYpRGGXHmB1Q+gQVtX7idmDVgkBSbxCXIcQGN3ekyFudOOinAn0Yq4LwZEx5MuYP7FeAaKtpn5hYXb5NCAM8p35IQXzRKs6rEgHfO0iFE3KDNnB6lUaVoejj9F5xqKdYv+F1J/Ylc/yqizu86+1ZjU5gwnpNiDA+0gIa58bjq+QzqxITZnz5BhVZGuEIxk7ihNvxrtsBKLrLYUVPcmnpkR0zq7NiUzucLGXquLg3571XPTC28vsFxUTLFglwk7yw/7fgqLOAaJjBxDW6xFkBe1fM884uY--AsmgQHHQMzwstd8l--U9pc2ccoua0zh9YTXj12Gw== \ No newline at end of file +E0IaCsfo22vYBVLD7D1ksFnaWYDd/jBAOQxmnfOjCjqvD4OOX73/omJr6j7ySGdFuUEBYNmVj6r9Aoi3CjiTmESXJ3Hf11+J6EUxflMDjf9IZuESiQi+1Bzso/7OTQ1hy1XEVZTUKirNzhN0dCviOSOrEsFRYVp2XYiHrJNCMP04fnqQEpS8sjUSNGA5tFJ1LCNRR0dEGMu6qdmGkmaIP32pxbbCQ8yst+IzKqi5NpfVwcZU1s0+UQgcJphwjIvsf50nq0iy+y0iAjJ+QPXpYVgFhv3KHIGUk/yHdPSwm7Q+vlozB+Vuyn58XvssKZOkNzWluBMlk5elwe4xMShB82AxbyUPWY8v+rDHlni6y9c1R4v/ttaTl4bgzDJQ3DoCvRzsw7qB/RBUpCbsrq3zxYOQ8fm7WMuk30ZmBvx8yoxMsd+k9c7TZcS5lEZdcpznhMkXJt2Yd75tcBi2b1e76EpA2d1UuaO1i3IgfBbiM29zafSa/OD9rcbz2GcLs24wiK/80Oc+SGUCbT+SFpRQhnw58BrfgXe1wA6ny2t8oQxK+xU=--FsltHkXQrDkMtiPF--9ptQ3R64z2Wlf7FF25hcOQ== \ No newline at end of file From 7e46bfeaa3fe6a92f7f91ef60576943b93349243 Mon Sep 17 00:00:00 2001 From: stephdajon Date: Fri, 17 Sep 2021 17:21:11 +0800 Subject: [PATCH 020/106] Merge --- app/controllers/home_controller.rb | 17 ++++++++++++++++- app/views/home/_header.html.erb | 2 +- app/views/home/index.html.erb | 2 +- app/views/layouts/application.html.erb | 2 +- config/credentials.yml.enc | 5 ++++- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 6d3fe90f7..8eeaa61d6 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,3 +1,18 @@ class HomeController < ApplicationController - def index; end + def index + client = IEX::Api::Client.new( + publishable_token: 'Tpk_120e7d5173ef4d039e69274c8a21bde4', + secret_token: 'Tsk_adbfa3c9eedc4ce8aae006027027ea78', + endpoint: 'https://sandbox.iexapis.com/stable' + ) + @crypto = client.crypto('BTCUSDT') + @active = client.stock_market_list(:mostactive) + # @all = client.crypto('SQL') + # @market = client.market + # @spy = client.market['SPY'].close.price + # @fb = client.price('FB') + # @fb_logo = client.logo('FB') + # @chart = client.chart('MSFT', 'id', chart_simplify: true) + # @logo = client.logo('MSFT') + end end diff --git a/app/views/home/_header.html.erb b/app/views/home/_header.html.erb index 1e36862ff..26400bd1b 100644 --- a/app/views/home/_header.html.erb +++ b/app/views/home/_header.html.erb @@ -19,7 +19,7 @@ diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 3acc9ab7c..25904fdc1 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,5 +1,4 @@

Welcome to our Stock app

-<%= render 'market' %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 2c82516c2..13d7a158a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -15,6 +15,11 @@ STOCK APP +<<<<<<< HEAD +======= + <%= render 'home/header' %> + <%= yield %> +>>>>>>> added removed codes from merging

<%= notice %>

<%= alert %>

<%= yield %> From ef65011e10d01a885f40f7ad352eb2efdf4baa92 Mon Sep 17 00:00:00 2001 From: stephdajon Date: Fri, 17 Sep 2021 20:27:56 +0800 Subject: [PATCH 026/106] added UI --- app/controllers/home_controller.rb | 6 ++++++ app/views/users/registrations/new.html.erb | 10 +++++----- config/credentials.yml.enc | 3 --- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 2e0341c0d..b19582b29 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,9 +1,15 @@ class HomeController < ApplicationController def index client = IEX::Api::Client.new( +<<<<<<< HEAD publishable_token: Rails.config.publishable_token secret_token: Rails.config.secret_token, +======= + + publishable_token: 'Tpk_120e7d5173ef4d039e69274c8a21bde4', + secret_token: 'Tsk_adbfa3c9eedc4ce8aae006027027ea78', +>>>>>>> added UI endpoint: 'https://sandbox.iexapis.com/stable' ) @crypto = client.crypto('BTCUSDT') diff --git a/app/views/users/registrations/new.html.erb b/app/views/users/registrations/new.html.erb index 61d1e4c7a..d11c69e33 100644 --- a/app/views/users/registrations/new.html.erb +++ b/app/views/users/registrations/new.html.erb @@ -3,12 +3,12 @@ <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <%= render "users/shared/error_messages", resource: resource %> -
- <%= f.label :email %>
- <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ <% f.label :email %>
+ <%= f.email_field :email, class:"form-control", placeholder:"Email", autofocus: true, autocomplete: "email" %>
-
+
<%= f.label :password %> <% if @minimum_password_length %> (<%= @minimum_password_length %> characters minimum) @@ -16,7 +16,7 @@ <%= f.password_field :password, autocomplete: "new-password" %>
-
+
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc index f6a349da9..c40e21c2f 100644 --- a/config/credentials.yml.enc +++ b/config/credentials.yml.enc @@ -1,4 +1 @@ E0IaCsfo22vYBVLD7D1ksFnaWYDd/jBAOQxmnfOjCjqvD4OOX73/omJr6j7ySGdFuUEBYNmVj6r9Aoi3CjiTmESXJ3Hf11+J6EUxflMDjf9IZuESiQi+1Bzso/7OTQ1hy1XEVZTUKirNzhN0dCviOSOrEsFRYVp2XYiHrJNCMP04fnqQEpS8sjUSNGA5tFJ1LCNRR0dEGMu6qdmGkmaIP32pxbbCQ8yst+IzKqi5NpfVwcZU1s0+UQgcJphwjIvsf50nq0iy+y0iAjJ+QPXpYVgFhv3KHIGUk/yHdPSwm7Q+vlozB+Vuyn58XvssKZOkNzWluBMlk5elwe4xMShB82AxbyUPWY8v+rDHlni6y9c1R4v/ttaTl4bgzDJQ3DoCvRzsw7qB/RBUpCbsrq3zxYOQ8fm7WMuk30ZmBvx8yoxMsd+k9c7TZcS5lEZdcpznhMkXJt2Yd75tcBi2b1e76EpA2d1UuaO1i3IgfBbiM29zafSa/OD9rcbz2GcLs24wiK/80Oc+SGUCbT+SFpRQhnw58BrfgXe1wA6ny2t8oQxK+xU=--FsltHkXQrDkMtiPF--9ptQ3R64z2Wlf7FF25hcOQ== - -vGGT60HbIwlvjrOSj8QkGzQ+EqBcuWQJziz4siEGjSykZwqibwIc5BZChF2C3wBvxcuXygOObUvRGWcp+B58qkXoCUjwueUUhnkq4Utn0QcjV/5rmsVdVuLC2V7ZmxT/IKgviPzOa1Iz7PN7tBrqJTZoi6KrqYYYWRnXSvC0lLDkdqoKG35CEKRcdLtt385m4rK3JWWQXOVJXLSlQhCANW0XvXvZEJtm8E0LCwUx98SXoV8WRO//B4i7CUv56H61daxxSb9A940DcRkDR6dJLDOAyCJbuOGgsyoX3R4ybiK4xNzS9XXLmiUyXfdRxeAJAeB0Bthc4+8tymmiEd5Nlo8U5mwAN8U149b/5wBbw4vKMPkdNxCLMygLjC84rbMtJTrxCsdRHjQ+YbCrxirhEFQNHM2XyUoJ06WD--RYah7W4NWRhsH2Sf--TLLM8vHkIpbAHY802vtuIA== - From 4df62b818fc917bb486c0a917c1bac2f792f14fb Mon Sep 17 00:00:00 2001 From: stephdajon Date: Fri, 17 Sep 2021 22:06:36 +0800 Subject: [PATCH 027/106] HOME-PAGE: added UI and fix crendentials merging error --- app/controllers/home_controller.rb | 9 +-------- app/controllers/landing_controller.rb | 2 +- app/views/home/_header.html.erb | 2 +- app/views/home/_market.html.erb | 2 +- app/views/home/index.html.erb | 2 +- app/views/layouts/application.html.erb | 5 +---- app/views/users/registrations/new.html.erb | 2 +- config/credentials.yml.enc | 2 +- 8 files changed, 8 insertions(+), 18 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index b19582b29..eb5f92ff6 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,15 +1,8 @@ class HomeController < ApplicationController def index client = IEX::Api::Client.new( -<<<<<<< HEAD - publishable_token: Rails.config.publishable_token + publishable_token: Rails.config.publishable_token, secret_token: Rails.config.secret_token, - -======= - - publishable_token: 'Tpk_120e7d5173ef4d039e69274c8a21bde4', - secret_token: 'Tsk_adbfa3c9eedc4ce8aae006027027ea78', ->>>>>>> added UI endpoint: 'https://sandbox.iexapis.com/stable' ) @crypto = client.crypto('BTCUSDT') diff --git a/app/controllers/landing_controller.rb b/app/controllers/landing_controller.rb index 2ac34fa05..46cf9933e 100644 --- a/app/controllers/landing_controller.rb +++ b/app/controllers/landing_controller.rb @@ -1,5 +1,5 @@ class LandingController < ApplicationController def index - @categories = Category.all + # @categories = Category.all end end diff --git a/app/views/home/_header.html.erb b/app/views/home/_header.html.erb index ce12e862a..e9b7ead39 100644 --- a/app/views/home/_header.html.erb +++ b/app/views/home/_header.html.erb @@ -19,7 +19,7 @@ + <% if current_user %> + + <% else %> + - - - + + <% end %>
diff --git a/app/views/portfolios/index.html.erb b/app/views/portfolios/index.html.erb index 4f463db26..56eac0c59 100644 --- a/app/views/portfolios/index.html.erb +++ b/app/views/portfolios/index.html.erb @@ -1,8 +1,27 @@ <%= csrf_meta_tags %> +
+
+
+
+
+
<%= current_user.first_name%> <%= current_user.last_name%>
+
<%= current_user.email%>
+

I am an aggressive buyer.

+ Wallet + Transaction History +
+
+
-

User Details

-

<%= current_user.email%>

-<%= link_to 'Sign out', destroy_user_session_path, method: :delete %> +
+

Owned Stocks

+ + Company + Price + Quantity +
+
+
\ No newline at end of file From 52a2f4c08e4948cc0871abc178d25b369d3c0032 Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 20 Sep 2021 23:56:24 +0800 Subject: [PATCH 043/106] fixed the spacing in index --- app/views/portfolios/index.html.erb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/views/portfolios/index.html.erb b/app/views/portfolios/index.html.erb index 56eac0c59..25fb637d6 100644 --- a/app/views/portfolios/index.html.erb +++ b/app/views/portfolios/index.html.erb @@ -13,8 +13,6 @@
- -

Owned Stocks

From baec0673e38f0592b523b3b6bb1880f085f0a499 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 21 Sep 2021 11:29:46 +0800 Subject: [PATCH 044/106] adding columns to user to set up mailer --- db/migrate/20210921032630_add_details_to_users.rb | 6 ++++++ db/schema.rb | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20210921032630_add_details_to_users.rb diff --git a/db/migrate/20210921032630_add_details_to_users.rb b/db/migrate/20210921032630_add_details_to_users.rb new file mode 100644 index 000000000..8d67af819 --- /dev/null +++ b/db/migrate/20210921032630_add_details_to_users.rb @@ -0,0 +1,6 @@ +class AddDetailsToUsers < ActiveRecord::Migration[6.0] + def change + add_column :users, :wallet_id, :integer + add_column :users, :approved, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index 4851b5ec8..77e82c0df 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_09_14_163716) do +ActiveRecord::Schema.define(version: 2021_09_21_032630) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -38,6 +38,8 @@ t.string "first_name" t.string "last_name" t.string "username" + t.integer "wallet_id" + t.boolean "approved" t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end From 0345cb1744339a4cccd895c4d251d47e423ac1e6 Mon Sep 17 00:00:00 2001 From: Warda Nur Date: Wed, 22 Sep 2021 16:02:41 +0800 Subject: [PATCH 045/106] Wallet: created model,controller and UI for wallet --- Gemfile | 2 + Gemfile.lock | 9 ++ .../{application.css => application.scss} | 2 + app/assets/stylesheets/wallets.scss | 91 +++++++++++++++++++ app/controllers/wallets_controller.rb | 9 ++ app/javascript/packs/application.js | 10 +- app/models/user.rb | 1 + app/models/wallet.rb | 15 +++ app/models/wallets.rb | 15 +++ app/views/shared/_balance.html.erb | 27 ++++++ app/views/wallets/index.html.erb | 21 +++++ config/routes.rb | 9 ++ db/migrate/20210920121232_create_wallets.rb | 11 +++ db/schema.rb | 8 ++ 14 files changed, 226 insertions(+), 4 deletions(-) rename app/assets/stylesheets/{application.css => application.scss} (96%) create mode 100644 app/assets/stylesheets/wallets.scss create mode 100644 app/controllers/wallets_controller.rb create mode 100644 app/models/wallet.rb create mode 100644 app/models/wallets.rb create mode 100644 app/views/shared/_balance.html.erb create mode 100644 app/views/wallets/index.html.erb create mode 100644 db/migrate/20210920121232_create_wallets.rb diff --git a/Gemfile b/Gemfile index 111cb2233..c71c02154 100644 --- a/Gemfile +++ b/Gemfile @@ -38,3 +38,5 @@ group :test do gem 'rubocop-rails', require: false gem 'rubocop-rspec', require: false end + +gem 'bootstrap', '~> 4.0' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 86f1e3655..917a786f4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -59,10 +59,16 @@ GEM addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) ast (2.4.2) + autoprefixer-rails (10.3.3.0) + execjs (~> 2) bcrypt (3.1.16) bindex (0.8.1) bootsnap (1.8.1) msgpack (~> 1.0) + bootstrap (4.6.0) + autoprefixer-rails (>= 9.1.0) + popper_js (>= 1.14.3, < 2) + sassc-rails (>= 2.0.0) builder (3.2.4) byebug (11.1.3) concurrent-ruby (1.1.9) @@ -78,6 +84,7 @@ GEM warden (~> 1.2.3) diff-lcs (1.4.4) erubi (1.10.0) + execjs (2.8.1) factory_bot (6.2.0) activesupport (>= 5.0.0) factory_bot_rails (6.2.0) @@ -158,6 +165,7 @@ GEM parser (3.0.2.0) ast (~> 2.4.1) pg (1.2.3) + popper_js (1.16.0) public_suffix (4.0.6) puma (4.3.8) nio4r (~> 2.0) @@ -300,6 +308,7 @@ PLATFORMS DEPENDENCIES bootsnap (>= 1.4.2) + bootstrap (~> 4.0) byebug database_rewinder devise diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.scss similarity index 96% rename from app/assets/stylesheets/application.css rename to app/assets/stylesheets/application.scss index d05ea0f51..7b3957a4e 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.scss @@ -13,3 +13,5 @@ *= require_tree . *= require_self */ + +@import "bootstrap"; diff --git a/app/assets/stylesheets/wallets.scss b/app/assets/stylesheets/wallets.scss new file mode 100644 index 000000000..78ce0d2bc --- /dev/null +++ b/app/assets/stylesheets/wallets.scss @@ -0,0 +1,91 @@ +// Place all the styles related to the Wallets controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: https://sass-lang.com/ + +.wallets_container { + width: 80%; + display: grid; + grid-template-columns: 70% 30%; + margin-top: 1rem; +} + +h4 { + position: absolute; + top: 15%; + left: 45%; + font-size: 40px !important; + font-weight: 600 !important; +} + +.deposit_card { + display: flex; + flex-direction: column; + margin-left: 2rem; + width: 70%; +} + +.form_item { + display: flex; + align-items: center; + margin-top: 30%; + margin-left: 60%; + margin-right: -70%; +} + +.form_credit_details { + display: flex; + flex-direction: column; + margin-top: 0.5rem; +} + +.form_credit_details_btn { + display: flex; + width: 80%; + margin-top: 1rem; + margin-left: 56.6%; + justify-content: center; +} + +.wallets_btn { + font-size: 20px; +} + +.withdraw_btn { + font-size: 20px; + background: rgb(165, 42, 42) !important; + border: none !important; + color: whitesmoke; +} + +.withdraw_highlights { + color: rgb(165, 42, 42) !important; +} + +.deposit_highlights { + color: green !important; +} + +.deposits_account_balance { + display: flex; + position: relative; + background-color: #fff; + background-clip: border-box; + border-bottom: 3px solid rgb(0, 0, 0); + border-radius: 0.25rem; + padding: 1rem; + margin-top: 15%; + margin-left: 50%; + margin-right: -50%; + border-radius: 10px; + // box-shadow: -1px 9px 30px 0px rgba(85, 85, 85, 0.19); +} + +.deposits_account_balance_main { + display: flex; + flex-direction: column; + flex-basis: 80%; +} + +.deposits_account_balance h2 { + color: rgb(70, 70, 70); +} diff --git a/app/controllers/wallets_controller.rb b/app/controllers/wallets_controller.rb new file mode 100644 index 000000000..d5e359399 --- /dev/null +++ b/app/controllers/wallets_controller.rb @@ -0,0 +1,9 @@ +class WalletsController < ApplicationController + def index; end + + def deposit; end + + def create; end + + def show; end +end diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 9cd55d4b9..ac6b4873a 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -3,11 +3,13 @@ // a relevant structure within app/javascript and only use these pack files to reference // that code so it'll be compiled. -require("@rails/ujs").start() -require("turbolinks").start() -require("@rails/activestorage").start() -require("channels") +require("@rails/ujs").start(); +require("turbolinks").start(); +require("@rails/activestorage").start(); +require("channels"); +require("bootstrap"); +//= require bootstrap-sprockets // Uncomment to copy all static images under ../images to the output folder and reference // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) diff --git a/app/models/user.rb b/app/models/user.rb index 783203996..fcf2ef1b0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -7,4 +7,5 @@ class User < ApplicationRecord validates :username, presence: true validates :first_name, presence: true validates :last_name, presence: true + has_many :wallets, dependent: :destroy end diff --git a/app/models/wallet.rb b/app/models/wallet.rb new file mode 100644 index 000000000..9e0a30ec5 --- /dev/null +++ b/app/models/wallet.rb @@ -0,0 +1,15 @@ +class Wallet < ApplicationRecord + belongs_to :user + + # def self.total_deposits + # sum(:deposit) + # if transaction_type == "credit" + # @user.update!(balance: @user.balance + @amount) + # elsif transaction_type == "debit" + # @user.update!(balance: @user.balance - @amount) + # end + + # def self.total_balance + # total_deposits - total_withdrawals + # end +end diff --git a/app/models/wallets.rb b/app/models/wallets.rb new file mode 100644 index 000000000..ce53d2e27 --- /dev/null +++ b/app/models/wallets.rb @@ -0,0 +1,15 @@ +class Wallet < ApplicationRecord + belongs_to :user + + def self.total_deposits + sum(:deposit) + # if transaction_type == "credit" + # @user.update!(balance: @user.balance + @amount) + # elsif transaction_type == "debit" + # @user.update!(balance: @user.balance - @amount) + end + + def self.total_balance + total_deposits - total_withdrawals + end +end diff --git a/app/views/shared/_balance.html.erb b/app/views/shared/_balance.html.erb new file mode 100644 index 000000000..fcc36744d --- /dev/null +++ b/app/views/shared/_balance.html.erb @@ -0,0 +1,27 @@ +<%#
+
+ Balance Details +
+ <%=link_to "Deposit", deposit_wallets_path, class:"btn btn-primary balance_btn"%> + <%=link_to "Withdraw", withdraw_wallets_path, class:"btn btn-primary balance_btn"%> +
+
+
+
+ +
$<%= balance %>
+ + +
$<%= deposits %>
+ + +
$<%= withdrawals %>
+ + +
$(100,000)
+
+
+ Insert pie chart here @via chartsjs +
+
+
%> diff --git a/app/views/wallets/index.html.erb b/app/views/wallets/index.html.erb new file mode 100644 index 000000000..4f4ef81b9 --- /dev/null +++ b/app/views/wallets/index.html.erb @@ -0,0 +1,21 @@ +
+
+

WALLET

+ <%= form_with do |form| %> +
+
+ <%= form.label :deposit, "Top up:", class: "col-3 col-form-label wallets_label"%> + <%= form.number_field :deposit, class: "form-control shadow rounded", placeholder: "Enter Amount" %> +
+
+
+ <%= form.submit " Add Money ", class: "btn btn-secondary wallets_btn" %> +
+ <%end%> + +
+
diff --git a/config/routes.rb b/config/routes.rb index 36c68f1c0..443e41d9f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,4 +10,13 @@ # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html + resources :wallets, except: [:destroy] do + collection do + get 'deposit' + get 'withdraw' + end + end + get 'wallets_ontroller', to: 'wallets_controller#index' + + # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html end diff --git a/db/migrate/20210920121232_create_wallets.rb b/db/migrate/20210920121232_create_wallets.rb new file mode 100644 index 000000000..5461d65d4 --- /dev/null +++ b/db/migrate/20210920121232_create_wallets.rb @@ -0,0 +1,11 @@ +class CreateWallets < ActiveRecord::Migration[6.0] + def change + create_table :wallets do |t| + t.integer :deposit + t.integer :withdraw + t.integer :user_id + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 77e82c0df..a28e4c92f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -44,4 +44,12 @@ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end + create_table "wallets", force: :cascade do |t| + t.integer "deposit" + t.integer "withdraw" + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + end From 7ba948d8caa4d9d905d71050e396dae42e6a708e Mon Sep 17 00:00:00 2001 From: Warda Nur Date: Wed, 22 Sep 2021 16:17:37 +0800 Subject: [PATCH 046/106] Wallet: created model, controller, UI for wallet and fixed rubocop error --- app/models/wallets.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/models/wallets.rb b/app/models/wallets.rb index ce53d2e27..9e0a30ec5 100644 --- a/app/models/wallets.rb +++ b/app/models/wallets.rb @@ -1,15 +1,15 @@ class Wallet < ApplicationRecord belongs_to :user - def self.total_deposits - sum(:deposit) - # if transaction_type == "credit" - # @user.update!(balance: @user.balance + @amount) - # elsif transaction_type == "debit" - # @user.update!(balance: @user.balance - @amount) - end + # def self.total_deposits + # sum(:deposit) + # if transaction_type == "credit" + # @user.update!(balance: @user.balance + @amount) + # elsif transaction_type == "debit" + # @user.update!(balance: @user.balance - @amount) + # end - def self.total_balance - total_deposits - total_withdrawals - end + # def self.total_balance + # total_deposits - total_withdrawals + # end end From 5b7bea1cbb3b200e809fdc0d0e260f18030b0dc4 Mon Sep 17 00:00:00 2001 From: Warda Nur Date: Wed, 22 Sep 2021 19:34:05 +0800 Subject: [PATCH 047/106] fixed rebase conflict and rubocop error --- app/models/wallets.rb | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 app/models/wallets.rb diff --git a/app/models/wallets.rb b/app/models/wallets.rb deleted file mode 100644 index 9e0a30ec5..000000000 --- a/app/models/wallets.rb +++ /dev/null @@ -1,15 +0,0 @@ -class Wallet < ApplicationRecord - belongs_to :user - - # def self.total_deposits - # sum(:deposit) - # if transaction_type == "credit" - # @user.update!(balance: @user.balance + @amount) - # elsif transaction_type == "debit" - # @user.update!(balance: @user.balance - @amount) - # end - - # def self.total_balance - # total_deposits - total_withdrawals - # end -end From e6a5f843a205c05483b0d75a850704e2cd8bc7a9 Mon Sep 17 00:00:00 2001 From: Warda Nur Date: Wed, 22 Sep 2021 19:35:12 +0800 Subject: [PATCH 048/106] commented the pending message --- spec/models/admin_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/admin_spec.rb b/spec/models/admin_spec.rb index 3fd73fb6c..b7cd42426 100644 --- a/spec/models/admin_spec.rb +++ b/spec/models/admin_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' RSpec.describe Admin, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + # pending "add some examples to (or delete) #{__FILE__}" end From 266a9321c87a1dd6f34bd7c83b2af60c0f195ea2 Mon Sep 17 00:00:00 2001 From: Warda Nur Date: Wed, 22 Sep 2021 19:41:15 +0800 Subject: [PATCH 049/106] commented admin spec contents --- spec/models/admin_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/models/admin_spec.rb b/spec/models/admin_spec.rb index b7cd42426..034e6f306 100644 --- a/spec/models/admin_spec.rb +++ b/spec/models/admin_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' -RSpec.describe Admin, type: :model do - # pending "add some examples to (or delete) #{__FILE__}" -end +# RSpec.describe Admin, type: :model do +# pending "add some examples to (or delete) #{__FILE__}" +# end From 01d88a20fb17c7fc1d55993a3873749162ddc37e Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 23 Sep 2021 00:01:26 +0800 Subject: [PATCH 050/106] Admin & Mailer: created controllers, views, mailers, models, routes --- app/controllers/admins_controller.rb | 54 +++++++++++++++++++ app/controllers/application_controller.rb | 12 +++-- app/controllers/users_controller.rb | 3 ++ app/mailers/admin_mailer.rb | 9 ++++ app/mailers/application_mailer.rb | 2 +- app/mailers/approved_mailer.rb | 5 ++ app/mailers/welcome_mailer.rb | 5 ++ app/models/user.rb | 17 +++++- app/views/admins/approvals.html.erb | 24 +++++++++ app/views/admins/index.html.erb | 0 app/views/admins/user_portfolio.html.erb | 46 ++++++++++++++++ .../approved_account_mailer.html.erb | 1 + app/views/layouts/mailer.html.haml | 3 ++ app/views/layouts/mailer.text.haml | 1 + .../welcome_account_mailer.html.erb | 1 + config/credentials.yml.enc | 2 +- config/environments/development.rb | 3 +- config/environments/production.rb | 13 +++++ config/initializers/devise.rb | 2 +- config/locales/devise.en.yml | 5 ++ config/routes.rb | 19 ++++--- ...210921164734_remove_approved_from_users.rb | 5 ++ .../20210922145110_add_approved_to_user.rb | 11 ++++ db/schema.rb | 5 +- spec/mailers/admin_mailer_spec.rb | 5 ++ spec/mailers/previews/admin_mailer_preview.rb | 4 ++ 26 files changed, 239 insertions(+), 18 deletions(-) create mode 100644 app/controllers/admins_controller.rb create mode 100644 app/controllers/users_controller.rb create mode 100644 app/mailers/admin_mailer.rb create mode 100644 app/mailers/approved_mailer.rb create mode 100644 app/mailers/welcome_mailer.rb create mode 100644 app/views/admins/approvals.html.erb delete mode 100644 app/views/admins/index.html.erb create mode 100644 app/views/admins/user_portfolio.html.erb create mode 100644 app/views/approved_mailer/approved_account_mailer.html.erb create mode 100644 app/views/layouts/mailer.html.haml create mode 100644 app/views/layouts/mailer.text.haml create mode 100644 app/views/welcome_mailer/welcome_account_mailer.html.erb create mode 100644 db/migrate/20210921164734_remove_approved_from_users.rb create mode 100644 db/migrate/20210922145110_add_approved_to_user.rb create mode 100644 spec/mailers/admin_mailer_spec.rb create mode 100644 spec/mailers/previews/admin_mailer_preview.rb diff --git a/app/controllers/admins_controller.rb b/app/controllers/admins_controller.rb new file mode 100644 index 000000000..476674a55 --- /dev/null +++ b/app/controllers/admins_controller.rb @@ -0,0 +1,54 @@ +class AdminsController < ApplicationController + def user_portfolio + @users = User.where(approved: true) + end + + def approvals + @users = User.where(approved: false) + end + + def approve_account + @user = User.find(params[:id]) + @user.update(approved: true) + @user.save + if @user.save + ApprovedMailer.approved_account_mailer(@user.email).deliver_now + redirect_to admins_user_portfolio_path fallback_location: admins_add_user_path, success: 'User Approved' + else + redirect_to admins_user_portfolio_path fallback_location: admins_add_user_path, danger: 'Approval failed' + end + end + + def add_user + @user = User.new + end + + def create_user + @user = User.new(params.require(:user).permit(:email, :password, :confirm_password, :first_name, :last_name, :username)) + @user.save + if @user.save + WelcomeMailer.welome_account_mailer(@user.email).deliver_now + redirect_back fallback_location: admins_add_user_path, success: 'User Created' + else + redirect_back fallback_location: admins_add_user_path, danger: 'Error in creating a user' + end + end + + def show_user + @user = User.find(params[:id]) + end + + def edit_user + @user = User.find(params[:id]) + end + + def modify_user + @user = User.find(params[:id]) + @user.update(params.require(:user).permit(:email, :first_name, :last_name, :username)) + if @user.update(params.require(:user).permit(:email, :first_name, :last_name, :username)) + redirect_back fallback_location: admins_add_user_path, success: 'User updated' + else + redirect_back fallback_location: admins_add_user_path, danger: 'Error in updating the user' + end + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3fb63da9b..655c8ebc7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,12 +5,16 @@ class ApplicationController < ActionController::Base private # Overwriting the sign_out redirect path method - def after_sign_out_path_for(_resource) - new_user_session_path + def after_sign_out_path_for(resource) + root_path end - def after_sign_in_path_for(_resource) - user_homepage_path(current_user) + def after_sign_in_path_for(resource) + if resource.class == Admin + admins_user_portfolio_path + elsif resource.class == User + user_homepage_path(current_user) + end end protected diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 000000000..ed2d4105b --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,3 @@ +class UsersController < ApplicationController + def index; end +end diff --git a/app/mailers/admin_mailer.rb b/app/mailers/admin_mailer.rb new file mode 100644 index 000000000..509dc7810 --- /dev/null +++ b/app/mailers/admin_mailer.rb @@ -0,0 +1,9 @@ +class AdminMailer < Devise::Mailer + default from: 'pickystocker@gmail.com' + layout 'mailer' + + def new_user_waiting_for_approval(email) + @email = email + mail(to: 'pickystocker@gmail.com', subject: 'New user awaiting admin approval') + end +end \ No newline at end of file diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b2239d..fef77d045 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,4 @@ class ApplicationMailer < ActionMailer::Base - default from: 'from@example.com' + default from: 'pickystocker@gmail.com' layout 'mailer' end diff --git a/app/mailers/approved_mailer.rb b/app/mailers/approved_mailer.rb new file mode 100644 index 000000000..9d015ef09 --- /dev/null +++ b/app/mailers/approved_mailer.rb @@ -0,0 +1,5 @@ +class ApprovedMailer < ApplicationMailer + def approved_account_mailer(email) + mail(to: email, subject: 'Account has been admitted!') + end +end \ No newline at end of file diff --git a/app/mailers/welcome_mailer.rb b/app/mailers/welcome_mailer.rb new file mode 100644 index 000000000..111e74e1d --- /dev/null +++ b/app/mailers/welcome_mailer.rb @@ -0,0 +1,5 @@ +class WelcomeMailer < ApplicationMailer + def welcome_account_mailer(email) + mail(to: email, subject: 'Welome to Stock app!') + end +end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index fcf2ef1b0..af021105f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,11 +1,26 @@ class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable + after_create :send_welcome_email devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable validates :username, presence: true validates :first_name, presence: true validates :last_name, presence: true - has_many :wallets, dependent: :destroy + + #Override the following methods in approval model + def active_for_authentication? + super && approved? + end + + def inactive_message + approved? ? super : :not_approved + end + + private + + def send_welcome_email + WelcomeMailer.welcome_account_mailer(email).deliver_now + end end diff --git a/app/views/admins/approvals.html.erb b/app/views/admins/approvals.html.erb new file mode 100644 index 000000000..3bb514c26 --- /dev/null +++ b/app/views/admins/approvals.html.erb @@ -0,0 +1,24 @@ +<%= csrf_meta_tags %> +
+ <%# data headers %> + <% if @users.empty? %> +

No Pending Approvals

+ <% end %> +
+
ID
+
Username
+
Email
+
Action
+
+ + <%# loop all data here %> + <% @users.each do |user| %> +
+
<%= user.id %>
+
<%= user.username %>
+
<%= user.email %>
+ <%= link_to "Admit", admins_approvals_path(id: user.id, admitted: true), method: :put %> +
+ <% end %> +
+
\ No newline at end of file diff --git a/app/views/admins/index.html.erb b/app/views/admins/index.html.erb deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/views/admins/user_portfolio.html.erb b/app/views/admins/user_portfolio.html.erb new file mode 100644 index 000000000..b66f12a0d --- /dev/null +++ b/app/views/admins/user_portfolio.html.erb @@ -0,0 +1,46 @@ +<%= csrf_meta_tags %> +

Admin Center

+ +
+
+
+

User List

+ <%= link_to 'Create User', admins_add_user_path, {remote: true, 'data-toggle' => "modal", 'data-target' => '#applicationModal', class: "link-nav-btn-primary-dark" } %> +
+ <%# add user path should have views and controller %> + <%= link_to "Go to Approvals", admins_approvals_path, method: 'get'%> +
+ <%# data headers %> + <% if @users.empty? %> +

No Admitted Users yet

+ <% else %> +
+
ID
+
Username
+
Email
+
Action
+
+ + <%# loop all data here %> + + <% @users.each do |user| %> + + + <% end %> +
<%= user.email %> + <%= user.approved %> + <%= link_to "Edit", edit_user_path(user) %> +
+ // <%# @users.each do |user| %> + // <%# if user.admitted == false %> + // <%#= user.username %>
+ // <%#= user.email %>
+ // <%#= link_to "View", user_profile_path(id: user.id), method: 'get' %> + // <%#= link_to "Edit User", edit_user_profile_path(id: user.id), method: 'get' %> + // <%#= button_to "Approve", admins_admissions_path(id: user.id), method: 'put' %> + // <%# end %> + // <%# end %> + <% end %> + +
+
\ No newline at end of file diff --git a/app/views/approved_mailer/approved_account_mailer.html.erb b/app/views/approved_mailer/approved_account_mailer.html.erb new file mode 100644 index 000000000..5f3d286b4 --- /dev/null +++ b/app/views/approved_mailer/approved_account_mailer.html.erb @@ -0,0 +1 @@ +

Your profile has been activated and approved. Enjoy trading!

\ No newline at end of file diff --git a/app/views/layouts/mailer.html.haml b/app/views/layouts/mailer.html.haml new file mode 100644 index 000000000..28739ee90 --- /dev/null +++ b/app/views/layouts/mailer.html.haml @@ -0,0 +1,3 @@ +%hmtl + %body + = yield \ No newline at end of file diff --git a/app/views/layouts/mailer.text.haml b/app/views/layouts/mailer.text.haml new file mode 100644 index 000000000..f1d0cc898 --- /dev/null +++ b/app/views/layouts/mailer.text.haml @@ -0,0 +1 @@ += yield \ No newline at end of file diff --git a/app/views/welcome_mailer/welcome_account_mailer.html.erb b/app/views/welcome_mailer/welcome_account_mailer.html.erb new file mode 100644 index 000000000..0f53f2c95 --- /dev/null +++ b/app/views/welcome_mailer/welcome_account_mailer.html.erb @@ -0,0 +1 @@ +

Welcome to the Stock App. Wait for your approval!

\ No newline at end of file diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc index 33a6f8602..ca0654ee7 100644 --- a/config/credentials.yml.enc +++ b/config/credentials.yml.enc @@ -1 +1 @@ -E0IaCsfo22vYBVLD7D1ksFnaWYDd/jBAOQxmnfOjCjqvD4OOX73/omJr6j7ySGdFuUEBYNmVj6r9Aoi3CjiTmESXJ3Hf11+J6EUxflMDjf9IZuESiQi+1Bzso/7OTQ1hy1XEVZTUKirNzhN0dCviOSOrEsFRYVp2XYiHrJNCMP04fnqQEpS8sjUSNGA5tFJ1LCNRR0dEGMu6qdmGkmaIP32pxbbCQ8yst+IzKqi5NpfVwcZU1s0+UQgcJphwjIvsf50nq0iy+y0iAjJ+QPXpYVgFhv3KHIGUk/yHdPSwm7Q+vlozB+Vuyn58XvssKZOkNzWluBMlk5elwe4xMShB82AxbyUPWY8v+rDHlni6y9c1R4v/ttaTl4bgzDJQ3DoCvRzsw7qB/RBUpCbsrq3zxYOQ8fm7WMuk30ZmBvx8yoxMsd+k9c7TZcS5lEZdcpznhMkXJt2Yd75tcBi2b1e76EpA2d1UuaO1i3IgfBbiM29zafSa/OD9rcbz2GcLs24wiK/80Oc+SGUCbT+SFpRQhnw58BrfgXe1wA6ny2t8oQxK+xU=--FsltHkXQrDkMtiPF--9ptQ3R64z2Wlf7FF25hcOQ== \ No newline at end of file +cSKRZpbDhjVidZ5eHDlvZHCY8IP+iMQdq3rIyeOuYBegPWDfd2ejZbMz9yGP4ItCJSOa5c17crNbbXLQ68+v3J+H3JEt1Oxz7P+LLWhxdOzedssZpZxkgcCebtbhZpVle/Jx0Sd7uYG9S/A+PH2Q5BNO9vzuYgDBbt80MuC4/2/DQJTeNAxAXoqzkn0CT3lqYbWfM0cR4Ec+PAhM3a9lg4R+7XPqZTGs0RRPYApeX3anN5QI08KR7+HoXCAfeA/Ysy6LzcwK9Enn1hzFgmQXH0dqseIxLBGzjkYj6cvMDo8cFvitVDzFDA/C4M7wC1r5VGkhlAnhQiMkOMqoAnG0K6tZnemHVYOZhl9aF3eBjSeVXq9TgSsheBx1LB95JU/piwLCycQKSD67knFzB2giwaa9251GmoKzrlXwVafov2bn+gIzTtSTNkeoFVwxXww5bFQFfqtPBKQY/1ZDdpxiVgfV7a7J59h6NrYD+IlfCpxrx06Us3nl6E/Sul2TqAxzAS0YZSw5l6pi7TzssAzZ4QOr3FKaLjLKtqbIuyzhwVS+r+rlBpQayNkviT5MTs7vLKDuKWPmbw3z4YD57Q/8T6OXhlMvwQVesTT3PXyYcyFX2i9JEb8VsNPcyaRC9UmBMAC5qc7//UA2zrXc2jsLlAQ132oy--lW1xEcTcJr/azKcb--CgTTuSimfmiDALelqQGxWA== \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index 412dda94d..9d89c6c10 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -37,7 +37,8 @@ config.action_mailer.perform_caching = false # The generator will install an initializer which describes ALL of Devise's configuration options. - config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } + host = 'localhost:3000' + config.action_mailer.default_url_options = { :host => 'localhost:3000', protocol: 'http' } # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log diff --git a/config/environments/production.rb b/config/environments/production.rb index 69afea11b..cd5c7740a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -109,4 +109,17 @@ # config.active_record.database_selector = { delay: 2.seconds } # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session + config.action_mailer.delivery_method = :smtp + host = 'https://rails-stock-trading-app.herokuapp.com/' #replace with your own url + config.action_mailer.default_url_options = { host: host } + + # SMTP settings for gmail + config.action_mailer.smtp_settings = { + :address => "smtp.gmail.com", + :port => 587, + :user_name => , + :password => , + :authentication => "plain", + :enable_starttls_auto => true + } end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 79e5e47f4..bb4dfadfa 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -24,7 +24,7 @@ # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class # with default "from" parameter. - config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' + config.mailer_sender = 'pickystocker@gmail.com' # Configure the class responsible to send e-mails. # config.mailer = 'Devise::Mailer' diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml index c9602d553..f2dbd6c9e 100644 --- a/config/locales/devise.en.yml +++ b/config/locales/devise.en.yml @@ -38,7 +38,12 @@ en: send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." updated: "Your password has been changed successfully. You are now signed in." updated_not_active: "Your password has been changed successfully." + devise: registrations: + user: + signed_up_but_not_approved: 'You have signed up successfully but your account has not been approved by your administrator yet' + failure: + not_approved: 'Your account has not been approved by your administrator yet.' destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon." signed_up: "Welcome! You have signed up successfully." signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." diff --git a/config/routes.rb b/config/routes.rb index 443e41d9f..745f027c8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,13 +10,18 @@ # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html - resources :wallets, except: [:destroy] do - collection do - get 'deposit' - get 'withdraw' - end + + #routes for admin only + authenticated :admin do + get '/admins/user-portfolio', to: 'admins#user_portfolio' #list view of users + get '/admins/approvals', to: 'admins#approvals' #view to approve users + put '/admins/approvals', to: 'admins#approve_account' #acting to approve the account of user + get '/admins/add_user', to: 'admins#add_user' + post '/admins/add_user', to: 'admins#create_user' + get '/admins/user-portfolio/:id', to: 'admins#show_user', as: :user_profile + put '/admins/user-portfolio/:id', to: 'admins#modify_user' + patch '/admins/user-portfolio/:id', to: 'admins#modify_user' + get '/admins/user-portfolio/:id/edit', to: 'admins#edit_user', as: :edit_user_profile end - get 'wallets_ontroller', to: 'wallets_controller#index' - # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html end diff --git a/db/migrate/20210921164734_remove_approved_from_users.rb b/db/migrate/20210921164734_remove_approved_from_users.rb new file mode 100644 index 000000000..73e692aad --- /dev/null +++ b/db/migrate/20210921164734_remove_approved_from_users.rb @@ -0,0 +1,5 @@ +class RemoveApprovedFromUsers < ActiveRecord::Migration[6.0] + def change + remove_column :users, :approved, :boolean + end +end diff --git a/db/migrate/20210922145110_add_approved_to_user.rb b/db/migrate/20210922145110_add_approved_to_user.rb new file mode 100644 index 000000000..c9bd03a81 --- /dev/null +++ b/db/migrate/20210922145110_add_approved_to_user.rb @@ -0,0 +1,11 @@ +class AddApprovedToUser < ActiveRecord::Migration[6.0] + def self.up + add_column :users, :approved, :boolean, :default => false, :null => false + add_index :users, :approved + end + + def self.down + remove_index :users, :approved + remove_column :users, :approved + end +end diff --git a/db/schema.rb b/db/schema.rb index a28e4c92f..7719fcd18 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_09_21_032630) do +ActiveRecord::Schema.define(version: 2021_09_22_145110) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -39,7 +39,8 @@ t.string "last_name" t.string "username" t.integer "wallet_id" - t.boolean "approved" + t.boolean "approved", default: false, null: false + t.index ["approved"], name: "index_users_on_approved" t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end diff --git a/spec/mailers/admin_mailer_spec.rb b/spec/mailers/admin_mailer_spec.rb new file mode 100644 index 000000000..b28ea3c4a --- /dev/null +++ b/spec/mailers/admin_mailer_spec.rb @@ -0,0 +1,5 @@ +require "rails_helper" + +RSpec.describe AdminMailer, type: :mailer do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/mailers/previews/admin_mailer_preview.rb b/spec/mailers/previews/admin_mailer_preview.rb new file mode 100644 index 000000000..73ea1b7b0 --- /dev/null +++ b/spec/mailers/previews/admin_mailer_preview.rb @@ -0,0 +1,4 @@ +# Preview all emails at http://localhost:3000/rails/mailers/admin_mailer +class AdminMailerPreview < ActionMailer::Preview + +end From 50708a6e7b0d5172648ec52c5e66ebce308c3728 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 23 Sep 2021 00:28:27 +0800 Subject: [PATCH 051/106] rubocop mailers, controllers, models, views and routes --- app/controllers/application_controller.rb | 8 ++++---- app/mailers/admin_mailer.rb | 2 +- app/mailers/approved_mailer.rb | 2 +- app/mailers/welcome_mailer.rb | 2 +- app/models/user.rb | 15 ++++++++------- app/views/admins/user_portfolio.html.erb | 11 +---------- config/routes.rb | 10 ++++++++-- spec/mailers/admin_mailer_spec.rb | 2 +- spec/mailers/previews/admin_mailer_preview.rb | 1 - 9 files changed, 25 insertions(+), 28 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 655c8ebc7..dd7db3bcb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,14 +5,14 @@ class ApplicationController < ActionController::Base private # Overwriting the sign_out redirect path method - def after_sign_out_path_for(resource) + def after_sign_out_path_for(_resource) root_path end def after_sign_in_path_for(resource) - if resource.class == Admin - admins_user_portfolio_path - elsif resource.class == User + if resource.instance_of?(Admin) + admins_user_portfolio_path + elsif resource.instance_of?(User) user_homepage_path(current_user) end end diff --git a/app/mailers/admin_mailer.rb b/app/mailers/admin_mailer.rb index 509dc7810..c78dcc254 100644 --- a/app/mailers/admin_mailer.rb +++ b/app/mailers/admin_mailer.rb @@ -6,4 +6,4 @@ def new_user_waiting_for_approval(email) @email = email mail(to: 'pickystocker@gmail.com', subject: 'New user awaiting admin approval') end -end \ No newline at end of file +end diff --git a/app/mailers/approved_mailer.rb b/app/mailers/approved_mailer.rb index 9d015ef09..299d94c03 100644 --- a/app/mailers/approved_mailer.rb +++ b/app/mailers/approved_mailer.rb @@ -2,4 +2,4 @@ class ApprovedMailer < ApplicationMailer def approved_account_mailer(email) mail(to: email, subject: 'Account has been admitted!') end -end \ No newline at end of file +end diff --git a/app/mailers/welcome_mailer.rb b/app/mailers/welcome_mailer.rb index 111e74e1d..ddf37e0ee 100644 --- a/app/mailers/welcome_mailer.rb +++ b/app/mailers/welcome_mailer.rb @@ -2,4 +2,4 @@ class WelcomeMailer < ApplicationMailer def welcome_account_mailer(email) mail(to: email, subject: 'Welome to Stock app!') end -end \ No newline at end of file +end diff --git a/app/models/user.rb b/app/models/user.rb index af021105f..ee03a5b9b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,6 +2,7 @@ class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable after_create :send_welcome_email + has_many :wallets, dependent: :destroy devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable @@ -9,15 +10,15 @@ class User < ApplicationRecord validates :first_name, presence: true validates :last_name, presence: true - #Override the following methods in approval model - def active_for_authentication? - super && approved? - end - - def inactive_message + # Override the following methods in approval model + def active_for_authentication? + super && approved? + end + + def inactive_message approved? ? super : :not_approved end - + private def send_welcome_email diff --git a/app/views/admins/user_portfolio.html.erb b/app/views/admins/user_portfolio.html.erb index b66f12a0d..3e2772bc7 100644 --- a/app/views/admins/user_portfolio.html.erb +++ b/app/views/admins/user_portfolio.html.erb @@ -31,16 +31,7 @@ <% end %> - // <%# @users.each do |user| %> - // <%# if user.admitted == false %> - // <%#= user.username %>
- // <%#= user.email %>
- // <%#= link_to "View", user_profile_path(id: user.id), method: 'get' %> - // <%#= link_to "Edit User", edit_user_profile_path(id: user.id), method: 'get' %> - // <%#= button_to "Approve", admins_admissions_path(id: user.id), method: 'put' %> - // <%# end %> - // <%# end %> - <% end %> + <% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 745f027c8..94ac4e1ee 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,9 +7,15 @@ resources :users do get 'homepage', to: 'portfolios#index' end - - # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html + resources :wallets, except: [:destroy] do + collection do + get 'deposit' + get 'withdraw' + end + end + get 'wallets_ontroller', to: 'wallets_controller#index' + # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html #routes for admin only authenticated :admin do diff --git a/spec/mailers/admin_mailer_spec.rb b/spec/mailers/admin_mailer_spec.rb index b28ea3c4a..9264c50f9 100644 --- a/spec/mailers/admin_mailer_spec.rb +++ b/spec/mailers/admin_mailer_spec.rb @@ -1,4 +1,4 @@ -require "rails_helper" +require 'rails_helper' RSpec.describe AdminMailer, type: :mailer do pending "add some examples to (or delete) #{__FILE__}" diff --git a/spec/mailers/previews/admin_mailer_preview.rb b/spec/mailers/previews/admin_mailer_preview.rb index 73ea1b7b0..b3f5edda0 100644 --- a/spec/mailers/previews/admin_mailer_preview.rb +++ b/spec/mailers/previews/admin_mailer_preview.rb @@ -1,4 +1,3 @@ # Preview all emails at http://localhost:3000/rails/mailers/admin_mailer class AdminMailerPreview < ActionMailer::Preview - end From b29221c967a3942d32d45d01ac83b288c03a9285 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 23 Sep 2021 00:31:06 +0800 Subject: [PATCH 052/106] added needed changes for model user and approved mailer --- app/models/user.rb | 1 - ...ccount_mailer.html.erb => admitted_mailer.html.erb} | 0 config/routes.rb | 10 ++-------- 3 files changed, 2 insertions(+), 9 deletions(-) rename app/views/approved_mailer/{approved_account_mailer.html.erb => admitted_mailer.html.erb} (100%) diff --git a/app/models/user.rb b/app/models/user.rb index ee03a5b9b..bfa11a9a6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,7 +2,6 @@ class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable after_create :send_welcome_email - has_many :wallets, dependent: :destroy devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable diff --git a/app/views/approved_mailer/approved_account_mailer.html.erb b/app/views/approved_mailer/admitted_mailer.html.erb similarity index 100% rename from app/views/approved_mailer/approved_account_mailer.html.erb rename to app/views/approved_mailer/admitted_mailer.html.erb diff --git a/config/routes.rb b/config/routes.rb index 94ac4e1ee..745f027c8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,16 +7,10 @@ resources :users do get 'homepage', to: 'portfolios#index' end - - resources :wallets, except: [:destroy] do - collection do - get 'deposit' - get 'withdraw' - end - end - get 'wallets_ontroller', to: 'wallets_controller#index' + # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html + #routes for admin only authenticated :admin do get '/admins/user-portfolio', to: 'admins#user_portfolio' #list view of users From 9b73226fe20a9f33279b21d97a3ecb32c7ce0084 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 23 Sep 2021 01:08:05 +0800 Subject: [PATCH 053/106] Admin: views on adding user --- app/views/admins/add_user.html.erb | 13 +++++++++++++ app/views/admins/user_portfolio.html.erb | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 app/views/admins/add_user.html.erb diff --git a/app/views/admins/add_user.html.erb b/app/views/admins/add_user.html.erb new file mode 100644 index 000000000..066bc1c12 --- /dev/null +++ b/app/views/admins/add_user.html.erb @@ -0,0 +1,13 @@ + <%= form_with scope: :user, url: '/admins/add_user', method: :post do |f| %> +
+ <%= f.email_field :email, autofocus: true, autocomplete: "email", placeholder: "Email" %> + <%= f.text_field :first_name, autofocus: true, autocomplete: :off, placeholder: "First Name" %> + <%= f.text_field :last_name, autofocus: true, autocomplete: :off, placeholder: "Last Name" %> + <%= f.text_field :username, autofocus: true, autocomplete: :off, placeholder: "Username" %> + <%= f.password_field :password, autocomplete: "new-password", placeholder: "Password (6 characters minimum)" %> + <%= f.password_field :password_confirmation, autocomplete: "new-password", placeholder: "Confirm Password" %> +
+
+ <%= f.submit "Create Account" %> +
+ <% end %> \ No newline at end of file diff --git a/app/views/admins/user_portfolio.html.erb b/app/views/admins/user_portfolio.html.erb index 3e2772bc7..3bffceb74 100644 --- a/app/views/admins/user_portfolio.html.erb +++ b/app/views/admins/user_portfolio.html.erb @@ -5,7 +5,7 @@

User List

- <%= link_to 'Create User', admins_add_user_path, {remote: true, 'data-toggle' => "modal", 'data-target' => '#applicationModal', class: "link-nav-btn-primary-dark" } %> + <%= link_to 'Create User', admins_add_user_path %>
<%# add user path should have views and controller %> <%= link_to "Go to Approvals", admins_approvals_path, method: 'get'%> From b2bd25c2a24c7779a806daeefe8816b25638fe63 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 23 Sep 2021 01:19:46 +0800 Subject: [PATCH 054/106] registration controller: added autofocus, new file in user index, corrected the routes from the previous PR --- .../users/registrations_controller.rb | 12 ++++++------ app/views/users/index.html.erb | 10 ++++++++++ app/views/users/registrations/new.html.erb | 18 +++++++++--------- config/routes.rb | 5 +++++ 4 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 app/views/users/index.html.erb diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index b9e664fe3..4ca0ed55a 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -10,9 +10,9 @@ class Users::RegistrationsController < Devise::RegistrationsController # end # POST /resource - # def create - # super - # end + def create + super + end # GET /resource/edit # def edit @@ -41,9 +41,9 @@ class Users::RegistrationsController < Devise::RegistrationsController # protected # If you have extra params to permit, append them to the sanitizer. - # def configure_sign_up_params - # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute]) - # end + def configure_sign_up_params + devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute]) + end # If you have extra params to permit, append them to the sanitizer. # def configure_account_update_params diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb new file mode 100644 index 000000000..5ca30429d --- /dev/null +++ b/app/views/users/index.html.erb @@ -0,0 +1,10 @@ +

User Details

+ + + + + + + + +
Name: <%= @user.first_name %><%= @user.last_name %>Email: <%= @user.email %>
\ No newline at end of file diff --git a/app/views/users/registrations/new.html.erb b/app/views/users/registrations/new.html.erb index 7009d8e9d..97be8837c 100644 --- a/app/views/users/registrations/new.html.erb +++ b/app/views/users/registrations/new.html.erb @@ -8,22 +8,22 @@ <%= f.email_field :email, class:"form-control", placeholder:"Email", autofocus: true, autocomplete: "email" %> -
+
<%= f.label :username %>
- <%= f.text_field :username %> + <%= f.username_field :username, autofocus: true, autocomplete: "username" %>
-
- <%= f.label :first_name %>
- <%= f.text_field :first_name %> +
+ <%= f.label :firstname %>
+ <%= f.first_name_field :firstname, autofocus: true, autocomplete: "firstname" %>
-
- <%= f.label :last_name %>
- <%= f.text_field :last_name %> +
+ <%= f.label :lastname %>
+ <%= f.last_name_field :lastname, autofocus: true, autocomplete: "lastname" %>
-
+
<%= f.label :password %> <% if @minimum_password_length %> (<%= @minimum_password_length %> characters minimum) diff --git a/config/routes.rb b/config/routes.rb index 745f027c8..82bd25aac 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,11 @@ Rails.application.routes.draw do +<<<<<<< Updated upstream devise_for :admins, path: 'admins', controllers: { sessions: "admins/sessions"} devise_for :users, path: 'users', controllers: { sessions: "users/sessions" , registrations: 'users/registrations'} +======= + devise_for :admins, path: 'admins', controllers: { sessions: "admins/sessions", registrations: : 'users/registrations'} + devise_for :users, path: 'users', controllers: { sessions: "users/sessions" } +>>>>>>> Stashed changes # get 'home/index' root 'home#index' From 4124bcc734749c08ca4cf14855e25b7ecc3d9fa9 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 23 Sep 2021 01:37:22 +0800 Subject: [PATCH 055/106] deleted bootstrap in stylsheets, renamed mailer, changes text type in registrations, edited routes to route properly --- app/assets/stylesheets/application.scss | 2 -- ...ml.erb => approved_account_mailer.html.erb} | 0 app/views/users/registrations/new.html.erb | 18 +++++++++--------- config/routes.rb | 5 ----- 4 files changed, 9 insertions(+), 16 deletions(-) rename app/views/approved_mailer/{admitted_mailer.html.erb => approved_account_mailer.html.erb} (100%) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 7b3957a4e..d05ea0f51 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -13,5 +13,3 @@ *= require_tree . *= require_self */ - -@import "bootstrap"; diff --git a/app/views/approved_mailer/admitted_mailer.html.erb b/app/views/approved_mailer/approved_account_mailer.html.erb similarity index 100% rename from app/views/approved_mailer/admitted_mailer.html.erb rename to app/views/approved_mailer/approved_account_mailer.html.erb diff --git a/app/views/users/registrations/new.html.erb b/app/views/users/registrations/new.html.erb index 97be8837c..7009d8e9d 100644 --- a/app/views/users/registrations/new.html.erb +++ b/app/views/users/registrations/new.html.erb @@ -8,22 +8,22 @@ <%= f.email_field :email, class:"form-control", placeholder:"Email", autofocus: true, autocomplete: "email" %>
-
+
<%= f.label :username %>
- <%= f.username_field :username, autofocus: true, autocomplete: "username" %> + <%= f.text_field :username %>
-
- <%= f.label :firstname %>
- <%= f.first_name_field :firstname, autofocus: true, autocomplete: "firstname" %> +
+ <%= f.label :first_name %>
+ <%= f.text_field :first_name %>
-
- <%= f.label :lastname %>
- <%= f.last_name_field :lastname, autofocus: true, autocomplete: "lastname" %> +
+ <%= f.label :last_name %>
+ <%= f.text_field :last_name %>
-
+
<%= f.label :password %> <% if @minimum_password_length %> (<%= @minimum_password_length %> characters minimum) diff --git a/config/routes.rb b/config/routes.rb index 82bd25aac..745f027c8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,11 +1,6 @@ Rails.application.routes.draw do -<<<<<<< Updated upstream devise_for :admins, path: 'admins', controllers: { sessions: "admins/sessions"} devise_for :users, path: 'users', controllers: { sessions: "users/sessions" , registrations: 'users/registrations'} -======= - devise_for :admins, path: 'admins', controllers: { sessions: "admins/sessions", registrations: : 'users/registrations'} - devise_for :users, path: 'users', controllers: { sessions: "users/sessions" } ->>>>>>> Stashed changes # get 'home/index' root 'home#index' From 046f57bdfd511f86f125f5a487b54a0a0c01489c Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 23 Sep 2021 01:38:42 +0800 Subject: [PATCH 056/106] rubocop fix in registration controller --- app/controllers/users/registrations_controller.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 4ca0ed55a..f73825c70 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -10,9 +10,6 @@ class Users::RegistrationsController < Devise::RegistrationsController # end # POST /resource - def create - super - end # GET /resource/edit # def edit From 07ad3e60a144a05bdd1181edf9ca15f2c8c7e506 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 23 Sep 2021 09:37:24 +0800 Subject: [PATCH 057/106] added extra lines to views admins, views layouts and added dummy email details to production.rb --- app/views/admins/add_user.html.erb | 26 ++++++++++++------------ app/views/admins/approvals.html.erb | 7 +++---- app/views/admins/user_portfolio.html.erb | 2 +- app/views/layouts/mailer.html.haml | 3 ++- app/views/layouts/mailer.text.haml | 2 +- app/views/users/index.html.erb | 3 ++- config/environments/production.rb | 4 ++-- 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/app/views/admins/add_user.html.erb b/app/views/admins/add_user.html.erb index 066bc1c12..a02cfbb9a 100644 --- a/app/views/admins/add_user.html.erb +++ b/app/views/admins/add_user.html.erb @@ -1,13 +1,13 @@ - <%= form_with scope: :user, url: '/admins/add_user', method: :post do |f| %> -
- <%= f.email_field :email, autofocus: true, autocomplete: "email", placeholder: "Email" %> - <%= f.text_field :first_name, autofocus: true, autocomplete: :off, placeholder: "First Name" %> - <%= f.text_field :last_name, autofocus: true, autocomplete: :off, placeholder: "Last Name" %> - <%= f.text_field :username, autofocus: true, autocomplete: :off, placeholder: "Username" %> - <%= f.password_field :password, autocomplete: "new-password", placeholder: "Password (6 characters minimum)" %> - <%= f.password_field :password_confirmation, autocomplete: "new-password", placeholder: "Confirm Password" %> -
-
- <%= f.submit "Create Account" %> -
- <% end %> \ No newline at end of file +<%= form_with scope: :user, url: '/admins/add_user', method: :post do |f| %> +
+ <%= f.email_field :email, autofocus: true, autocomplete: "email", placeholder: "Email" %> + <%= f.text_field :first_name, autofocus: true, autocomplete: :off, placeholder: "First Name" %> + <%= f.text_field :last_name, autofocus: true, autocomplete: :off, placeholder: "Last Name" %> + <%= f.text_field :username, autofocus: true, autocomplete: :off, placeholder: "Username" %> + <%= f.password_field :password, autocomplete: "new-password", placeholder: "Password (6 characters minimum)" %> + <%= f.password_field :password_confirmation, autocomplete: "new-password", placeholder: "Confirm Password" %> +
+
+ <%= f.submit "Create Account" %> +
+<% end %> \ No newline at end of file diff --git a/app/views/admins/approvals.html.erb b/app/views/admins/approvals.html.erb index 3bb514c26..66a886c59 100644 --- a/app/views/admins/approvals.html.erb +++ b/app/views/admins/approvals.html.erb @@ -1,6 +1,5 @@ -<%= csrf_meta_tags %> -
- <%# data headers %> +
+ <%# data on %> %> <% if @users.empty? %>

No Pending Approvals

<% end %> @@ -21,4 +20,4 @@
<% end %>
-
\ No newline at end of file +
diff --git a/app/views/admins/user_portfolio.html.erb b/app/views/admins/user_portfolio.html.erb index 3bffceb74..0106c7e17 100644 --- a/app/views/admins/user_portfolio.html.erb +++ b/app/views/admins/user_portfolio.html.erb @@ -34,4 +34,4 @@ <% end %>
- \ No newline at end of file + diff --git a/app/views/layouts/mailer.html.haml b/app/views/layouts/mailer.html.haml index 28739ee90..12bb582bc 100644 --- a/app/views/layouts/mailer.html.haml +++ b/app/views/layouts/mailer.html.haml @@ -1,3 +1,4 @@ %hmtl %body - = yield \ No newline at end of file + = yield + \ No newline at end of file diff --git a/app/views/layouts/mailer.text.haml b/app/views/layouts/mailer.text.haml index f1d0cc898..0a90f092c 100644 --- a/app/views/layouts/mailer.text.haml +++ b/app/views/layouts/mailer.text.haml @@ -1 +1 @@ -= yield \ No newline at end of file += yield diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 5ca30429d..a30e42e93 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -7,4 +7,5 @@ Email: <%= @user.email %> - \ No newline at end of file + + \ No newline at end of file diff --git a/config/environments/production.rb b/config/environments/production.rb index cd5c7740a..8b0d9a5a2 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -117,8 +117,8 @@ config.action_mailer.smtp_settings = { :address => "smtp.gmail.com", :port => 587, - :user_name => , - :password => , + :user_name => pickystocker, + :password => avioschool2021, :authentication => "plain", :enable_starttls_auto => true } From 08d9cfa9a0864a7ecb00da893d27e87a313a951b Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 23 Sep 2021 10:11:33 +0800 Subject: [PATCH 058/106] reverted back to placeholder in envrionment and production and renamed approved mailer --- ...roved_account_mailer.html.erb => approved_mailer.html.erb} | 0 config/environments/production.rb | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename app/views/approved_mailer/{approved_account_mailer.html.erb => approved_mailer.html.erb} (100%) diff --git a/app/views/approved_mailer/approved_account_mailer.html.erb b/app/views/approved_mailer/approved_mailer.html.erb similarity index 100% rename from app/views/approved_mailer/approved_account_mailer.html.erb rename to app/views/approved_mailer/approved_mailer.html.erb diff --git a/config/environments/production.rb b/config/environments/production.rb index 8b0d9a5a2..cd5c7740a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -117,8 +117,8 @@ config.action_mailer.smtp_settings = { :address => "smtp.gmail.com", :port => 587, - :user_name => pickystocker, - :password => avioschool2021, + :user_name => , + :password => , :authentication => "plain", :enable_starttls_auto => true } From 303a6d220f39e3610a348f46811756b930b6c368 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 23 Sep 2021 10:25:03 +0800 Subject: [PATCH 059/106] deleted spaces so github will recognize it as newline for views admin,layout and users --- app/views/admins/add_user.html.erb | 2 +- app/views/layouts/mailer.html.haml | 1 - app/views/users/index.html.erb | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/views/admins/add_user.html.erb b/app/views/admins/add_user.html.erb index a02cfbb9a..79acdb061 100644 --- a/app/views/admins/add_user.html.erb +++ b/app/views/admins/add_user.html.erb @@ -10,4 +10,4 @@
<%= f.submit "Create Account" %>
-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/layouts/mailer.html.haml b/app/views/layouts/mailer.html.haml index 12bb582bc..4e34f078a 100644 --- a/app/views/layouts/mailer.html.haml +++ b/app/views/layouts/mailer.html.haml @@ -1,4 +1,3 @@ %hmtl %body = yield - \ No newline at end of file diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index a30e42e93..4efca7a2c 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -8,4 +8,3 @@ - \ No newline at end of file From d4e3c5068ca0c55637c7549bc184bcc999b30055 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 23 Sep 2021 13:06:13 +0800 Subject: [PATCH 060/106] added the necessary credentials on the placeholder for gmailer --- config/environments/production.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index cd5c7740a..8e2e8face 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -117,8 +117,8 @@ config.action_mailer.smtp_settings = { :address => "smtp.gmail.com", :port => 587, - :user_name => , - :password => , + :user_name => Rails.application.credentials.gmail_mailer[:username], + :password => Rails.application.credentials.gmail_mailer[:password]>, :authentication => "plain", :enable_starttls_auto => true } From a04aab562ad4d196a1050bd9062f3d02abeb6da0 Mon Sep 17 00:00:00 2001 From: Warda Nur Date: Thu, 23 Sep 2021 18:32:48 +0800 Subject: [PATCH 061/106] App UI: updated login, sign up and homepage html.erb file --- app/views/admins/shared/_links.html.erb | 2 ++ app/views/home/_header.html.erb | 11 +++---- app/views/layouts/application.html.erb | 2 +- app/views/portfolios/index.html.erb | 28 ++++++++++++----- app/views/shared/_balance.html.erb | 27 ----------------- app/views/users/registrations/new.html.erb | 34 ++++++++++++++------- app/views/users/sessions/new.html.erb | 35 ++++++++++++++++------ app/views/users/shared/_links.html.erb | 20 +++++++------ app/views/wallets/index.html.erb | 21 ------------- config/locales/devise.en.yml | 2 +- 10 files changed, 90 insertions(+), 92 deletions(-) delete mode 100644 app/views/wallets/index.html.erb diff --git a/app/views/admins/shared/_links.html.erb b/app/views/admins/shared/_links.html.erb index 084af701c..aaecf0e8a 100644 --- a/app/views/admins/shared/_links.html.erb +++ b/app/views/admins/shared/_links.html.erb @@ -6,10 +6,12 @@ <%= link_to "Sign up", new_registration_path(resource_name) %>
<% end %> + <%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> <%= link_to "Forgot your password?", new_password_path(resource_name) %>
<% end %> + <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
<% end %> diff --git a/app/views/home/_header.html.erb b/app/views/home/_header.html.erb index a1c2cde0d..1be711404 100644 --- a/app/views/home/_header.html.erb +++ b/app/views/home/_header.html.erb @@ -1,6 +1,7 @@ -