|
|
Index
| Recent Threads
| Who's Online
| User List
| Register
| Search
| Help
| |
Synyx created an OpenCms 7.0.4 Live CD, based on SLAX Linux, which is now available.
If you want to order a free CD copy, please write, including your postal address, to 
![]() |
OpenCms Forum » List all forums » Forum: Questions about Programming » Thread: Add a new User to DB |
|
Thread Status: Normal Total posts in this thread: 7 |
[Add To My Favorites] [Watch this Thread] [Post new Thread] |
| Author |
|
|
Stranger
|
Hello. The USER_ID into DB for guest, admin and export isn't an autoincrement but a code like this 46769c87-e4de-362c-8e3e-4f1d811c3267. I want to generate this code for my users and I don't know how to do. I search online and I found the method AddUser() in the classCmsDbAccess. I Have a nullpointer exception. Someone can help me? Can you write me how to do it? Another question is if I can user a simple USER_ID autoincrement Opencms can give me problem? Sorry for my english. my code: CmsJspActionElement cms = new CmsJspActionElement(pageContext,request, response); CmsRequestContext requestContext= cms.getRequestContext(); CmsDbContext dbContext= new CmsDbContext (requestContext); String configPath = pageContext.getServletContext().getRealPath("/") + "WEB-INF/config/"; CmsConfigurationManager configurationManager = new CmsConfigurationManager(configPath); Map conf = configurationManager.getConfiguration(); String dbName = conf.get(CmsDbPool.KEY_DATABASE_NAME).toString().toLowerCase(); CmsDbAccess dbAccess=new CmsDbAccess(configurationManager.getConfiguration()); |
||
|
|
Stranger
|
sorry. the last rows is a my mistake. String poolUrl = conf.get("db.cos.pool").toString(); CmsDbAccess dbAccess=new CmsDbAccess(poolUrl); can you help me? it's a nullpointer exception. ( for variable "conf") |
||
|
|
Advanced Member Joined: May 7, 2004 Posts: 456 Status: Offline |
Hi, you shouldn't add content to the databases of OpenCms manually. Always use the methods provided in CmsObject, in this case createUser(). Nevertheless, the ids are created by the clas CmsUUID but normally you don't need this. Regards Florian ---------------------------------------- /** * Florian Hopf * Synyx GmbH & Co. KG */ |
||
|
|
Stranger
|
thank you flo. Can you help me with code? I don't found any axamples online |
||
|
|
Stranger
|
I have written this code for create user: CmsDefaultUsers defaultUsers = new CmsDefaultUsers(); CmsObject obj = OpenCms.initCmsObject(defaultUsers.getUserGuest()); String userFqn = "test"; String password = "789456123"; String description = "hello hello"; String configPath = pageContext.getServletContext().getRealPath("/") + "WEB-INF/config/"; CmsConfigurationManager configurationManager = new CmsConfigurationManager(configPath); //Map conf = configurationManager.getConfiguration(); Map additionalInfos= configurationManager.getConfiguration(); obj.createUser(userFqn,password,description ,additionalInfos); btu i have this response: Error org.opencms.security.CmsRoleViolationException: Error adding the user "farfarfarafafar". Reason: Error adding the user "test". Reason: The user "Guest" does not have access to the required "Account manager" role for organizational unit "". |
||
|
|
Stranger
|
maybe I didin't undestand. The code USER_ID with OU is only for user that has a role in opencms? I can insert a normal user into db manually? With a normal Sql code (INSERT INTO.......)?? can you explain me it? regards thank you. Fra |
||
|
|
Stranger
|
I resolve it! this is my code CmsJspActionElement cms = new CmsJspActionElement(pageContext,request, response); CmsDefaultUsers defaultUsers = new CmsDefaultUsers(); CmsObject obj = OpenCms.initCmsObject(defaultUsers.getUserGuest()); String username = "frafra"; String password = "xxxxxxx"; String description = "Mr.frafra number one"; String group = "Guests"; CmsUser user = obj.addWebUser(username, password, group, "Web User", new Hashtable() ); obj.writeWebUser(user); |
||
|
| [Show Printable Version of Thread] [Post new Thread] |