Fix conflict methods
This commit is contained in:
parent
87dab3df57
commit
8a188cf6bd
|
@ -50,21 +50,21 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
protected
|
||||
|
||||
def session
|
||||
def user_session
|
||||
Session.find_by_key(session_key)
|
||||
end
|
||||
|
||||
def current_user
|
||||
session.user if current_user?
|
||||
user_session.user if user_present?
|
||||
end
|
||||
|
||||
def current_user?
|
||||
!session.nil? and !session.user.nil?
|
||||
def user_present?
|
||||
!user_session.nil? and !user_session.user.nil?
|
||||
end
|
||||
|
||||
def set_locale
|
||||
unless session.nil?
|
||||
I18n.locale = session.user.lang
|
||||
unless user_session.nil?
|
||||
I18n.locale = user_session.user.lang
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class LastFmController < ApplicationController
|
|||
|
||||
def connect
|
||||
unless params[:sid].nil? or params[:token].nil?
|
||||
if current_user?
|
||||
if user_present?
|
||||
lastfm_api_session = LastFM::Auth.get_session(token: params[:token], api_sig: true)
|
||||
user = current_user
|
||||
user.lastfm_key = lastfm_api_session["session"]['key']
|
||||
|
@ -23,17 +23,16 @@ class LastFmController < ApplicationController
|
|||
|
||||
def getinfo
|
||||
@res = {}
|
||||
user = User.find_by_vkid(params[:mid])
|
||||
unless user.lastfm_key.nil?
|
||||
unless current_user.lastfm_key.nil?
|
||||
render json: {
|
||||
connected: true,
|
||||
username: user.lastfm_username
|
||||
username: current_user.lastfm_username
|
||||
}
|
||||
else
|
||||
render json: {
|
||||
connected: false,
|
||||
lastfm_login_url: "http://www.last.fm/api/auth?api_key=#{LastFM.api_key}"+
|
||||
"&cb=http://#{request.host}:#{request.port.to_s}/lastfm/connect/?sid=#{user.session.key}"
|
||||
"&cb=http://#{request.host}:#{request.port.to_s}/lastfm/connect/?sid=#{user_session.key}"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -43,7 +42,7 @@ class LastFmController < ApplicationController
|
|||
if params[:artist].nil? or params[:album].nil? or params[:name].nil?
|
||||
return render json: { status: 'bad params' }, status: 403
|
||||
end
|
||||
if !current_user? or (current_user.lastfm_key.nil? or current_user.lastfm_key == "")
|
||||
if !user_present? or (current_user.lastfm_key.nil? or current_user.lastfm_key == "")
|
||||
return render json: {status: 'lastfm account is not connected' }
|
||||
end
|
||||
r = LastFM::Track.update_now_playing(
|
||||
|
@ -62,10 +61,10 @@ class LastFmController < ApplicationController
|
|||
if params[:artist].nil? or params[:album].nil? or params[:name].nil?
|
||||
return render json: { status: 'bad params' }, status: 403
|
||||
end
|
||||
if current_user? and track = Track.find_by_id(params[:id])
|
||||
if user_present? and track = Track.find_by_id(params[:id])
|
||||
Scrobble.create(user: current_user, track: track, scrobbled_at: DateTime.now)
|
||||
end
|
||||
if !current_user? or (current_user.lastfm_key.nil? or current_user.lastfm_key == "")
|
||||
if !user_present? or (current_user.lastfm_key.nil? or current_user.lastfm_key == "")
|
||||
return render json: { status: 'lastfm account is not connected' }
|
||||
end
|
||||
r = LastFM::Track.scrobble(
|
||||
|
|
|
@ -3,9 +3,13 @@ class UserController < ApplicationController
|
|||
|
||||
def auth
|
||||
@res = {status: 'hello', newbie: false}
|
||||
user = User.find_by_vkid(params[:mid])
|
||||
user = current_user
|
||||
if user.nil?
|
||||
user = User.new(vkid: params[:mid], lang: 'ru').save
|
||||
user = User.find_or_create_by_vkid(params[:mid].to_i)
|
||||
if user.lang.nil?
|
||||
user.lang = "ru"
|
||||
user.save
|
||||
end
|
||||
@res[:newbie] = true
|
||||
end
|
||||
|
||||
|
@ -25,7 +29,7 @@ class UserController < ApplicationController
|
|||
def update
|
||||
allowed_params = [:name, :email, :lang, :show, :lastfm_username, :lastfm_key]
|
||||
|
||||
user = User.find_by_vkid(params[:mid])
|
||||
user = current_user
|
||||
unless params[:params].nil?
|
||||
update_params = {}
|
||||
params[:params] = params[:params].each{ |k, v| update_params[k.to_sym] = v }
|
||||
|
@ -71,7 +75,7 @@ class UserController < ApplicationController
|
|||
end
|
||||
|
||||
def set_first_favorites
|
||||
return render json: { status: "unauthorized" } unless current_user?
|
||||
return render json: { status: "unauthorized" } unless user_present?
|
||||
return render json: { status: "already imported" } unless current_user.favorites.empty?
|
||||
|
||||
artists = {}
|
||||
|
|
|
@ -2,4 +2,6 @@ class User < ActiveRecord::Base
|
|||
bitmask :music, :as => [:album, :single, :live, :bootleg, :soundtrack]
|
||||
has_one :session
|
||||
has_many :favorites
|
||||
|
||||
validates_uniqueness_of :vkid
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue