68 lines
1.5 KiB
Ruby
68 lines
1.5 KiB
Ruby
class UserController < ApplicationController
|
|
|
|
def auth
|
|
return unless authorized?
|
|
@res = {}
|
|
|
|
@res[:status] = 'hello'
|
|
user = User.find_by_vkid(params[:mid])
|
|
if user.nil?
|
|
user = User.new
|
|
user.vkid = params[:mid]
|
|
user.save
|
|
end
|
|
@res[:id] = user.id
|
|
@res[:username] = user.name
|
|
session = Session.find_or_create_by_user_id(user.id)
|
|
session.key = Digest::SHA256.hexdigest(rand(99999999).to_s + user.id.to_s + rand(99999999).to_s)
|
|
session.save
|
|
|
|
render :json => @res
|
|
end
|
|
|
|
def update
|
|
return unless authorized?
|
|
@res = {}
|
|
|
|
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
|
|
end
|
|
@res[:username] = user.name
|
|
@res[:email] = user.email
|
|
|
|
render :json => @res
|
|
end
|
|
|
|
def fav
|
|
return unless authorized?
|
|
@res = {status: 'fail'}
|
|
|
|
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'
|
|
end
|
|
end
|
|
|
|
render :json => @res
|
|
end
|
|
|
|
end
|