CSPアプリケーションをReactを使って書き換えるその4
IRIS側の処理は、IRISでREST APIを実装する方法を理解していれば、簡単です。
前回のログイン処理でユーザー認証をIRIS側でどのように実装されているか確認して見ましょう。
まずはディスパッチクラスの定義です。
Shop.Brokerというクラスの中で定義されています。
checkpasswordというメソッドが最後に定義されていて、最終的にShop.Rest.Customer:checkPasswordという(クラス)メソッドが呼ばれているのがわかると思います。
ここで定義しているパラメータは、とりあえずおまじない的に含めておくことをお勧めします。
(説明し出すと少し長くなるので)
Class Shop.Broker Extends%CSP.REST
{
Parameter CONVERTINPUTSTREAM = 1;Parameter HandleCorsRequest = 1;
XData UrlMap
{
<Routes>
<Route Url="/product/:code" Method="GET" Call="Shop.Rest.Product:getRecord"/>
<Route Url="/products" Method="GET" Call="Shop.Rest.Product:listRecords"/>
<Route Url="/deleteproduct/:code" Method="GET" Call="Shop.Rest.Product:deleteRecord"/>
<Route Url="/addproduct" Method="POST" Call="Shop.Product:createRecord"/>
<Route Url="/modifyproduct" Method="POST" Call="Shop.Rest.Product:modifyRecord"/>
<Route Url="/customer/:id" Method="GET" Call="Shop.Rest.Customer:getRecord"/>
<Route Url="/customers" Method="GET" Call="Shop.Rest.Customer:listRecords"/>
<Route Url="/deletecustomer/:id" Method="GET" Call="Shop.Rest.Customer:deleteRecord"/>
<Route Url="/addcustomer" Method="POST" Call="Shop.Customer:createRecord"/>
<Route Url="/modifycustomer" Method="POST" Call="Shop.Rest.Customer:modifyRecord"/>
<Route Url="/addorder" Method="POST" Call="Shop.Rest.POrder:createRecord"/>
<Route Url="/order/:id" Method="GET" Call="Shop.Rest.POrder:getRecord"/>
<Route Url="/orders" Method="GET" Call="Shop.Rest.POrder:listRecords"/>
<Route Url="/checkpassword/:userid/:password" Method="GET" Call="Shop.Rest.Customer:checkPassword"/>
</Routes>
}
}
Shop.Rest.CustomerクラスのcheckPasswordメソッドの中は以下のような感じです。
IRISがわかっている人ならば中身の説明は不要ですよね。
ClassMethod checkPassword(pUserId As%String, pPassword) As%Status
{
set status = $$$OK
try {
if$data(%request) {
set%response.ContentType="application/json"
set%response.CharSet = "utf-8"
}
set cust=##class(Shop.Customer).CheckPasswd(pUserId, pPassword)
setreturn = {}
if cust = "" {
setreturn.authorized = "ng"
}
else {
setreturn.authorized = "ok"
setreturn.ID = cust.%Id()
}
doreturn.%ToJSON()
}
catch e {
set status = e.AsStatus()
}
Quit status
}
大体こんな感じです。
結構色々なことを理解しないとなかなか前に進めませんが、やはり理解するには自分で何か作ってみるのが一番です。
ディスカッション (0)0