Fix coding standards in application
This commit is contained in:
parent
aca19eb51f
commit
e6f6475705
@ -1,26 +1,28 @@
|
|||||||
class API::ApplicationController < ApplicationController
|
module API
|
||||||
skip_before_filter :verify_authenticity_token
|
class ApplicationController < ::ApplicationController
|
||||||
skip_before_filter :authenticate!, only: [:cor_preflight]
|
skip_before_filter :verify_authenticity_token
|
||||||
|
skip_before_filter :authenticate!, only: [:cor_preflight]
|
||||||
|
|
||||||
before_filter :cor_filter
|
before_filter :cor_filter
|
||||||
|
|
||||||
def cor_filter
|
def cor_filter
|
||||||
headers['Access-Control-Allow-Origin'] = request.headers['Origin'] ?
|
headers['Access-Control-Allow-Origin'] = request.headers['Origin'] ?
|
||||||
request.headers['Origin'] :
|
request.headers['Origin'] :
|
||||||
''
|
''
|
||||||
headers['Access-Control-Allow-Credentials'] = 'true'
|
headers['Access-Control-Allow-Credentials'] = 'true'
|
||||||
headers['Access-Control-Expose-Headers'] = 'Content-Length'
|
headers['Access-Control-Expose-Headers'] = 'Content-Length'
|
||||||
end
|
end
|
||||||
|
|
||||||
def cor_preflight
|
def cor_preflight
|
||||||
headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE'
|
headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE'
|
||||||
headers['Access-Control-Allow-Headers'] =
|
headers['Access-Control-Allow-Headers'] =
|
||||||
'Content-Type, Content-Length, X-Requested-With'
|
'Content-Type, Content-Length, X-Requested-With'
|
||||||
|
|
||||||
head :ok
|
head :ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def authenticate!
|
def authenticate!
|
||||||
head :unauthorized if current_user.nil?
|
head :unauthorized if current_user.nil?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
class API::PlaylistsController < API::ApplicationController
|
module API
|
||||||
respond_to :json
|
class PlaylistsController < ApplicationController
|
||||||
|
respond_to :json
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@playlists = Playlist.all
|
@playlists = Playlist.all
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@playlist = current_user.playlists.build(params[:playlist].slice(:name))
|
@playlist = current_user.playlists.build(params[:playlist].slice(:name))
|
||||||
@playlist.save
|
@playlist.save
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
class API::SessionsController < API::ApplicationController
|
module API
|
||||||
skip_before_filter :authenticate!, only: [:create]
|
class SessionsController < ApplicationController
|
||||||
|
skip_before_filter :authenticate!, only: [:create]
|
||||||
|
|
||||||
def create
|
def create
|
||||||
user = User.find_by_email(params[:session][:email])
|
user = User.find_by_email(params[:session][:email])
|
||||||
|
|
||||||
if !user.try(:authenticate?, params[:session][:password])
|
unless user.try(:authenticate?, params[:session][:password])
|
||||||
return render json: '', status: :not_found
|
return render json: '', status: :not_found
|
||||||
|
end
|
||||||
|
|
||||||
|
@user = user
|
||||||
|
self.current_user = @user
|
||||||
end
|
end
|
||||||
|
|
||||||
@user = user
|
|
||||||
self.current_user = @user
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
class API::SoundsController < API::ApplicationController
|
module API
|
||||||
# FIXME: add some tests!
|
class SoundsController < ApplicationController
|
||||||
def show
|
# FIXME: add some tests!
|
||||||
sound = Sound.find params[:id]
|
def show
|
||||||
send_file sound.path, type: sound.mime_type
|
sound = Sound.find params[:id]
|
||||||
|
send_file sound.path, type: sound.mime_type
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
class API::TracksController < API::ApplicationController
|
module API
|
||||||
def index
|
class TracksController < ApplicationController
|
||||||
@tracks = Track.all
|
def index
|
||||||
|
@tracks = Track.all
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user