Auth prototype
This commit is contained in:
		
							parent
							
								
									78cc2d343c
								
							
						
					
					
						commit
						93130968fd
					
				
							
								
								
									
										26
									
								
								app/controllers/user_controller.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								app/controllers/user_controller.rb
									
									
									
									
									
										Normal 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
 | 
			
		||||
							
								
								
									
										2
									
								
								app/helpers/user_helper.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								app/helpers/user_helper.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
			
		||||
module UserHelper
 | 
			
		||||
end
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										8
									
								
								test/functional/user_controller_test.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								test/functional/user_controller_test.rb
									
									
									
									
									
										Normal 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
 | 
			
		||||
							
								
								
									
										4
									
								
								test/unit/helpers/user_helper_test.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								test/unit/helpers/user_helper_test.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,4 @@
 | 
			
		||||
require 'test_helper'
 | 
			
		||||
 | 
			
		||||
class UserHelperTest < ActionView::TestCase
 | 
			
		||||
end
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user