Author: Braulio Bhavamitra <braulio@prout.io>
stores_app: add phone to users and authenticate
%!v(PANIC=String method: strings: negative Repeat count)
diff --git a/app/models/user.rb b/app/models/user.rb index 129eb4977655d2943014d4db9605eb91c685ce06..c3a99fa866b86ac5cfe4c714bddcbe9b2e73c2e1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -142,7 +142,7 @@ validates_inclusion_of :terms_accepted, :in => [ '1' ], :if => lambda { |u| ! u.terms_of_use.blank? }, :message => N_('{fn} must be checked in order to signup.').fix_i18n scope :has_login?, lambda { |login,email,environment_id| - where('login = ? OR email = ?', login, email). + where('login = ? OR email = ? OR phone = ?', login, email, login). where(environment_id: environment_id) } diff --git a/db/migrate/20171118140710_add_phone_to_users.rb b/db/migrate/20171118140710_add_phone_to_users.rb new file mode 100644 index 0000000000000000000000000000000000000000..7f94bae93412ff07af9779b7e4ef5e57ff1996fe --- /dev/null +++ b/db/migrate/20171118140710_add_phone_to_users.rb @@ -0,0 +1,5 @@ +class AddPhoneToUsers < ActiveRecord::Migration + def change + add_column :users, :phone, :string + end +end diff --git a/plugins/stores_app/app/controllers/profile/stores_app_plugin/api_controller.rb b/plugins/stores_app/app/controllers/profile/stores_app_plugin/api_controller.rb index 68e9905bbc2be947ef443cf0fe6b11cf865b5c2c..f44f0455d044850947a8caff5ed6212c1d2f8071 100644 --- a/plugins/stores_app/app/controllers/profile/stores_app_plugin/api_controller.rb +++ b/plugins/stores_app/app/controllers/profile/stores_app_plugin/api_controller.rb @@ -1,8 +1,11 @@ module StoresAppPlugin - class ApiController < ::ApplicationController + class ApiController < ActionController::Base + + attr_reader :environment + include NeedsProfile layout false - + before_filter :set_environment needs_profile before_filter :allow_cors @@ -13,6 +16,14 @@ headers['Access-Control-Allow-Origin'] = '*' headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS' headers['Access-Control-Request-Method'] = '*' headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization' + end + + def user + @user ||= User.find_by private_token: params[:auth_token] + end + + def set_environment + @environment = Environment.default end end diff --git a/plugins/stores_app/app/controllers/profile/stores_app_plugin/users_controller.rb b/plugins/stores_app/app/controllers/profile/stores_app_plugin/users_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..154ded879be3de81158943241d66def64e47a815 --- /dev/null +++ b/plugins/stores_app/app/controllers/profile/stores_app_plugin/users_controller.rb @@ -0,0 +1,16 @@ +module StoresAppPlugin + class UsersController < ApiController + + def signin + @user = User.authenticate params[:login], params[:password] + if @user + render json: {auth_token: @user.private_token} + else + render json: {error: 'invalid_login_pass'} + end + end + + protected + + end +end