Foren
prolem after add user from portlet programaticly
Dax Saw, geändert vor 14 Jahren.
prolem after add user from portlet programaticly
Regular Member Beiträge: 165 Beitrittsdatum: 27.03.09 Neueste Beiträge
Hi
I try create user in my portlet by this code :
the new user appaears in database but i don't see him in control panel ->User (i can't see any users, just empty page).
Bu i can see this users in control_panel->communites-> and assign user roles to any community ->avilable -> and i see all users.
If i want sign in by new created user i couldn't.
Thanks for response.
I try create user in my portlet by this code :
public void processAction(ActionRequest req, ActionResponse res)
throws IOException, PortletException {
ThemeDisplay themeDisplay = (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
String languageID = themeDisplay.getUser().getLanguageId();
long accountID = themeDisplay.getAccount().getAccountId();
TimeZone timeZone = themeDisplay.getTimeZone();
long companyID = themeDisplay.getCompanyId();
long userId;
long contactID;
try {
userId = CounterLocalServiceUtil.increment();
contactID = userId;
contactID = contactID + 1;
System.out.println(userId);
UserLocalServiceUtil.createUser(userId);
User userToCreate = UserUtil.create(userId);
userToCreate.setFirstName("DArek_1");
userToCreate.setLastName("Darek_2");
userToCreate.setPassword("daxdax");
userToCreate.setActive(true);
userToCreate.setCreateDate(new Date());
userToCreate.setModifiedDate(new Date());
userToCreate.setLanguageId(languageID);
userToCreate.setGreeting("H2si drf ");
userToCreate.setCompanyId(companyID);
userToCreate.setContactId(contactID); // o jeden wiekszy niz userID
userToCreate.setReminderQueryQuestion("pytanie");
userToCreate.setReminderQueryAnswer("odpoweidz");
userToCreate.setTimeZoneId(timeZone.getID());
userToCreate.setAgreedToTermsOfUse(true);
Contact contact = ContactLocalServiceUtil.createContact(contactID);
contact.setContactId(contactID);
contact.setUserId(userId);
contact.setAccountId(accountID);
contact.setCompanyId(companyID);
userToCreate.setScreenName("ddzddaasd");
userToCreate.setEmailAddress("aada@notes.pl");
UserLocalServiceUtil.addUser(userToCreate);
ContactLocalServiceUtil.addContact(contact);
UserIndexer.updateUser(userToCreate);
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SearchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
the new user appaears in database but i don't see him in control panel ->User (i can't see any users, just empty page).
Bu i can see this users in control_panel->communites-> and assign user roles to any community ->avilable -> and i see all users.
If i want sign in by new created user i couldn't.
Thanks for response.
Aarti Jain, geändert vor 14 Jahren.
RE: prolem after add user from portlet programaticly
Regular Member Beiträge: 116 Beitrittsdatum: 02.09.08 Neueste Beiträge
Hi Dax,
Better approach to create a user programmatically would be to use the following method:
Regards,
Aarti Jain
Impetus Infotech Pvt. Ltd.
Noida
Better approach to create a user programmatically would be to use the following method:
long creatorUserId = 0;
long companyId = company.getCompanyId();
boolean autoPassword = true;
String password1 = null;
String password2 = null;
boolean autoScreenName = false;
String screenName = "screenName";
String emailAddress = "emailAddress@gmail.com";
String openId = "";
String firstName = "firstName";
String middleName = "middleName";
String lastName = "lastName";
int prefixId = 0;
int suffixId = 0;
boolean male = true;
int birthdayMonth = 2;
int birthdayDay = 21;
int birthdayYear = 1985;
String jobTitle = "jobTitle";
long[] groupIds = null;
long[] organizationIds = null;
long[] roleIds = null;
long[] userGroupIds = null;
boolean sendEmail = true;
ServiceContext serviceContext = new ServiceContext();
try {
UserLocalServiceUtil.addUser(creatorUserId, companyId, autoPassword, password1,password2, autoScreenName, screenName, emailAddress, openId,themeDisplay.getLocale(), firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);
} catch(Exception e){
out.println(e.getMessage());
}
Regards,
Aarti Jain
Impetus Infotech Pvt. Ltd.
Noida
Dax Saw, geändert vor 14 Jahren.
RE: prolem after add user from portlet programaticly
Regular Member Beiträge: 165 Beitrittsdatum: 27.03.09 Neueste Beiträge
Thanks for help Aarti.
It's works fine for me
Regards
DaX
It's works fine for me
Regards
DaX
Ram Anvesh Reddy, geändert vor 14 Jahren.
RE: prolem after add user from portlet programaticly
New Member Beitrag: 1 Beitrittsdatum: 11.08.09 Neueste Beiträge
Hey Aarti,
I'm a complete noob using liferay. I want guests to be able to log into the portal automatically without a login id or password. So i decided to add them as a user programatically with a random id (maybe guest<timestamp>) and automatically generated password and log them in automatically so that they can use the chat portlet in liferay ( it seems impossible to configure this portlet's permissions). can I use the above code? If so what all packages should be imported? Also it would be awesome if you could briefly describe how to deploy the code.
Thanks,
Ram Anvesh
I'm a complete noob using liferay. I want guests to be able to log into the portal automatically without a login id or password. So i decided to add them as a user programatically with a random id (maybe guest<timestamp>) and automatically generated password and log them in automatically so that they can use the chat portlet in liferay ( it seems impossible to configure this portlet's permissions). can I use the above code? If so what all packages should be imported? Also it would be awesome if you could briefly describe how to deploy the code.
Thanks,
Ram Anvesh