2011-06-20 23:28:09 +00:00
|
|
|
class UserController < ApplicationController
|
2011-06-21 20:44:19 +00:00
|
|
|
|
2011-06-20 23:28:09 +00:00
|
|
|
def auth
|
2011-06-22 00:55:09 +00:00
|
|
|
return unless authorized?
|
2011-06-20 23:28:09 +00:00
|
|
|
@res = {}
|
|
|
|
|
2011-06-22 00:55:09 +00:00
|
|
|
@res[:status] = 'hello'
|
|
|
|
user = User.find_by_vkid(params[:mid])
|
|
|
|
if user.nil?
|
|
|
|
user = User.new
|
|
|
|
user.vkid = params[:mid]
|
|
|
|
user.save
|
2011-06-21 20:44:19 +00:00
|
|
|
end
|
2011-06-22 00:55:09 +00:00
|
|
|
@res[:id] = user.id
|
|
|
|
@res[:username] = user.name
|
2011-06-21 20:44:19 +00:00
|
|
|
|
|
|
|
render :json => @res
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2011-06-22 00:55:09 +00:00
|
|
|
return unless authorized?
|
2011-06-21 23:29:18 +00:00
|
|
|
@res = {}
|
|
|
|
|
2011-06-22 00:55:09 +00:00
|
|
|
user = User.find_by_vkid(params[:mid])
|
|
|
|
unless params[:username].nil? or params[:email].nil?
|
|
|
|
user.name = params[:username]
|
|
|
|
user.email = params[:email]
|
|
|
|
user.save
|
2011-06-21 23:29:18 +00:00
|
|
|
end
|
2011-06-22 00:55:09 +00:00
|
|
|
@res[:username] = user.name
|
|
|
|
@res[:email] = user.email
|
2011-06-21 20:44:19 +00:00
|
|
|
|
2011-06-21 23:29:18 +00:00
|
|
|
render :json => @res
|
2011-06-21 20:44:19 +00:00
|
|
|
end
|
|
|
|
|
2011-06-22 00:05:12 +00:00
|
|
|
def fav
|
2011-06-22 00:55:09 +00:00
|
|
|
return unless authorized?
|
2011-06-22 00:05:12 +00:00
|
|
|
@res = {status: 'fail'}
|
|
|
|
|
2011-06-22 00:55:09 +00:00
|
|
|
fav = Favorite.new
|
|
|
|
if not params[:artist].nil?
|
|
|
|
artist = Artist.find(params[:artist]);
|
|
|
|
unless artist.nil?
|
|
|
|
fav.artist_id = artist.id
|
|
|
|
res[:status] = 'added'
|
|
|
|
end
|
|
|
|
elsif not params[:album].nil?
|
|
|
|
album = Album.find(params[:album]);
|
|
|
|
unless album.nil?
|
|
|
|
fav.album_id = album.id
|
|
|
|
res[:status] = 'added'
|
|
|
|
end
|
|
|
|
elsif not params[:track].nil?
|
|
|
|
track = Track.find(params[:track]);
|
|
|
|
unless track.nil?
|
|
|
|
fav.track_id = track.id
|
|
|
|
res[:status] = 'added'
|
2011-06-22 00:05:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
render :json => @res
|
|
|
|
end
|
|
|
|
|
2011-06-20 23:28:09 +00:00
|
|
|
end
|