I am looking for the correct way to perform server-side code without using a remote procedure type mechanism. I wish to use a SessionID as part of my login component. I have implemented a LoginManager and have been using the Login method to successfully authenticate my user and return the IPrincipal object. Now I wish to as part of the server side login code to generate a SessionID ( I know there is a DevForce SessionKey ), insert time and date of the session and associated UserAccountID into the database and return the autogenerated SessionID as a property in the Principal object. I have enclosed some sample code. I am assuming my problem here is that the SaveChanges in the new_Session method is ASync. If it is server side can I make it synchronous or how do I complete the login process in this context.
/// <summary> /// /// </summary> /// <param name="credential"></param> /// <param name="entityManager"></param> /// <returns></returns> public IPrincipal Login(ILoginCredential credential, EntityManager entityManager) { UserConfigEntities userEntities = new UserConfigEntities(entityManager);
if (credential == null) { throw new LoginException(LoginExceptionType.NoCredentials, "No credentials supplied"); } // Return an IPrincipal. Any serializable type may be returned, // here we use the DevForce UserIdentity and UserBase classes. UserAccount aUser = Get_User(userEntities, credential.UserName); Verify_Credentials(aUser, credential.UserName, credential.Password, credential.Domain);
var identity = new LEAF.Security.LEAFIdentity(credential.UserName, credential.Domain); var principal = new LEAF.Security.LEAFUser(identity, null); principal.loggedInUser = aUser; principal.SessionId = new_Session(entityManager, aUser); return principal; }
/// <summary> /// /// </summary> /// <returns></returns> private Int32 new_Session(EntityManager entityManager, UserAccount aUser) { LEAFSession userSession = new LEAFSession();
userSession.UserAccountID = aUser.UserAccountID; DateTime currentDateTime = DateTime.Now; userSession.DT_SessionStart = currentDateTime;
//update the datetime and sessionID for the Session userSession.DT_Insert = currentDateTime; userSession.DT_Update = currentDateTime; userSession.SID_Insert = -1; userSession.SID_Update = -1;
entityManager.AddEntity(userSession); entityManager.SaveChanges();
return userSession.LEAF_SessionID;
}
|