I'm having problems creating a User from within my app. It seems to think the
User already exists.
Any ideas please?
Mike
Here's my output:
(I'm logged in as test hence the msg: Verifying that 'test' can modify
'test6')
ApplyForm.cmApprove(133) | User test6 not found, OK, creating cons...
ApplyForm.cmApprove(150) | Saved cons, email= test6 - its Id= 126
ApplyForm.cmApprove(180) | About to save user: ...
UserSecurityAdvice.before(70) | Verifying that 'test' can modify 'test6'
UserDaoHibernate.saveUser(49) | user's id: null
ApplyForm.errMsg(373) | User 'test6' already exists!
ApplyForm.cmApprove(200) | User exists so deleting its newly cre'd cons, Id=
126
And here's the code:
try {
User u2= userManager.getUserByUsername(em);
userExists= true;
} catch (UsernameNotFoundException e) {
userExists= false;
}
if (userExists) {
errMsg("Username "+ em+ " already exists");
return null;
}
log.debug("User "+ em+ " not found, OK, creating cons..."); //DBG
....
log.debug("Saved cons, email= "+ em+ " - its Id= "+ consId);
User usr = new User();
usr.setConsId(consId); // So this user only sees their own cons rec.
usr.setUsername(em);
usr.setPassword(pwd);
usr.setConfirmPassword(pwd);
usr.setEmail(em);
usr.setFirstName(apply.getForename());
usr.setLastName(apply.getSurname());
usr.setPhoneNumber(apply.getPhoneMobile());
usr.setEnabled(true);
// Encrypt pwd...
Boolean encrypt = (Boolean)
getConfiguration().get(Constants.ENCRYPT_PASSWORD);
if (encrypt != null && encrypt.booleanValue()) {
String algorithm = (String)
getConfiguration().get(Constants.ENC_ALGORITHM);
if (algorithm == null) { // should only happen for test case
if (log.isDebugEnabled()) {
log.debug("assuming testcase, setting algorithm to
'SHA'");
}
algorithm = "SHA";
}
usr.setPassword(StringUtil.encodePassword(usr.getPassword(),
algorithm));
}
// Set the default user role on this new user
usr.addRole(roleManager.getRole(Constants.USER_ROLE));
try {
log.debug("About to save user: "+ usr); //DBG
45: userManager.saveUser(usr);
....
} catch (UserExistsException e) {
errMsg(e.getMessage());
log.debug("User exists so deleting its newly cre'd
cons, Id= "+ consId);
consultantManager.removeConsultant(""+ consId);
// redisplay the unencrypted passwords
usr.setPassword(usr.getConfirmPassword());
}
Line 45 throws UserExistsException
--
View this message in context:
http://www.nabble.com/Signup-tf4279429s2369.html#a12180682
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]