Foros de discusión

I need to assign conditional custom role while creating account by stranger

thumbnail
Omkar Khandare, modificado hace 11 años.

I need to assign conditional custom role while creating account by stranger

Junior Member Mensajes: 49 Fecha de incorporación: 7/03/12 Mensajes recientes
I am calling create account.jsp page from different pages for registration.
i am appending some parameter with it.
e.g.
type=Role 1
or
type=Role 2
as per such parameter i want make user create their account with specific Role which is already predefined by Administrator.

I am currently using hook plugin to override create_account.jsp page,
i have tried with ext plugin also but unable set role for User object before create account action call.

So how should i assign user a specific role rather than a default role i.e. Power User.?

Please Help.
thumbnail
meera prince, modificado hace 11 años.

RE: I need to assign conditional custom role while creating account by stra

Liferay Legend Mensajes: 1111 Fecha de incorporación: 8/02/11 Mensajes recientes
Hi Omkar Khandare,

create_account.jsp you can create select box there you can populate roles according to your parameter.
once user select the the role once he submit take the role and assign to him.

this should work for ext only we cant do in plugin because we need to customize CreataAccountAction.java class


Regards,
Meera Prince
thumbnail
Omkar Khandare, modificado hace 11 años.

I need to assign conditional custom role while creating account by stranger

Junior Member Mensajes: 49 Fecha de incorporación: 7/03/12 Mensajes recientes
I found CreateAccountAction.java source code from web,
Now i am using same with custom role modifications using Struts action override by through hook.
my refe.URL for steps of overriding existing struts action is

http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/lp-6-1-dgen06-overriding-and-adding-struts-actions-0

I kept all source code as it is.

& edited liferay-hook.xml file as given on liferay docs as.

<?xml version="1.0"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.1.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_1_0.dtd">

<hook>
<custom-jsp-dir>/META-INF/custom_jsps</custom-jsp-dir>
<struts-action>
<struts-action-path>/login/create_account</struts-action-path>
<struts-action-impl>com.liferay.portlet.login.action.CreateAccountAction</struts-action-impl>
</struts-action>
</hook>


but getting an exception as follows..

06:52:32,734 INFO [pool-2-thread-29][HookHotDeployListener:550] Registering hook for sa-public-registration-hook
06:52:32,890 ERROR [pool-2-thread-29][HotDeployImpl:191] com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for sa-public-registration-hook
com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for sa-public-registration-hook
at com.liferay.portal.kernel.deploy.hot.BaseHotDeployListener.throwHotDeployException(BaseHotDeployListener.java:46)
at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:276)
at com.liferay.portal.deploy.hot.HotDeployImpl.doFireDeployEvent(HotDeployImpl.java:188)
at com.liferay.portal.deploy.hot.HotDeployImpl.fireDeployEvent(HotDeployImpl.java:96)
at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:27)
at com.liferay.portal.kernel.servlet.PluginContextListener.fireDeployEvent(PluginContextListener.java:151)
at com.liferay.portal.kernel.servlet.PluginContextListener.doPortalInit(PluginContextListener.java:141)
at com.liferay.portal.kernel.util.BasePortalLifecycle.portalInit(BasePortalLifecycle.java:42)
at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:64)
at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:56)
at com.liferay.portal.kernel.util.BasePortalLifecycle.registerPortalLifecycle(BasePortalLifecycle.java:52)
at com.liferay.portal.kernel.servlet.PluginContextListener.contextInitialized(PluginContextListener.java:103)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:649)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1585)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NoClassDefFoundError: com/liferay/portal/struts/PortletAction
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2889)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1170)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
at com.liferay.portal.kernel.util.InstanceFactory.newInstance(InstanceFactory.java:52)
at com.liferay.portal.kernel.util.InstanceFactory.newInstance(InstanceFactory.java:27)
at com.liferay.portal.deploy.hot.HookHotDeployListener.initStrutsAction(HookHotDeployListener.java:2138)
at com.liferay.portal.deploy.hot.HookHotDeployListener.initStrutsActions(HookHotDeployListener.java:2198)
at com.liferay.portal.deploy.hot.HookHotDeployListener.doInvokeDeploy(HookHotDeployListener.java:628)
at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:273)
... 24 more
Caused by: java.lang.ClassNotFoundException: com.liferay.portal.struts.PortletAction
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
... 38 more

Can anyone tell me how to resolve it.
thumbnail
Gnaniyar Zubair, modificado hace 11 años.

RE: I need to assign conditional custom role while creating account by stra

Liferay Master Mensajes: 722 Fecha de incorporación: 19/12/07 Mensajes recientes
Instead of HOOK, EXT plugin will suit for your requirement it seems which have full control.

Extend addUser method of CreateAccountAction.java


1. Define Role Names in property file
2. Get the Role Name in CreateAccountAction from property
Role role = RoleLocalServiceUtil.getRole(company.getCompanyId(), PropsUtil.get("my.custom.role"));


3. After adding the user, just assign

UserLocalServiceUtil.addRoleUsers(role.getRoleId(), userId);
thumbnail
Omkar Khandare, modificado hace 11 años.

RE: I need to assign conditional custom role while creating account by stra

Junior Member Mensajes: 49 Fecha de incorporación: 7/03/12 Mensajes recientes
i have started using ext plugin

i have overriding only addUser method through extending CreateAccount class
my method get called but.

i am getting an exception as follows.

ERROR [http-bio-8080-exec-4][render_portlet_jsp:154] com.liferay.portal.security.auth.PrincipalException
at com.liferay.portal.service.permission.RolePermissionImpl.check(RolePermissionImpl.java:31)
at com.liferay.portal.service.permission.RolePermissionUtil.check(RolePermissionUtil.java:30)
at com.liferay.portal.service.impl.UserServiceImpl.checkRoles(UserServiceImpl.java:1872)
at com.liferay.portal.service.impl.UserServiceImpl.checkAddUserPermission(UserServiceImpl.java:1709)
at com.liferay.portal.service.impl.UserServiceImpl.addUserWithWorkflow(UserServiceImpl.java:456)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:122)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.security.pacl.PACLAdvice.invoke(PACLAdvice.java:51)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
at com.liferay.portal.service.UserServiceUtil.addUserWithWorkflow(UserServiceUtil.java:372)

Plz Help.
thumbnail
meera prince, modificado hace 11 años.

RE: I need to assign conditional custom role while creating account by stra

Liferay Legend Mensajes: 1111 Fecha de incorporación: 8/02/11 Mensajes recientes
HI
To avoid PrincipalException we should call LocalServiceUtil class methods not serviceUtils. Use UserLocalServiceIUtil class instead of UserServiceIUtil .

If use RoleSrviceUtil then use RoleLocalServiceUtils.

Regards,
Meera Prince
http://www.liferaysavvy.com/
thumbnail
Omkar Khandare, modificado hace 11 años.

RE: I need to assign conditional custom role while creating account by stra

Junior Member Mensajes: 49 Fecha de incorporación: 7/03/12 Mensajes recientes
now i am using

UserLocalServiceUtil.addUserWithWorkflow(...)

instead of UserServiceUtil.addUserWithWorkflow(...)

but i dont have two additional parameters values for
1.creatorUserId
2.locale

except these we got all in CreateAccountAction

Now when i submit my form it shows error as

Your request failed to complete

NOT any exception on console..
even i set creatorUserId as Administrator userID from user_ table
& setting locale through LocaleUtil.getDefault()

but still same error on sign in page.

What should i do now.?
thumbnail
meera prince, modificado hace 11 años.

RE: I need to assign conditional custom role while creating account by stra

Liferay Legend Mensajes: 1111 Fecha de incorporación: 8/02/11 Mensajes recientes
HI
Send me your Exception StackTrace.

ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
locale=themeDisplay.getLocale();
creatorUserId=give admin id10169


Regards,
Meera Prince
thumbnail
Omkar Khandare, modificado hace 11 años.

RE: I need to assign conditional custom role while creating account by stra

Junior Member Mensajes: 49 Fecha de incorporación: 7/03/12 Mensajes recientes
Thats a problem that i dont have any stack trace..

but i realized that..
my method giving an error on putting before and after comments everywhere.

my method in addUser method of my EXT plugin class.

User user = UserLocalServiceUtil.addUserWithWorkflow(0, company.getCompanyId(), autoPassword, password1, password2, autoScreenName, screenName, emailAddress, facebookId, openId, locale, firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);

is not executing properly & giving error.

On create account form submission i am only getting error as
Your request failed to complete

on jsp page of create account form.

Please help.
emoticon
thumbnail
meera prince, modificado hace 11 años.

RE: I need to assign conditional custom role while creating account by stra

Liferay Legend Mensajes: 1111 Fecha de incorporación: 8/02/11 Mensajes recientes
Hi place that code inside
try{

User user = UserLocalServiceUtil.addUserWithWorkflow(0, company.getCompanyId(), autoPassword, password1, password2, autoScreenName, screenName, emailAddress, facebookId, openId, locale, firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);
}catch(Exception e){

e.printTrackTrace();
}

Regards,
Meera Prince
thumbnail
meera prince, modificado hace 11 años.

RE: I need to assign conditional custom role while creating account by stra

Liferay Legend Mensajes: 1111 Fecha de incorporación: 8/02/11 Mensajes recientes
HI The following link is example for how to override struts actions,

https://github.com/liferay/liferay-plugins/tree/master/hooks/sample-struts-action-hook


Regards,
Meera Prince