Session Support Structure

<< Click to Display Table of Contents >>

Navigation:  PUM - Modellierung und Codeerzeugung > Strukturen und Muster >

Session Support Structure

Beschreibung

Diese Struktur ermöglicht die Bearbeitung von Benutzer-Sessions.

Beispielimplementierung

Benutzer loggt sich ein - Smalltalk - Server

 

apiSessionNewSession: aTSTAPIParNewSession options: aMSKRestCallOptions

 

 "Creates a new session for the user and returns the new session object"

 

 | aTSTAPIResSingleSession aTSTAPIAppSession userFound customerFound ATSTAPIAppSession aTSTAppSession |

 

 "We check the parameter"

 aTSTAPIParNewSession getLogin pumIsStringAndNotEmpty

         ifFalse:[ self errorMessageClass errCodeGeneralErrorThrowSignal: aMSKRestCallOptions  with1Args: #('login parameter not set') ].

 

 

 aTSTAPIParNewSession getPassword pumIsStringAndNotEmpty

         ifFalse:[ self errorMessageClass errCodeGeneralErrorThrowSignal: aMSKRestCallOptions  with1Args: #('password parameter not set') ].

 

 "Now we can check at our customers if there is a user known with that login"

 self dataRootInstance getCustomer do: [ :eachTSTAppCustomer |

         userFound isNil ifTrue:[ userFound := eachTSTAppCustomer getUsers detect: [ :eachTSTAppUser | eachTSTAppUser getLogin = aTSTAPIParNewSession getLogin ] ifNone: [ nil ] ]

 ].

 

 "so if no user has been found"

 userFound isNil

         ifTrue:[ self errorMessageClass errCodeGeneralErrorThrowSignal: aMSKRestCallOptions  with1Args: #('user could not be found') ].

 

 "now to check the password"

 (userFound getPassword =  GRPlatform current secureHashFor: aTSTAPIParNewSession getPassword)

         ifFalse:[  self errorMessageClass errCodeGeneralErrorThrowSignal: aMSKRestCallOptions  with1Args: #('password wrong') ].

 

 "we create the persistent structure"

 aTSTAppSession := TSTAppSession newInitialized.

 

 aTSTAppSession

         setAppUser: userFound ;

         setCurrentLocale: aMSKRestCallOptions localeString ;

         setLocation: aMSKRestCallOptions requesterHost  ;

 

 "the following values should be retrieved from the server for rabbitmq websocket server"

         setWsLogin: nil ;

         setWsPassword: nil ;

         setVHost: nil ;        

         updateTimeout.

 

 "Now the session get persistent"

 self dataRootInstance addActiveAppSession: aTSTAppSession.

 

 "We create the return api structure"

 aTSTAPIResSingleSession := TSTAPIResSingleSession newInitialized setAllAttributesToNil.

 aTSTAPIResSingleSession

         setSession: (TSTAPIAppSession copyFrom: aTSTAppSession).

 

         

 ^(self restAnswerClass okRequestFor: aMSKRestCallOptions restCallInstance result: aTSTAPIResSingleSession) 

                 successWithCommitCall;

                 yourself