1
0
Fork 0

Auth prototype

This commit is contained in:
magnolia-fan 2011-06-21 03:28:09 +04:00
parent 78cc2d343c
commit 93130968fd
5 changed files with 41 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,2 @@
module UserHelper
end

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,4 @@
require 'test_helper'
class UserHelperTest < ActionView::TestCase
end