Hi,
There's been a lot of discussion on the list about how to extend
Turbine-User, so I thought I'd note that I found an alternative method
(which may be simpler if less elegant).
The problem-- I can't follow the method outlined in the Extend User How-To,
because I'm using the decoupled Torque and the Turbine security model is
still coupled to the old Torque.
The solution-- Don't change User, but create a completely new object
"CustomTurbineUser", mapped to the database that reads/writes the full set
of fields in the same table. Turbine continues to use the old User for
security login.
The catch -- when saving CustomTurbineUser, the fields that User maps to
(FIRST_NAME, LAST_NAME, USER_ID and one or two others) will not be
permanently stored as User will overwrite these the next time it is saved
(which appears to happen at logout). This can be gotten around by clearing
the User from the session, then putting it back.
I created the CustomTurbineUser (and CustomTurbineUserPeer) objects by
making a new schema "customuser-schema.xml" and running "ant project-om".
Here's some sample code. The actual code was slightly different as I had
some of this in method calls. I also took out error checking.
I recognize this is a bit of a hack. Works best when most data access is
retrieval, not writing to the database. Look forward to when the security
model uses the decoupled Torque and I don't need to do this.
WILL
***************************
String username = "user_to_change";
/////////////////// get the user record
Criteria crit = new Criteria();
crit.add(TurbineUserPeer.LOGIN_NAME,username);
List RecordList = CustomTurbineUserPeer.doSelect(crit);
CustomTurbineUser EditUser = (CustomTurbineUser) RecordList.get(0);
/////////////////// change the user record
EditUser.setState("CA");
/////////////////// save the modified user info
// Save the RunData User (in case there are any recent changes)
User u = data.getUser();
TurbineSecurity.saveUser(u);
// Take the security user out of the session.
// (Note-- must be done before changing the database as it apparently saves
User).
data.getSession().removeAttribute(User.SESSION_KEY);
// Change the database.
EditUser.save();
//reload User
User u2 = TurbineSecurity.getUser(EditUser.getLoginName());
data.setUser(u2);
u2.setHasLoggedIn(Boolean.TRUE);
// put the User back in the session
data.getSession().setAttribute(User.SESSION_KEY,u2);
***************************
and the schema.
<table name="CUSTOM_TURBINE_USER" idMethod="idbroker" skipSql="true">
<column name="USER_ID" required="true" primaryKey="true"
type="INTEGER"/>
<column name="LOGIN_NAME" required="true" size="32" type="VARCHAR"/>
<column name="PASSWORD_VALUE" required="true" size="32" type="VARCHAR"/>
<column name="FIRST_NAME" required="true" size="99" type="VARCHAR"/>
<column name="LAST_NAME" required="true" size="99" type="VARCHAR"/>
<column name="EMAIL" size="99" type="VARCHAR"/>
<column name="CONFIRM_VALUE" size="99" type="VARCHAR"/>
<column name="MODIFIED" type="TIMESTAMP"/>
<column name="CREATED" type="TIMESTAMP"/>
<column name="LAST_LOGIN" type="TIMESTAMP"/>
<column name="OBJECTDATA" type="VARBINARY"/>
<!-- NEW ADDITIONS -->
<column name="COMPANY" size="255" type="VARCHAR" />
<column name="ADDRESS1" size="255" type="VARCHAR" />
<column name="ADDRESS2" size="255" type="VARCHAR" />
<column name="CITY" size="255" type="VARCHAR" />
<column name="STATE" size="255" type="VARCHAR" />
<column name="ZIP" size="255" type="VARCHAR" />
<column name="COUNTRY" size="255" type="VARCHAR" />
<column name="PHONE" size="255" type="VARCHAR" />
<unique>
<unique-column name="LOGIN_NAME"/>
</unique>
</table>
_______________________________________
Forio Business Simulations
Will Glass-Husain
(415) 440-7500 phone
(415) 235-4293 mobile
[EMAIL PROTECTED]
www.forio.com
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>