Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
sawi _
prolem after add user from portlet programaticly
9. Juli 2009 07:41
Antwort

sawi _

Rang: Regular Member

Nachrichten: 148

Eintrittsdatum: 27. März 2009

Neue Beiträge

Hi
I try create user in my portlet by this code :
 1public void processAction(ActionRequest req, ActionResponse res)
 2            throws IOException, PortletException {
 3       
 4        ThemeDisplay themeDisplay = (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
 5        String languageID = themeDisplay.getUser().getLanguageId();
 6        long accountID = themeDisplay.getAccount().getAccountId();
 7        TimeZone timeZone = themeDisplay.getTimeZone();
 8        long companyID = themeDisplay.getCompanyId();
 9        long userId;
10        long contactID;
11        try {
12            userId = CounterLocalServiceUtil.increment();
13            contactID = userId;
14            contactID = contactID + 1;
15            System.out.println(userId);
16            UserLocalServiceUtil.createUser(userId);
17            User userToCreate = UserUtil.create(userId);
18            userToCreate.setFirstName("DArek_1");
19            userToCreate.setLastName("Darek_2");
20            userToCreate.setPassword("daxdax");
21            userToCreate.setActive(true);
22            userToCreate.setCreateDate(new Date());
23            userToCreate.setModifiedDate(new Date());
24            userToCreate.setLanguageId(languageID);
25            userToCreate.setGreeting("H2si drf ");
26            userToCreate.setCompanyId(companyID);
27            userToCreate.setContactId(contactID);  // o jeden wiekszy niz userID
28            userToCreate.setReminderQueryQuestion("pytanie");
29            userToCreate.setReminderQueryAnswer("odpoweidz");
30            userToCreate.setTimeZoneId(timeZone.getID());
31            userToCreate.setAgreedToTermsOfUse(true);
32            Contact contact = ContactLocalServiceUtil.createContact(contactID);
33            contact.setContactId(contactID);
34            contact.setUserId(userId);
35            contact.setAccountId(accountID);
36            contact.setCompanyId(companyID);
37            userToCreate.setScreenName("ddzddaasd");
38            userToCreate.setEmailAddress("aada@notes.pl");
39            UserLocalServiceUtil.addUser(userToCreate);
40            ContactLocalServiceUtil.addContact(contact);
41            
42       
43             UserIndexer.updateUser(userToCreate);
44            
45            } catch (SystemException e) {
46                // TODO Auto-generated catch block
47                e.printStackTrace();
48            } catch (SearchException e) {
49                // TODO Auto-generated catch block
50                e.printStackTrace();
51            }
52        }
53       



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
RE: prolem after add user from portlet programaticly
9. Juli 2009 09:50
Antwort

Aarti Jain

Rang: Regular Member

Nachrichten: 116

Eintrittsdatum: 2. September 2008

Neue Beiträge

Hi Dax,

Better approach to create a user programmatically would be to use the following method:

 1
 2long creatorUserId = 0;
 3long companyId = company.getCompanyId();
 4boolean autoPassword = true;
 5String password1 = null;
 6String password2 = null;
 7boolean autoScreenName = false;
 8String screenName = "screenName";
 9String emailAddress = "emailAddress@gmail.com";
10String openId = "";
11String firstName = "firstName";
12String middleName = "middleName";
13String lastName = "lastName";
14int prefixId = 0;
15int suffixId = 0;
16boolean male = true;
17int birthdayMonth = 2;
18int birthdayDay = 21;   
19int birthdayYear = 1985;
20String jobTitle = "jobTitle";
21long[] groupIds = null;
22long[] organizationIds = null;
23long[] roleIds = null;
24long[] userGroupIds = null;
25boolean sendEmail = true;   
26ServiceContext serviceContext = new ServiceContext();
27
28try {    
29           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);
30       } catch(Exception e){
31           out.println(e.getMessage());
32         }


Regards,
Aarti Jain
Impetus Infotech Pvt. Ltd.
Noida
sawi _
RE: prolem after add user from portlet programaticly
10. Juli 2009 04:43
Antwort

sawi _

Rang: Regular Member

Nachrichten: 148

Eintrittsdatum: 27. März 2009

Neue Beiträge

Thanks for help Aarti.
It's works fine for me

Regards
DaX
Ram Anvesh Reddy
RE: prolem after add user from portlet programaticly
11. August 2009 01:32
Antwort

Ram Anvesh Reddy

Rang: New Member

Nachrichten: 1

Eintrittsdatum: 11. August 2009

Neue 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