diff --git a/Gemfile b/Gemfile index 4b0a014a..162155eb 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,8 @@ end gem 'rails', '~> 5.1' gem 'pg' -gem 'authlogic', '~> 3' +gem 'devise' +gem 'devise-encryptable' gem 'jc-validates_timeliness' gem 'awesome_nested_set' gem 'will_paginate' @@ -18,8 +19,8 @@ gem 'cups' gem 'simple_form' # Files Processors -gem 'carrierwave' -gem 'carrierwave_backgrounder' +gem 'carrierwave', '~> 0.11.2' +gem 'carrierwave_backgrounder', '~> 0.4.2' gem 'mini_magick', '3.8.1' gem 'rghost' #Could make it happen only with carrierwave gem 'pdf-reader' diff --git a/Gemfile.lock b/Gemfile.lock index 2b0b56fc..b723700e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -48,15 +48,11 @@ GEM archive-zip (0.7.0) io-like (~> 0.3.0) arel (8.0.0) - authlogic (3.6.1) - activerecord (>= 3.2, < 5.2) - activesupport (>= 3.2, < 5.2) - request_store (~> 1.0) - scrypt (>= 1.2, < 4.0) awesome_nested_set (3.1.3) activerecord (>= 4.0.0, < 5.2) awesome_print (1.8.0) barby (0.6.5) + bcrypt (3.1.12) bcrypt_pbkdf (1.0.0) bugsnag (6.3.0) builder (3.2.3) @@ -116,6 +112,14 @@ GEM database_cleaner (1.6.2) declarative (0.0.10) declarative-option (0.1.0) + devise (4.5.0) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0, < 6.0) + responders + warden (~> 1.2.3) + devise-encryptable (0.2.0) + devise (>= 2.1.0) ed25519 (1.2.4) erubi (1.7.0) eventmachine (1.2.5) @@ -123,9 +127,6 @@ GEM faraday (0.13.1) multipart-post (>= 1.2, < 3) ffi (1.9.18) - ffi-compiler (1.0.1) - ffi (>= 1.0.0) - rake get_process_mem (0.2.1) globalid (0.4.1) activesupport (>= 4.2.0) @@ -206,6 +207,7 @@ GEM nio4r (2.1.0) nokogiri (1.8.1) mini_portile2 (~> 2.3.0) + orm_adapter (0.5.0) os (0.9.6) paper_trail (8.1.1) activerecord (>= 4.2, < 5.2) @@ -270,6 +272,9 @@ GEM declarative-option (< 0.2.0) uber (< 0.2.0) request_store (1.3.2) + responders (2.4.0) + actionpack (>= 4.2.0, < 5.3) + railties (>= 4.2.0, < 5.3) retriable (3.1.1) rghost (0.9.6) rqrcode (0.10.1) @@ -288,8 +293,6 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - scrypt (3.0.5) - ffi-compiler (>= 1.0, < 2.0) selenium-webdriver (2.53.4) childprocess (~> 0.5) rubyzip (~> 1.0) @@ -346,6 +349,8 @@ GEM unicorn-worker-killer (0.4.4) get_process_mem (~> 0) unicorn (>= 4, < 6) + warden (1.2.7) + rack (>= 1.0) websocket (1.2.5) websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) @@ -361,7 +366,6 @@ PLATFORMS DEPENDENCIES RedCloth - authlogic (~> 3) awesome_nested_set awesome_print barby @@ -374,13 +378,15 @@ DEPENDENCIES capistrano-rails capybara capybara-screenshot - carrierwave - carrierwave_backgrounder + carrierwave (~> 0.11.2) + carrierwave_backgrounder (~> 0.4.2) chromedriver-helper chunky_png coffee-rails (~> 4.2) cups database_cleaner + devise + devise-encryptable ed25519 google_drive interactive_editor @@ -415,4 +421,4 @@ DEPENDENCIES will_paginate BUNDLED WITH - 1.16.1 + 1.16.4 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d3e8fbb1..c75ea63d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :null_session, unless: :trusted_sites - before_action :set_js_format_in_iframe_request, :set_paper_trail_whodunnit + before_action :set_js_format_in_iframe_request, :set_paper_trail_whodunnit, :assign_currents before_bugsnag_notify :add_user_info_to_bugsnag after_action -> { expires_now if current_user || current_customer } @@ -51,22 +51,6 @@ def add_user_info_to_bugsnag(notif) end end - def current_customer_session - @current_customer_session ||= CustomerSession.find - end - - def current_customer - @current_customer ||= current_customer_session && current_customer_session.record - end - - def current_user_session - @current_user_session ||= UserSession.find - end - - def current_user - @current_user ||= current_user_session && current_user_session.record - end - def user_for_paper_trail current_user.try(:id) end @@ -231,4 +215,42 @@ def trusted_sites return true if request.headers[custom_header] == site end end + + def assign_currents + Current.user = current_user + Current.customer = current_customer + end + + # Devise SignIn callback + def after_sign_in_path_for(resource_or_scope) + session[:has_an_open_shift] = current_user.has_stale_shift? + current_user + if @user_session.record.has_stale_shift? + [ + edit_shift_url(@user_session.record.stale_shift), + notice: t('view.shifts.edit_stale') + ] + else + [prints_url, notice: t('view.user_sessions.correctly_created')] + end + + end + + # Devise SignOut callback + def after_sign_out_path_for(resource_or_scope) + if resource_or_scope == :user + new_user_session_path + elsif resource_or_scope == :admin + new_admin_session_path + else + root_path + end + if params[:close_shift] + if params[:as_operator] + current_user.last_open_shift_as_operator! + end + + current_user_session.close_shift! + end + end end diff --git a/app/controllers/customers/confirmations_controller.rb b/app/controllers/customers/confirmations_controller.rb new file mode 100644 index 00000000..ef7b210f --- /dev/null +++ b/app/controllers/customers/confirmations_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Customers::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/customers/omniauth_callbacks_controller.rb b/app/controllers/customers/omniauth_callbacks_controller.rb new file mode 100644 index 00000000..efc3aa4d --- /dev/null +++ b/app/controllers/customers/omniauth_callbacks_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Customers::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/plataformatec/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/customers/passwords_controller.rb b/app/controllers/customers/passwords_controller.rb new file mode 100644 index 00000000..55b7a299 --- /dev/null +++ b/app/controllers/customers/passwords_controller.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class Customers::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/customers/registrations_controller.rb b/app/controllers/customers/registrations_controller.rb new file mode 100644 index 00000000..3ac9dd47 --- /dev/null +++ b/app/controllers/customers/registrations_controller.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +class Customers::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/customers/sessions_controller.rb b/app/controllers/customers/sessions_controller.rb new file mode 100644 index 00000000..ab0be3cb --- /dev/null +++ b/app/controllers/customers/sessions_controller.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class Customers::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/customers/unlocks_controller.rb b/app/controllers/customers/unlocks_controller.rb new file mode 100644 index 00000000..35850ff2 --- /dev/null +++ b/app/controllers/customers/unlocks_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Customers::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/password_resets_controller.rb b/app/controllers/password_resets_controller.rb index d9c2598b..02e302f2 100644 --- a/app/controllers/password_resets_controller.rb +++ b/app/controllers/password_resets_controller.rb @@ -24,17 +24,17 @@ def create # GET /password_resets/token/edit def edit @title = t('view.password_resets.edit_title') - @customer = Customer.find_using_perishable_token( - params[:token], TOKEN_VALIDITY - ) + # @customer = Customer.find_using_perishable_token( + # params[:token], TOKEN_VALIDITY + # ) end # PUT /password_resets/token def update @title = t('view.password_resets.edit_title') - @customer = Customer.find_using_perishable_token( - params[:token], TOKEN_VALIDITY - ) + # @customer = Customer.find_using_perishable_token( + # params[:token], TOKEN_VALIDITY + # ) respond_to do |format| if @customer.try(:update, customer_params) diff --git a/app/controllers/user_sessions_controller.rb b/app/controllers/user_sessions_controller.rb deleted file mode 100644 index 6b67e5a6..00000000 --- a/app/controllers/user_sessions_controller.rb +++ /dev/null @@ -1,67 +0,0 @@ -class UserSessionsController < ApplicationController - before_action :require_no_user, only: [:new, :create] - before_action :require_user, only: :destroy - - - # GET /user_sessions/new - # GET /user_sessions/new.json - def new - @title = t 'view.user_sessions.new_title' - @user_session = UserSession.new - end - - def create - @title = t 'view.user_sessions.new_title' - @user_session = UserSession.new( - params.require(:user_session).permit(:username, :password) - ) - - respond_to do |format| - if @user_session.save - session[:has_an_open_shift] = current_user.has_stale_shift? - - format.html { redirect_back_or_default *initial_url_and_options } - format.json { render json: @user_session, status: :created, location: initial_url } - else - format.html { render action: 'new' } - format.json { render json: @user_session.errors, status: :unprocessable_entity } - end - end - end - - def destroy - if params[:close_shift] - if params[:as_operator] - current_user.last_open_shift_as_operator! - end - - current_user_session.close_shift! - end - - record = current_user_session.record - record.reset_persistence_token # ensure the session is over - current_user_session.destroy - - if Rails.env.test? - (Capybara.page.driver.remove_cookie('user_credentials') rescue nil) - end - - respond_to do |format| - format.html { redirect_to(new_user_session_url, notice: t('view.user_sessions.correctly_destroyed')) } - format.json { head :ok } - end - end - - private - - def initial_url_and_options - if @user_session.record.has_stale_shift? - [ - edit_shift_url(@user_session.record.stale_shift), - notice: t('view.shifts.edit_stale') - ] - else - [prints_url, notice: t('view.user_sessions.correctly_created')] - end - end -end diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb new file mode 100644 index 00000000..3d1e2e5a --- /dev/null +++ b/app/controllers/users/sessions_controller.rb @@ -0,0 +1,12 @@ +class Users::SessionsController < Devise::SessionsController + before_action :require_no_user, only: [:new, :create] + before_action :require_user, only: :destroy + + before_action :set_title + + private + + def set_title + @title = t("view.user_sessions.#{action_name}_title") + end +end diff --git a/app/models/current.rb b/app/models/current.rb new file mode 100644 index 00000000..fca8cee5 --- /dev/null +++ b/app/models/current.rb @@ -0,0 +1,20 @@ +class Current # < ActiveSupport::CurrentAttributes + # attribute :user, :customer + # Temporal CurrentAttributes + + def self.user + ::RequestStore.read('user') + end + + def self.user=(value) + ::RequestStore.write('user', value) + end + + def self.customer + ::RequestStore.read('customer') + end + + def self.customer=(value) + ::RequestStore.write('customer', value) + end +end diff --git a/app/models/customer.rb b/app/models/customer.rb index ba071fa6..b43fd8a8 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -1,14 +1,16 @@ class Customer < ApplicationModel - has_paper_trail ignore: [:perishable_token] + has_paper_trail - acts_as_authentic do |c| - c.maintain_sessions = false - c.validates_uniqueness_of_email_field_options = { case_sensitive: false } - c.validates_length_of_email_field_options = { maximum: 255 } - c.merge_validates_length_of_password_field_options({ minimum: 4 }) + devise :database_authenticatable, :recoverable, :trackable, :validatable, :encryptable - c.crypto_provider = Authlogic::CryptoProviders::Sha512 - end + # acts_as_authentic do |c| + # c.maintain_sessions = false + # c.validates_uniqueness_of_email_field_options = { case_sensitive: false } + # c.validates_length_of_email_field_options = { maximum: 255 } + # c.merge_validates_length_of_password_field_options({ minimum: 4 }) + + # c.crypto_provider = Authlogic::CryptoProviders::Sha512 + # end KINDS = { normal: 'n', diff --git a/app/models/customer_session.rb b/app/models/customer_session.rb deleted file mode 100644 index 3630deff..00000000 --- a/app/models/customer_session.rb +++ /dev/null @@ -1,3 +0,0 @@ -class CustomerSession < Authlogic::Session::Base - find_by_login_method :find_by_activated_email -end diff --git a/app/models/print.rb b/app/models/print.rb index 63209999..75c3b9c2 100644 --- a/app/models/print.rb +++ b/app/models/print.rb @@ -72,8 +72,9 @@ class Print < ApplicationModel def initialize(attributes = nil) super(attributes) - self.user = UserSession.find.try(:user) || user rescue user + self.user = Current.user || user rescue user self.status ||= STATUS[:pending_payment] + self.pay_later! if [1, '1', true].include?(pay_later) case @@ -144,7 +145,7 @@ def mark_order_as_completed end def revoke! - return unless UserSession.find.try(:record).try(:admin) + return unless Current.user.try(:admin) Print.transaction do begin diff --git a/app/models/user.rb b/app/models/user.rb index f83e310c..8b66e790 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,12 +1,15 @@ class User < ApplicationModel - has_paper_trail except: [:persistence_token, :updated_at, :lock_version] + has_paper_trail except: [:updated_at, :lock_version] mount_uploader :avatar, AvatarUploader, mount_on: :avatar_file_name - acts_as_authentic do |c| - c.maintain_sessions = false - c.crypto_provider = Authlogic::CryptoProviders::Sha512 - c.merge_validates_length_of_password_field_options({ minimum: 4 }) - end + devise :database_authenticatable, :recoverable, :trackable, :validatable, :encryptable + + + # acts_as_authentic do |c| + # c.maintain_sessions = false + # c.crypto_provider = Authlogic::CryptoProviders::Sha512 + # c.merge_validates_length_of_password_field_options({ minimum: 4 }) + # end # Scopes scope :actives, -> { where(enable: true) } diff --git a/app/models/user_session.rb b/app/models/user_session.rb index 73d039ea..106ef52f 100644 --- a/app/models/user_session.rb +++ b/app/models/user_session.rb @@ -1,13 +1,13 @@ -class UserSession < Authlogic::Session::Base - find_by_login_method :find_by_username_or_email +class UserSession #< Authlogic::Session::Base + # find_by_login_method :find_by_username_or_email - after_save :create_shift + # after_save :create_shift - def create_shift - record.start_shift! unless record.has_pending_shift? || record.not_shifted - end + # def create_shift + # record.start_shift! unless record.has_pending_shift? || record.not_shifted + # end - def close_shift! - fail 'Unclosed shifts!' unless record.close_pending_shifts! - end + # def close_shift! + # fail 'Unclosed shifts!' unless record.close_pending_shifts! + # end end diff --git a/app/views/customers/confirmations/new.html.erb b/app/views/customers/confirmations/new.html.erb new file mode 100644 index 00000000..496c56b2 --- /dev/null +++ b/app/views/customers/confirmations/new.html.erb @@ -0,0 +1,20 @@ +

Resend confirmation instructions

+ +<%= simple_form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> + <%= f.error_notification %> + <%= f.full_error :confirmation_token %> + +
+ <%= f.input :email, + required: true, + autofocus: true, + value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email), + input_html: { autocomplete: "email" } %> +
+ +
+ <%= f.button :submit, "Resend confirmation instructions" %> +
+<% end %> + +<%= render "customers/shared/links" %> diff --git a/app/views/customers/mailer/confirmation_instructions.html.erb b/app/views/customers/mailer/confirmation_instructions.html.erb new file mode 100644 index 00000000..dc55f64f --- /dev/null +++ b/app/views/customers/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/customers/mailer/email_changed.html.erb b/app/views/customers/mailer/email_changed.html.erb new file mode 100644 index 00000000..32f4ba80 --- /dev/null +++ b/app/views/customers/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/customers/mailer/password_change.html.erb b/app/views/customers/mailer/password_change.html.erb new file mode 100644 index 00000000..b41daf47 --- /dev/null +++ b/app/views/customers/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/customers/mailer/reset_password_instructions.html.erb b/app/views/customers/mailer/reset_password_instructions.html.erb new file mode 100644 index 00000000..f667dc12 --- /dev/null +++ b/app/views/customers/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/customers/mailer/unlock_instructions.html.erb b/app/views/customers/mailer/unlock_instructions.html.erb new file mode 100644 index 00000000..41e148bf --- /dev/null +++ b/app/views/customers/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/customers/passwords/edit.html.erb b/app/views/customers/passwords/edit.html.erb new file mode 100644 index 00000000..2b551767 --- /dev/null +++ b/app/views/customers/passwords/edit.html.erb @@ -0,0 +1,24 @@ +

Change your password

+ +<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> + <%= f.error_notification %> + + <%= f.input :reset_password_token, as: :hidden %> + <%= f.full_error :reset_password_token %> + +
+ <%= f.input :password, + label: "New password", + required: true, + autofocus: true, + hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length), + input_html: { autocomplete: "new-password" } %> + <%= f.input :password_confirmation, label: "Confirm your new password", required: true %> +
+ +
+ <%= f.button :submit, "Change my password" %> +
+<% end %> + +<%= render "customers/shared/links" %> diff --git a/app/views/customers/passwords/new.html.erb b/app/views/customers/passwords/new.html.erb new file mode 100644 index 00000000..f82ab54a --- /dev/null +++ b/app/views/customers/passwords/new.html.erb @@ -0,0 +1,18 @@ +

Forgot your password?

+ +<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :email, + required: true, + autofocus: true, + input_html: { autocomplete: "email" } %> +
+ +
+ <%= f.button :submit, "Send me reset password instructions" %> +
+<% end %> + +<%= render "customers/shared/links" %> diff --git a/app/views/customers/registrations/edit.html.erb b/app/views/customers/registrations/edit.html.erb new file mode 100644 index 00000000..54fbc6c3 --- /dev/null +++ b/app/views/customers/registrations/edit.html.erb @@ -0,0 +1,35 @@ +

Edit <%= resource_name.to_s.humanize %>

+ +<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :email, required: true, autofocus: true %> + + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> +

Currently waiting confirmation for: <%= resource.unconfirmed_email %>

+ <% end %> + + <%= f.input :password, + hint: "leave it blank if you don't want to change it", + required: false + input_html: { autocomplete: "new-password" } %> + <%= f.input :password_confirmation, + required: false, + input_html: { autocomplete: "new-password" } %> + <%= f.input :current_password, + hint: "we need your current password to confirm your changes", + required: true, + input_html: { autocomplete: "current-password" } %> +
+ +
+ <%= f.button :submit, "Update" %> +
+<% end %> + +

Cancel my account

+ +

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

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

Sign up

+ +<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :email, + required: true, + autofocus: true , + input_html: { autocomplete: "email" }%> + <%= f.input :password, + required: true, + hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length), + input_html: { autocomplete: "new-password" } %> + <%= f.input :password_confirmation, + required: true, + input_html: { autocomplete: "new-password" } %> +
+ +
+ <%= f.button :submit, "Sign up" %> +
+<% end %> + +<%= render "customers/shared/links" %> diff --git a/app/views/customers/sessions/new.html.erb b/app/views/customers/sessions/new.html.erb new file mode 100644 index 00000000..4f9eb995 --- /dev/null +++ b/app/views/customers/sessions/new.html.erb @@ -0,0 +1,20 @@ +

Log in

+ +<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +
+ <%= f.input :email, + required: false, + autofocus: true, + input_html: { autocomplete: "email" } %> + <%= f.input :password, + required: false, + input_html: { autocomplete: "current-password" } %> + <%= f.input :remember_me, as: :boolean if devise_mapping.rememberable? %> +
+ +
+ <%= f.button :submit, "Log in" %> +
+<% end %> + +<%= render "customers/shared/links" %> diff --git a/app/views/customers/shared/_links.html.erb b/app/views/customers/shared/_links.html.erb new file mode 100644 index 00000000..e6a3e419 --- /dev/null +++ b/app/views/customers/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/customers/unlocks/new.html.erb b/app/views/customers/unlocks/new.html.erb new file mode 100644 index 00000000..37f63986 --- /dev/null +++ b/app/views/customers/unlocks/new.html.erb @@ -0,0 +1,19 @@ +

Resend unlock instructions

+ +<%= simple_form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> + <%= f.error_notification %> + <%= f.full_error :unlock_token %> + +
+ <%= f.input :email, + required: true, + autofocus: true, + input_html: { autocomplete: "email" } %> +
+ +
+ <%= f.button :submit, "Resend unlock instructions" %> +
+<% end %> + +<%= render "customers/shared/links" %> diff --git a/app/views/devise/confirmations/new.html.erb b/app/views/devise/confirmations/new.html.erb new file mode 100644 index 00000000..949b1727 --- /dev/null +++ b/app/views/devise/confirmations/new.html.erb @@ -0,0 +1,16 @@ +

Resend confirmation instructions

+ +<%= simple_form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> + <%= f.error_notification %> + <%= f.full_error :confirmation_token %> + +
+ <%= f.input :email, required: true, autofocus: true %> +
+ +
+ <%= f.button :submit, "Resend confirmation instructions" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/mailer/confirmation_instructions.html.erb b/app/views/devise/mailer/confirmation_instructions.html.erb new file mode 100644 index 00000000..dc55f64f --- /dev/null +++ b/app/views/devise/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/devise/mailer/password_change.html.erb b/app/views/devise/mailer/password_change.html.erb new file mode 100644 index 00000000..b41daf47 --- /dev/null +++ b/app/views/devise/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/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb new file mode 100644 index 00000000..f667dc12 --- /dev/null +++ b/app/views/devise/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/devise/mailer/unlock_instructions.html.erb b/app/views/devise/mailer/unlock_instructions.html.erb new file mode 100644 index 00000000..41e148bf --- /dev/null +++ b/app/views/devise/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/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb new file mode 100644 index 00000000..a938930b --- /dev/null +++ b/app/views/devise/passwords/edit.html.erb @@ -0,0 +1,19 @@ +

Change your password

+ +<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> + <%= f.error_notification %> + + <%= f.input :reset_password_token, as: :hidden %> + <%= f.full_error :reset_password_token %> + +
+ <%= f.input :password, label: "New password", required: true, autofocus: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %> + <%= f.input :password_confirmation, label: "Confirm your new password", required: true %> +
+ +
+ <%= f.button :submit, "Change my password" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb new file mode 100644 index 00000000..d1503e76 --- /dev/null +++ b/app/views/devise/passwords/new.html.erb @@ -0,0 +1,15 @@ +

Forgot your password?

+ +<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :email, required: true, autofocus: true %> +
+ +
+ <%= f.button :submit, "Send me reset password instructions" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb new file mode 100644 index 00000000..5db350b5 --- /dev/null +++ b/app/views/devise/registrations/edit.html.erb @@ -0,0 +1,27 @@ +

Edit <%= resource_name.to_s.humanize %>

+ +<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :email, required: true, autofocus: true %> + + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> +

Currently waiting confirmation for: <%= resource.unconfirmed_email %>

+ <% end %> + + <%= f.input :password, autocomplete: "off", hint: "leave it blank if you don't want to change it", required: false %> + <%= f.input :password_confirmation, required: false %> + <%= f.input :current_password, hint: "we need your current password to confirm your changes", required: true %> +
+ +
+ <%= f.button :submit, "Update" %> +
+<% end %> + +

Cancel my account

+ +

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

+ +<%= link_to "Back", :back %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb new file mode 100644 index 00000000..34b4279e --- /dev/null +++ b/app/views/devise/registrations/new.html.erb @@ -0,0 +1,17 @@ +

Sign up

+ +<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :email, required: true, autofocus: true %> + <%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %> + <%= f.input :password_confirmation, required: true %> +
+ +
+ <%= f.button :submit, "Sign up" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb new file mode 100644 index 00000000..31f8a4d4 --- /dev/null +++ b/app/views/devise/sessions/new.html.erb @@ -0,0 +1,15 @@ +

Log in

+ +<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +
+ <%= f.input :email, required: false, autofocus: true %> + <%= f.input :password, required: false %> + <%= f.input :remember_me, as: :boolean if devise_mapping.rememberable? %> +
+ +
+ <%= f.button :submit, "Log in" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb new file mode 100644 index 00000000..e6a3e419 --- /dev/null +++ b/app/views/devise/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/devise/unlocks/new.html.erb b/app/views/devise/unlocks/new.html.erb new file mode 100644 index 00000000..788f62e9 --- /dev/null +++ b/app/views/devise/unlocks/new.html.erb @@ -0,0 +1,16 @@ +

Resend unlock instructions

+ +<%= simple_form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> + <%= f.error_notification %> + <%= f.full_error :unlock_token %> + +
+ <%= f.input :email, required: true, autofocus: true %> +
+ +
+ <%= f.button :submit, "Resend unlock instructions" %> +
+<% end %> + +<%= render "devise/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 00000000..76a5dcd0 --- /dev/null +++ b/app/views/users/sessions/new.html.erb @@ -0,0 +1,22 @@ +
+
+
+ <%= simple_form_for(resource, as: resource_name, url: session_path(resource_name), defaults: { required: false }) do |f| %> +
+ <%= f.input :username, input_html: { autocomplete: 'off', autofocus: true, class: 'span3' } %> + <%= f.input :password, input_html: { class: 'span3' } %> +
+
+ <%= f.button :submit, t('view.user_sessions.login'), class: 'btn btn-primary' %> +
+ <% end %> +
+
+
+ +<% if resource.errors.any? %> + +<% end %> diff --git a/config/initializers/carrierwave_backgrounder.rb b/config/initializers/carrierwave_backgrounder.rb index 9da6264a..7244f05d 100644 --- a/config/initializers/carrierwave_backgrounder.rb +++ b/config/initializers/carrierwave_backgrounder.rb @@ -1,8 +1,3 @@ CarrierWave::Backgrounder.configure do |c| - # c.backend :resque, queue: :carrierwave c.backend :sidekiq, queue: :carrierwave - # c.backend :girl_friday, queue: :carrierwave - # c.backend :sucker_punch, queue: :carrierwave - # c.backend :qu, queue: :carrierwave - # c.backend :qc end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb new file mode 100644 index 00000000..95979ccd --- /dev/null +++ b/config/initializers/devise.rb @@ -0,0 +1,272 @@ +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 = 'bc2669e02c8d691af8d616988029515f9ece4ca647ea8831323466d13dc146368d6ea5cd60b9a5dc4116673c70bc0169406bf5c365125db76b7c813a33533aac' + + # ==> 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. 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 11. If + # using other algorithms, it sets how many times you want the password to be hashed. + # + # 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 : 20 + + # Set up a pepper to generate the hashed password. + # config.pepper = '93b2d1e623477421887577755a5603c40159c1451bf25ddecd14cb5f31a934ff2a841617dc828fb44e84247be3cc12969d6d2834103c20553b9e01446b7e4e0c' + + # 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. 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 = :authlogic_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 = true + + # 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' +end diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml new file mode 100644 index 00000000..bd4c3ebc --- /dev/null +++ b/config/locales/devise.en.yml @@ -0,0 +1,62 @@ +# Additional translations at https://github.com/plataformatec/devise/wiki/I18n + +en: + devise: + confirmations: + 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" + 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 confirm link to confirm your new email address." + updated: "Your account has been updated successfully." + 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/customer/customer_session.rb b/config/routes/customer/customer_session.rb index 69d1e8c0..0a17a742 100644 --- a/config/routes/customer/customer_session.rb +++ b/config/routes/customer/customer_session.rb @@ -1,3 +1,6 @@ -resources :customer_sessions, only: [:new, :create] do - delete :destroy, on: :collection -end +# resources :customer_sessions, only: [:new, :create] do +# delete :destroy, on: :collection +# end +devise_for :customers, path: 'customers', controllers: { + sessions: 'customers/sessions' # poner todos los demas +} diff --git a/config/routes/user/user_session.rb b/config/routes/user/user_session.rb index 010adbe8..97fd0982 100644 --- a/config/routes/user/user_session.rb +++ b/config/routes/user/user_session.rb @@ -1,3 +1,4 @@ -resources :user_sessions, only: [:new, :create] do - delete :destroy, on: :collection -end +# resources :user_sessions, only: [:new, :create] do +# delete :destroy, on: :collection +# end +devise_for :users, path: 'users', controllers: { sessions: 'users/sessions' } diff --git a/db/migrate/20170304192533_authlogic_users_to_devise.rb b/db/migrate/20170304192533_authlogic_users_to_devise.rb new file mode 100644 index 00000000..f9df841e --- /dev/null +++ b/db/migrate/20170304192533_authlogic_users_to_devise.rb @@ -0,0 +1,49 @@ +class AuthlogicUsersToDevise < ActiveRecord::Migration[5.1] + def up + add_column :users, :confirmation_token, :string, limit: 255 + add_column :users, :confirmed_at, :timestamp + add_column :users, :confirmation_sent_at, :timestamp + add_column :users, :unconfirmed_email, :string + + execute "UPDATE users SET confirmed_at = created_at, confirmation_sent_at = created_at" + + add_column :users, :reset_password_token, :string, limit: 255 + add_column :users, :reset_password_sent_at, :timestamp + add_column :users, :remember_token, :string, limit: 255 + add_column :users, :remember_created_at, :timestamp + add_column :users, :unlock_token, :string, limit: 255 + add_column :users, :locked_at, :timestamp + add_column :users, :sign_in_count, :integer + + rename_column :users, :crypted_password, :encrypted_password + + remove_column :users, :persistence_token + + add_index :users, :confirmation_token, unique: true + add_index :users, :reset_password_token, unique: true + add_index :users, :unlock_token, unique: true + end + + def down + remove_column :users, :confirmation_token + remove_column :users, :confirmed_at + remove_column :users, :confirmation_sent_at + remove_column :users, :unconfirmed_email + remove_column :users, :reset_password_token + remove_column :users, :reset_password_sent_at + remove_column :users, :remember_token + remove_column :users, :remember_created_at + remove_column :users, :unlock_token + remove_column :users, :locked_at + + rename_column :users, :encrypted_password, :crypted_password + rename_column :users, :sign_in_count, :login_count + + add_column :users, :persistence_token, :string + add_column :users, :single_access_token, :string + + remove_index :users, :confirmation_token + remove_index :users, :reset_password_token + remove_index :users, :unlock_token + end +end diff --git a/db/migrate/20170304195401_authlogic_customer_to_devise.rb b/db/migrate/20170304195401_authlogic_customer_to_devise.rb new file mode 100644 index 00000000..0ede28e4 --- /dev/null +++ b/db/migrate/20170304195401_authlogic_customer_to_devise.rb @@ -0,0 +1,51 @@ +class AuthlogicCustomerToDevise < ActiveRecord::Migration[5.1] + def up + add_column :customers, :confirmation_token, :string, limit: 255 + add_column :customers, :confirmed_at, :timestamp + add_column :customers, :confirmation_sent_at, :timestamp + add_column :customers, :unconfirmed_email, :string + + execute "UPDATE customers SET confirmed_at = created_at, confirmation_sent_at = created_at" + + add_column :customers, :reset_password_token, :string, limit: 255 + add_column :customers, :reset_password_sent_at, :timestamp + add_column :customers, :remember_token, :string, limit: 255 + add_column :customers, :remember_created_at, :timestamp + add_column :customers, :unlock_token, :string, limit: 255 + add_column :customers, :locked_at, :timestamp + add_column :customers, :sign_in_count, :integer + + rename_column :customers, :crypted_password, :encrypted_password + + remove_column :customers, :persistence_token + remove_column :customers, :perishable_token + + add_index :customers, :confirmation_token, unique: true + add_index :customers, :reset_password_token, unique: true + add_index :customers, :unlock_token, unique: true + end + + def down + # remove_column :customers, :confirmation_token + remove_column :customers, :confirmed_at + remove_column :customers, :confirmation_sent_at + remove_column :customers, :unconfirmed_email + remove_column :customers, :reset_password_token + remove_column :customers, :reset_password_sent_at + remove_column :customers, :remember_token + remove_column :customers, :remember_created_at + remove_column :customers, :unlock_token + remove_column :customers, :locked_at + + rename_column :customers, :encrypted_password, :crypted_password + rename_column :customers, :sign_in_count, :login_count + + add_column :customers, :persistence_token, :string + add_column :customers, :perishable_token, :string + add_column :customers, :single_access_token, :string + + # remove_index :customers, :confirmation_token + # remove_index :customers, :reset_password_token + # remove_index :customers, :unlock_token + end +end diff --git a/db/schema.rb b/db/schema.rb index 7ab98d19..e21c332c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -66,19 +66,30 @@ t.datetime "updated_at" t.boolean "bonus_without_expiration", default: false, null: false t.string "email" - t.string "crypted_password" + t.string "encrypted_password" t.string "password_salt" - t.string "persistence_token" - t.string "perishable_token" t.boolean "enable", default: true t.string "kind", limit: 1, default: "n", null: false t.integer "group_id" + t.string "confirmation_token", limit: 255 + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" + t.string "unconfirmed_email" + t.string "reset_password_token", limit: 255 + t.datetime "reset_password_sent_at" + t.string "remember_token", limit: 255 + t.datetime "remember_created_at" + t.string "unlock_token", limit: 255 + t.datetime "locked_at" + t.integer "sign_in_count" t.string "rfid" t.index "to_tsvector('spanish'::regconfig, (((((COALESCE(identification, ''::character varying))::text || ' '::text) || (COALESCE(name, ''::character varying))::text) || ' '::text) || (COALESCE(lastname, ''::character varying))::text))", name: "index_customers_on_identification_name_and_lastname_ts", using: :gin + t.index ["confirmation_token"], name: "index_customers_on_confirmation_token", unique: true t.index ["email"], name: "index_customers_on_email", unique: true t.index ["enable"], name: "index_customers_on_enable" t.index ["identification"], name: "index_customers_on_identification", unique: true - t.index ["perishable_token"], name: "index_customers_on_perishable_token" + t.index ["reset_password_token"], name: "index_customers_on_reset_password_token", unique: true + t.index ["unlock_token"], name: "index_customers_on_unlock_token", unique: true end create_table "customers_groups", id: :serial, force: :cascade do |t| @@ -314,9 +325,8 @@ t.string "language", null: false t.string "email", null: false t.string "username", null: false - t.string "crypted_password", null: false + t.string "encrypted_password", null: false t.string "password_salt", null: false - t.string "persistence_token", null: false t.boolean "admin", default: false, null: false t.boolean "enable" t.integer "lock_version", default: 0 @@ -329,7 +339,21 @@ t.datetime "avatar_updated_at" t.integer "lines_per_page" t.boolean "not_shifted", default: false + t.string "confirmation_token", limit: 255 + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" + t.string "unconfirmed_email" + t.string "reset_password_token", limit: 255 + t.datetime "reset_password_sent_at" + t.string "remember_token", limit: 255 + t.datetime "remember_created_at" + t.string "unlock_token", limit: 255 + t.datetime "locked_at" + t.integer "sign_in_count" + t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["email"], name: "index_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true t.index ["username"], name: "index_users_on_username", unique: true end diff --git a/lib/admin_constraint.rb b/lib/admin_constraint.rb index 61d25036..443e3fcd 100644 --- a/lib/admin_constraint.rb +++ b/lib/admin_constraint.rb @@ -3,7 +3,7 @@ def matches?(request) credentials = request.cookie_jar['user_credentials'] Rails.logger.info("Someone wants to loggin #{credentials}") return false if credentials.blank? - user = User.find_by_persistence_token(credentials.split(':')[0]) - user && user.admin? && user.not_shifted + # user = User.find_by_persistence_token(credentials.split(':')[0]) + # user && user.admin? && user.not_shifted end end diff --git a/test/controllers/application_controller_test.rb b/test/controllers/application_controller_test.rb index cc92d00b..ecc83c7d 100644 --- a/test/controllers/application_controller_test.rb +++ b/test/controllers/application_controller_test.rb @@ -28,7 +28,7 @@ def setup test 'current user session' do assert_nil @controller.send(:current_user_session) - UserSession.create(@operator) + sign_in(@operator) assert_not_nil @controller.send(:current_user_session) end @@ -36,7 +36,7 @@ def setup test 'current user' do assert_nil @controller.send(:current_user) - UserSession.create(@operator) + sign_in(@operator) assert_not_nil @controller.send(:current_user) assert_equal @operator.id, @controller.send(:current_user).id @@ -74,7 +74,7 @@ def setup assert_equal I18n.t('messages.must_be_logged_in'), @controller.send(:flash)[:notice] - UserSession.create(@operator) + sign_in(@operator) assert_not_equal false, @controller.send(:require_user) end @@ -82,7 +82,7 @@ def setup test 'require no user' do assert @controller.send(:require_no_user) - UserSession.create(@operator) + sign_in(@operator) assert !@controller.send(:require_no_user) assert_redirected_to prints_url @@ -96,7 +96,7 @@ def setup assert_equal I18n.t('messages.must_be_logged_in'), @controller.send(:flash)[:notice] - UserSession.create(@operator) + sign_in(@operator) assert_not_equal false, @controller.send(:require_customer_or_user) end @@ -107,7 +107,7 @@ def setup assert_not_nil @controller.send(:check_logged_in) assert_redirected_to root_url - UserSession.create(@operator) + sign_in(@operator) assert_nil @controller.send(:check_logged_in) assert_not_nil @controller.send(:current_user) @@ -145,7 +145,7 @@ def setup assert_equal I18n.t('messages.must_be_logged_in'), @controller.send(:flash)[:notice] - UserSession.create(@operator) + sign_in(@operator) assert_not_equal false, @controller.send(:require_no_customer_or_user) end @@ -163,14 +163,14 @@ def setup test 'require no customer or admin with user' do @operator.update(admin: false) - UserSession.create(@operator) + sign_in(@operator) assert @controller.send(:require_no_customer_or_user) assert_response :success end test 'require admin user with admin user' do - UserSession.create(@operator) + sign_in(@operator) assert_not_equal false, @controller.send(:require_admin_user) end @@ -178,7 +178,7 @@ def setup test 'require admin with a non admin user' do @operator.update(admin: false) - UserSession.create(@operator) + sign_in(@operator) assert_equal false, @controller.send(:require_admin_user) assert_redirected_to prints_url @@ -209,7 +209,7 @@ def setup @operator.update(admin: false, not_shifted: false) @operator.close_pending_shifts! - UserSession.create(@operator) + sign_in(@operator) @controller.send(:session)[:has_an_open_shift] = true @@ -230,7 +230,7 @@ def setup @operator.update(not_shifted: true) assert_no_difference 'Shift.count' do - UserSession.create(@operator) + sign_in(@operator) @controller.send(:session)[:has_an_open_shift] = true assert_nil @controller.send(:run_shift_tasks) diff --git a/test/controllers/articles_controller_test.rb b/test/controllers/articles_controller_test.rb index 1f48b295..14b323b2 100644 --- a/test/controllers/articles_controller_test.rb +++ b/test/controllers/articles_controller_test.rb @@ -5,7 +5,7 @@ class ArticlesControllerTest < ActionController::TestCase @article = articles(:binding) @operator = users(:operator) - UserSession.create(@operator) + sign_in(@operator) end test 'should get index' do diff --git a/test/controllers/bonuses_controller_test.rb b/test/controllers/bonuses_controller_test.rb index 4e330fe8..adacd567 100644 --- a/test/controllers/bonuses_controller_test.rb +++ b/test/controllers/bonuses_controller_test.rb @@ -2,7 +2,7 @@ class BonusesControllerTest < ActionController::TestCase def setup - UserSession.create(users(:operator)) + sign_in(users(:operator)) end test 'should get index' do diff --git a/test/controllers/customers_controller_test.rb b/test/controllers/customers_controller_test.rb index 6cf343f1..0d83bdfb 100644 --- a/test/controllers/customers_controller_test.rb +++ b/test/controllers/customers_controller_test.rb @@ -7,7 +7,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should get index' do - UserSession.create(@operator) + sign_in(@operator) get :index assert_response :success @@ -17,7 +17,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should get filtered index' do - UserSession.create(@operator) + sign_in(@operator) get :index, params: { q: 'Anakin|Darth' } assert_response :success @@ -30,7 +30,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should get index with debt customers' do - UserSession.create(@operator) + sign_in(@operator) get :index, params: { status: 'with_debt' } assert_response :success @@ -42,7 +42,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should get new' do - UserSession.create(@operator) + sign_in(@operator) get :new assert_response :success @@ -62,7 +62,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should create simple customer' do - UserSession.create(@operator) + sign_in(@operator) assert_difference ['Customer.unscoped.count'] do assert_difference 'PaperTrail::Version.count' do @@ -86,7 +86,7 @@ class CustomersControllerTest < ActionController::TestCase test 'should create customer' do User.where(id: @operator.id).update_all(not_shifted: true) - UserSession.create(@operator) + sign_in(@operator) assert_difference ['Customer.unscoped.count', 'Bonus.count'] do assert_difference 'PaperTrail::Version.count', 2 do @@ -169,7 +169,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should show customer' do - UserSession.create(@operator) + sign_in(@operator) get :show, params: { id: @customer.to_param } assert_response :success @@ -179,7 +179,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should get edit' do - UserSession.create(@operator) + sign_in(@operator) get :edit, params: { id: @customer.to_param } assert_response :success @@ -190,7 +190,7 @@ class CustomersControllerTest < ActionController::TestCase test 'should update customer' do User.where(id: @operator.id).update_all(not_shifted: true) - UserSession.create(@operator) + sign_in(@operator) assert_no_difference 'Customer.count' do assert_difference 'Bonus.count' do @@ -215,7 +215,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should update customer deposits' do - UserSession.create(@operator) + sign_in(@operator) assert_no_difference 'Customer.count' do assert_difference 'Deposit.count' do @@ -238,7 +238,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should destroy customer' do - UserSession.create(@operator) + sign_in(@operator) assert_difference('Customer.count', -1) do delete :destroy, params: { id: Customer.find(customers(:teacher).id).to_param } @@ -248,7 +248,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should get credit detail' do - UserSession.create(@operator) + sign_in(@operator) get :credit_detail, params: { id: @customer.to_param }, xhr: true @@ -323,7 +323,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should pay off customer debt' do - UserSession.create(@operator) + sign_in(@operator) put :pay_off_debt, params: { id: @customer.to_param }, xhr: true @@ -334,7 +334,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should pay off a customer month debt' do - UserSession.create(@operator) + sign_in(@operator) month = @customer.months_to_pay.last @@ -347,7 +347,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should be able to use customer rfid' do - UserSession.create(@operator) + sign_in(@operator) @customer.update(rfid: '123123') put :use_rfid, params: { id: @customer.to_param, rfid: '123123' }, xhr: true @@ -359,7 +359,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should not be able to use customer rfid' do - UserSession.create(@operator) + sign_in(@operator) @customer.update(rfid: '123123') put :use_rfid, params: { id: @customer.to_param, rfid: '111111' }, xhr: true @@ -370,7 +370,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should assign customer rfid' do - UserSession.create(@operator) + sign_in(@operator) assert_nil @customer.rfid post :assign_rfid, params: { id: @customer.to_param, rfid: '123123' }, xhr: true diff --git a/test/controllers/customers_groups_controller_test.rb b/test/controllers/customers_groups_controller_test.rb index e2b8fcf1..7971a156 100644 --- a/test/controllers/customers_groups_controller_test.rb +++ b/test/controllers/customers_groups_controller_test.rb @@ -3,7 +3,7 @@ class CustomersGroupsControllerTest < ActionController::TestCase setup do @customers_group = customers_groups(:graduate) - UserSession.create users(:operator) + sign_in users(:operator) end test 'should get index' do diff --git a/test/controllers/documents_controller_test.rb b/test/controllers/documents_controller_test.rb index fac9340c..9a207b2c 100644 --- a/test/controllers/documents_controller_test.rb +++ b/test/controllers/documents_controller_test.rb @@ -5,7 +5,7 @@ class DocumentsControllerTest < ActionController::TestCase @document = documents(:math_book) @operator = users(:operator) - UserSession.create(@operator) + sign_in(@operator) prepare_document_files end diff --git a/test/controllers/files_controller_test.rb b/test/controllers/files_controller_test.rb index 3290c4e7..19f9be39 100644 --- a/test/controllers/files_controller_test.rb +++ b/test/controllers/files_controller_test.rb @@ -10,7 +10,7 @@ class FilesControllerTest < ActionController::TestCase end test 'should download avatar' do - UserSession.create(@operator) + sign_in(@operator) get :download, params: { path: drop_private_dir(@operator.avatar.path) } assert_response :success @@ -21,7 +21,7 @@ class FilesControllerTest < ActionController::TestCase end test 'should download document' do - UserSession.create(@operator) + sign_in(@operator) get :download, params: { path: drop_private_dir(@document.file.path) } assert_response :success @@ -32,7 +32,7 @@ class FilesControllerTest < ActionController::TestCase end test 'should not download document' do - UserSession.create(@operator) + sign_in(@operator) file = @document.file.path @@ -45,7 +45,7 @@ class FilesControllerTest < ActionController::TestCase end test 'should download barcode' do - UserSession.create(@operator) + sign_in(@operator) get :download_barcode, params: { code: @document.code } assert_response :success @@ -54,7 +54,7 @@ class FilesControllerTest < ActionController::TestCase end test 'should download barcode of new document' do - UserSession.create(@operator) + sign_in(@operator) get :download_barcode, params: { code: '159321' } assert_response :success @@ -84,7 +84,7 @@ class FilesControllerTest < ActionController::TestCase end test 'should not download avatar' do - UserSession.create(@operator) + sign_in(@operator) file = @operator.avatar.path diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb index c46c2dd2..0915f759 100644 --- a/test/controllers/orders_controller_test.rb +++ b/test/controllers/orders_controller_test.rb @@ -10,7 +10,7 @@ class OrdersControllerTest < ActionController::TestCase test 'should get user index' do @request.host = 'localhost' - UserSession.create(@operator) + sign_in(@operator) get :index, params: { type: 'all' } assert_response :success @@ -25,7 +25,7 @@ class OrdersControllerTest < ActionController::TestCase test 'should get user for print index' do @request.host = 'localhost' - UserSession.create(@operator) + sign_in(@operator) get :index, params: { type: 'print' } assert_response :success @@ -38,7 +38,7 @@ class OrdersControllerTest < ActionController::TestCase test 'should get user filtered index' do @request.host = 'localhost' - UserSession.create(@operator) + sign_in(@operator) get :index, params: { type: 'all', q: 'darth' } assert_response :success @@ -114,7 +114,7 @@ class OrdersControllerTest < ActionController::TestCase test 'should show user order' do @request.host = 'localhost' - UserSession.create(@operator) + sign_in(@operator) get :show, params: { type: 'all', id: @order.to_param } assert_response :success @@ -168,7 +168,7 @@ class OrdersControllerTest < ActionController::TestCase test 'should cancel order as user' do @request.host = 'localhost' - UserSession.create(@operator) + sign_in(@operator) assert_no_difference 'Order.count' do delete :destroy, params: { id: @order.to_param, type: 'all' } diff --git a/test/controllers/payments_controller_test.rb b/test/controllers/payments_controller_test.rb index ef711526..79bc3ede 100644 --- a/test/controllers/payments_controller_test.rb +++ b/test/controllers/payments_controller_test.rb @@ -2,7 +2,7 @@ class PaymentsControllerTest < ActionController::TestCase def setup - UserSession.create(users(:operator)) + sign_in(users(:operator)) end test 'should get index' do diff --git a/test/controllers/print_job_types_controller_test.rb b/test/controllers/print_job_types_controller_test.rb index 273cf744..ba3cca41 100644 --- a/test/controllers/print_job_types_controller_test.rb +++ b/test/controllers/print_job_types_controller_test.rb @@ -4,7 +4,7 @@ class PrintJobTypesControllerTest < ActionController::TestCase setup do @print_job_type = PrintJobType.find print_job_types(:a4).id - UserSession.create(users(:operator)) + sign_in(users(:operator)) end test 'should get index' do diff --git a/test/controllers/prints_controller_test.rb b/test/controllers/prints_controller_test.rb index a4fab44e..9fb84d48 100644 --- a/test/controllers/prints_controller_test.rb +++ b/test/controllers/prints_controller_test.rb @@ -6,7 +6,7 @@ class PrintsControllerTest < ActionController::TestCase @printer = ::CustomCups.pdf_printer @operator = users(:operator) - UserSession.create(@operator) + sign_in(@operator) fail "Can't find a PDF printer to run tests with." unless @printer diff --git a/test/controllers/shift_closures_controller_test.rb b/test/controllers/shift_closures_controller_test.rb index d309f14f..c99615ad 100644 --- a/test/controllers/shift_closures_controller_test.rb +++ b/test/controllers/shift_closures_controller_test.rb @@ -5,7 +5,7 @@ class ShiftClosuresControllerTest < ActionController::TestCase @shift_closure = shift_closures(:first) @operator = users(:operator) - UserSession.create(@operator) + sign_in(@operator) end test "should get index" do diff --git a/test/controllers/shifts_controller_test.rb b/test/controllers/shifts_controller_test.rb index 3a7841c5..319fc3ff 100644 --- a/test/controllers/shifts_controller_test.rb +++ b/test/controllers/shifts_controller_test.rb @@ -4,7 +4,7 @@ class ShiftsControllerTest < ActionController::TestCase setup do @shift = shifts(:current_shift) - UserSession.create(users(:operator)) + sign_in(users(:operator)) end test 'should get index' do diff --git a/test/controllers/stats_controller_test.rb b/test/controllers/stats_controller_test.rb index 0bb95d68..d1ea8b7f 100644 --- a/test/controllers/stats_controller_test.rb +++ b/test/controllers/stats_controller_test.rb @@ -3,7 +3,7 @@ class StatsControllerTest < ActionController::TestCase def setup @controller = StatsController.new - UserSession.create(users(:operator)) + sign_in(users(:operator)) end test 'should get printers stats' do diff --git a/test/controllers/tags_controller_test.rb b/test/controllers/tags_controller_test.rb index 5e5d2157..28d6f3a1 100644 --- a/test/controllers/tags_controller_test.rb +++ b/test/controllers/tags_controller_test.rb @@ -3,7 +3,7 @@ class TagsControllerTest < ActionController::TestCase setup do @tag = tags(:books) - UserSession.create(users(:operator)) + sign_in(users(:operator)) end test 'should get index' do diff --git a/test/controllers/user_sessions_controller_test.rb b/test/controllers/user_sessions_controller_test.rb index 058e1c42..4ba98424 100644 --- a/test/controllers/user_sessions_controller_test.rb +++ b/test/controllers/user_sessions_controller_test.rb @@ -114,7 +114,7 @@ class UserSessionsControllerTest < ActionController::TestCase @operator.close_pending_shifts! assert_difference '@operator.shifts.count' do - UserSession.create(@operator) + sign_in(@operator) end assert_not_nil UserSession.find @@ -132,7 +132,7 @@ class UserSessionsControllerTest < ActionController::TestCase @operator.close_pending_shifts! assert_difference '@operator.shifts.count' do - UserSession.create(@operator) + sign_in(@operator) end assert_not_nil UserSession.find @@ -151,7 +151,7 @@ class UserSessionsControllerTest < ActionController::TestCase test 'should exit whitout close the shift' do @operator.close_pending_shifts! - UserSession.create(@operator) + sign_in(@operator) assert_equal 1, @operator.shifts.pending.size diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 27cc4523..cfd0de5b 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -4,7 +4,7 @@ class UsersControllerTest < ActionController::TestCase setup do @operator = users(:operator) - UserSession.create(@operator) + sign_in(@operator) prepare_avatar_files end diff --git a/test/fixtures/customers.yml b/test/fixtures/customers.yml index 91d8409d..ce532a42 100644 --- a/test/fixtures/customers.yml +++ b/test/fixtures/customers.yml @@ -4,10 +4,8 @@ student: identification: 123 email: student@printhub.com enable: true - password_salt: <%= salt = Authlogic::Random.hex_token %> - crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt('student123' + salt) %> - persistence_token: 6cde0674657a8a313ce952df979de2830309aa4c11ca65805dd00bfdc65dbcc2f5e36718660a1d2e68c1a08c276d996763985d2f06fd3d076eb7bc4d97b1e317 - perishable_token: <%= Authlogic::Random.friendly_token %> + password_salt: <%= salt = hex_token %> + encrypted_password: <%= encrypt('student123', salt) %> free_monthly_bonus: 100.00 bonus_without_expiration: false kind: <%= Customer::KINDS[:reliable] %> @@ -18,10 +16,8 @@ teacher: identification: 321 email: teacher@printhub.com enable: true - password_salt: <%= salt = Authlogic::Random.hex_token %> - crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt('teacher123' + salt) %> - persistence_token: 6cde0674657a8a313ce952df979de2830309aa4c11ca65805dd00bfdc65dbcc2f5e36718660a1d2e68c1a08c276d996763985d2f06fd3d076eb7bc4d97b1e317 - perishable_token: <%= Authlogic::Random.friendly_token %> + password_salt: <%= salt = hex_token %> + encrypted_password: <%= encrypt('teacher123', salt) %> free_monthly_bonus: 10.00 bonus_without_expiration: false kind: <%= Customer::KINDS[:normal] %> @@ -32,10 +28,8 @@ student_without_bonus: identification: 666 email: student_without_bonus@printhub.com enable: true - password_salt: <%= salt = Authlogic::Random.hex_token %> - crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt('student_without_bonus123' + salt) %> - persistence_token: 6cde0674657a8a313ce952df979de2830309aa4c11ca65805dd00bfdc65dbcc2f5e36718660a1d2e68c1a08c276d996763985d2f06fd3d076eb7bc4d97b1e317 - perishable_token: <%= Authlogic::Random.friendly_token %> + password_salt: <%= salt = hex_token %> + encrypted_password: <%= encrypt('student_without_bonus123', salt) %> free_monthly_bonus: 0.00 bonus_without_expiration: false kind: <%= Customer::KINDS[:normal] %> diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 7f40484a..31fc679e 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -6,9 +6,8 @@ operator: default_printer: <%= Cups.show_destinations.select {|p| p =~ /pdf/i}.first %> lines_per_page: 10 username: operator - password_salt: <%= salt = Authlogic::Random.hex_token %> - crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt('operator123' + salt) %> - persistence_token: 6cde0674657a8a313ce952df979de2830309aa4c11ca65805dd00bfdc65dbcc2f5e36718660a1d2e68c1a08c276d996763985d2f06fd3d076eb7bc4d97b1e317 + password_salt: <%= salt = hex_token %> + encrypted_password: <%= encrypt('operator123', salt) %> admin: true enable: true not_shifted: false diff --git a/test/models/print_test.rb b/test/models/print_test.rb index 457f6ba2..a791dd6a 100644 --- a/test/models/print_test.rb +++ b/test/models/print_test.rb @@ -2,6 +2,7 @@ # Clase para probar el modelo "Print" class PrintTest < ActiveSupport::TestCase + # Función para inicializar las variables utilizadas en las pruebas def setup @print = prints(:math_print) @@ -244,7 +245,7 @@ def teardown end test 'create with free credit and paying more in cash' do - UserSession.create(users(:operator)) + Current.user = users(:operator) @customer = customers(:student) Bonus.all.delete_all Deposit.all.delete_all @@ -314,7 +315,7 @@ def teardown end test 'create with free credit' do - UserSession.create(users(:operator)) + Current.user = users(:operator) counts = ['Print.count', 'Payment.count', '::CustomCups.last_job_id(@printer)', 'ArticleLine.count'] @@ -718,7 +719,7 @@ def teardown end test 'revoke' do - UserSession.create(@operator) + Current.user = @operator @article = articles(:binding) assert_difference '@article.reload.stock', 2 do @@ -733,7 +734,7 @@ def teardown test 'can not revoke if is not admin' do @operator.update(admin: false) - UserSession.create(users(:operator)) + Current.user = users(:operator) assert_no_difference('Bonus.count') { assert_nil @print.revoke! } @@ -741,7 +742,8 @@ def teardown end test 'revoke a print paid with credit returns the value to the customer' do - UserSession.create(@operator) + Current.user = @operator + print = prints(:math_print_with_credit) initial_bonus = print.customer.bonuses.to_a.sum(&:remaining) payments_amount = print.payments.select(&:credit?).to_a.sum(&:paid) diff --git a/test/models/user_test.rb b/test/models/user_test.rb index ec4402ce..d2948216 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -2,6 +2,7 @@ # Clase para probar el modelo "User" class UserTest < ActiveSupport::TestCase + # Función para inicializar las variables utilizadas en las pruebas def setup @operator = users(:operator) @@ -17,7 +18,7 @@ def setup assert_equal users(:operator).default_printer, @operator.default_printer assert_equal users(:operator).lines_per_page, @operator.lines_per_page assert_equal users(:operator).username, @operator.username - assert_equal users(:operator).crypted_password, @operator.crypted_password + assert_equal users(:operator).encrypted_password, @operator.encrypted_password assert_equal users(:operator).admin, @operator.admin assert_equal users(:operator).enable, @operator.enable end diff --git a/test/test_helper.rb b/test/test_helper.rb index 5173eb45..7d550996 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,7 +1,7 @@ ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' -require 'authlogic/test_case' +# require 'authlogic/test_case' require 'sidekiq/testing' require 'database_cleaner' # require 'minitest/reporters' @@ -12,12 +12,32 @@ # Minitest::Reporters.use! Minitest::Reporters::ProgressReporter.new +module FixturesExAuthlogicHelpers + def hex_token + SecureRandom.hex(64) + end + + def friendly_token + SecureRandom.urlsafe_base64(15) + end + + def encrypt(text, salt) + Devise::Encryptable::Encryptors::AuthlogicSha512.digest( + text, Devise.stretches, salt, nil + ) + end +end + +ActiveRecord::FixtureSet.context_class.send :include, FixturesExAuthlogicHelpers + class ActiveSupport::TestCase ActiveRecord::Migration.maintain_test_schema! set_fixture_class versions: PaperTrail::Version # self.use_transactional_fixtures = true # Minitest::Reporters.use! Minitest::Reporters::ProgressReporter.new + # Fixtures Ex-Authlogic generators + fixtures :all # Add more helper methods to be used by all tests here... @@ -95,13 +115,7 @@ def drop_all_prints end class ActionController::TestCase - include Authlogic::TestCase - setup :activate_authlogic -end - -class ActiveSupport::TestCase - include Authlogic::TestCase - setup :activate_authlogic + include Devise::Test::ControllerHelpers end class JSException < Exception @@ -150,6 +164,7 @@ def self._running_local ) end + # (Capybara.page.driver.remove_cookie('user_credentials') rescue nil) Capybara.register_driver :poltergeist do |app| Capybara::Poltergeist::Driver.new(app, { # debug: true, @@ -238,7 +253,7 @@ def login(*args) # options[:expected_path] ||= prints_path # user = options[:user_id].present? ? User.find(options[:user_id]) : users(:operator) - # # UserSession.create(user) + # # sign_in(user) # page.driver.set_cookie( # 'user_credentials', # "#{user.persistence_token}::#{user.id}"