2012-05-23 1 views
0

저는 Rhomobile에서 매우 새로운 사람입니다. Rhoconnect를 사용하여 webservice에 로그인하려면 아무에게도 이것을 구현하는 방법을 알려줄 수 있습니까?Rhoconnect webservice login need

내가 설정 CONTROLER에 함께 시도했다 :

def do_login 
    if @params['username'] and @params['password'] 
     begin 
     SyncEngine.login(@params['username'], @params['password'], (url_for :action => :login_callback)) 
     @response['headers']['Wait-Page'] = 'true' 
     redirect :action => :index 
     rescue Rho::RhoError => e 
     @msg = e.message 
     render :action => :login 
     end 
    else 
     @msg = Rho::RhoError.err_message(Rho::RhoError::ERR_UNATHORIZED) unless @msg && @msg.length > 0 
     render :action => :login 
    end 
    end 

경우 SyncEngine.login(@params['username'], @params['password']) 호출 sourecadapter 방법 login; 내가

def login(username, password) 
     user_info = {:username => username, :password => password } 
     response = RestClient.get(@[email protected]['username'][email protected]['password']) 
     result = RestClient.post(:url => "my-webservice") 
     @msg=result["body"] 
     render :action => :index 
end 

를 호출하고있어 어디에서 시도했다 :

class Application < Rhoconnect::Base 
    class << self 
    def authenticate(username,password,session) 
     result = RestClient.post(:url => "mywebservice") 
     true # do some interesting authentication here... 
    end 
end 

그러나 나는 아무것도 없어 ... PLZ 몇 가지 아이디어 줘; 이 문제를 해결하는 방법

답변

1

Rhodes에서 SyncEngine.login을 호출하면 RhoConnect 앱의 application.rb에 인증 메소드 (사용자 이름, 비밀번호, 세션)가 호출됩니다. 그런 다음 authenticate 메소드를 코딩하여 다음과 같이 사용자 인증 구현을 호출 할 수 있습니다.

def authenticate(username, password, session) 
    # for example 
    resp = RestClient.post(:url => "mywebservice", :login => {:username => username, :password => password}) 

    #parse resp as needed and return the result either true or false 
    # i.e. status contains value true or false in the response body 
    result = JSON.parse(resp.body)['status'] 
end 

희망 사항.