diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb new file mode 100644 index 0000000..950c624 --- /dev/null +++ b/app/controllers/user_controller.rb @@ -0,0 +1,26 @@ +require 'digest' + +class UserController < ApplicationController + @@secret_key + def auth + # Defining secret key dependent on hostname + @@secret_key = request.host == 'beathaven.org' ? 'sdgwSbl3nNE4ZxafuPrp' : 's5zyjb693z6uV4rbhEyc' + @res = {} + + unless params[:expire].nil? or params[:mid].nil? or params[:secret].nil? or params[:sid].nil? or params[:sig].nil? + # Calculating hash + hash = 'expire='+ params[:expire] +'mid='+ params[:mid] +'secret='+ params[:secret] +'sid='+ params[:sid] + @@secret_key + hash_md5 = Digest::MD5.hexdigest(hash) + + if Digest::MD5.hexdigest(hash) == params[:sig] + @res[:status] = 'hello' + else + @res[:status] = 'bad signature' + end + else + @res[:status] = 'bad params' + end + + render :json => @res + end +end diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb new file mode 100644 index 0000000..0147c3f --- /dev/null +++ b/app/helpers/user_helper.rb @@ -0,0 +1,2 @@ +module UserHelper +end diff --git a/config/routes.rb b/config/routes.rb index 037e429..2be460f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -56,6 +56,7 @@ Beathaven::Application.routes.draw do # Note: This route will make all actions in every controller accessible via GET requests. # match ':controller(/:action(/:id(.:format)))' + match 'user/auth' => 'user#auth' match 'artist/autocomplete' => 'artist#autocomplete' match 'artist/(:name)/' => 'artist#data', :constraints => { :name => /[^\/]*/ } end diff --git a/test/functional/user_controller_test.rb b/test/functional/user_controller_test.rb new file mode 100644 index 0000000..104b787 --- /dev/null +++ b/test/functional/user_controller_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class UserControllerTest < ActionController::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/test/unit/helpers/user_helper_test.rb b/test/unit/helpers/user_helper_test.rb new file mode 100644 index 0000000..ad44a53 --- /dev/null +++ b/test/unit/helpers/user_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class UserHelperTest < ActionView::TestCase +end