basic authentication stuff
This commit is contained in:
@@ -267,6 +267,23 @@ class UserController < Users::ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def obtain_token
|
||||
redirect_to user_omniauth_authorize_path('facebook') and return unless current_user.present?
|
||||
respond_to do |format|
|
||||
format.html { render layout: 'user/obtain_token' }
|
||||
format.json do
|
||||
render json: json_response(ok: false, status: 401) and return unless params[:user].present? && params[:user][:email].present? && params[:user][:password].present?
|
||||
user = User.find_by_email(params[:user][:email])
|
||||
render json: json_response(ok: false, status: 401) and return unless user
|
||||
render json: json_response(ok: false, status: 401) and return unless user.valid_password?(params[:user][:password])
|
||||
user.ensure_authentication_token
|
||||
sign_in user
|
||||
render json: json_response(ok: true, auth_token: user.authentication_token, user_id: user.id)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
def move_table
|
||||
render json: json_alert('messages.no_active_list', list_active: false) and return unless list.present?
|
||||
render json: json_alert('messages.table_not_found') and return unless params[:table_id].present?
|
||||
|
||||
@@ -20,23 +20,6 @@ module Users
|
||||
end
|
||||
end
|
||||
|
||||
def obtain_token
|
||||
redirect_to user_omniauth_authorize_path('facebook') and return unless current_user.present?
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json do
|
||||
render json: json_response(ok: false, status: 401) and return unless params[:user].present? && params[:user][:email].present? && params[:user][:password].present?
|
||||
user = User.find_by_email(params[:user][:email])
|
||||
render json: json_response(ok: false, status: 401) and return unless user
|
||||
render json: json_response(ok: false, status: 401) and return unless user.valid_password?(params[:user][:password])
|
||||
user.ensure_authentication_token
|
||||
sign_in user
|
||||
render json: json_response(ok: true, auth_token: user.authentication_token, user_id: user.id)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
def handle_message_params
|
||||
flash.now[:notice] = t('messages.the_list_has_been_closed', list: List.model_name.human) if params[:list_closed].present?
|
||||
flash.now[:notice] = t("messages.#{params[:message]}", list: List.model_name.human, supplier: Supplier.model_name.human) if params[:message].present? && params[:message] =~ /^\w+$/
|
||||
|
||||
Reference in New Issue
Block a user