Forum for discussing general topics related to Couch.
13 posts Page 1 of 2
Hi,
I really need help with this, please. I am trying to insert users from external file (.csv) directly into couch db, which is the only way since they are created there... and I don't know if I am doing it correctly and how actually complicated it really is...
So far I can insert all the other fields but the issue (I hope that's the only one) is encoding the password, with Phpass (I'm sorry, but :lol:), which isn't encoded properly. I can tell as it does not resemble the others created in the backend. This way:
$hasher = new PasswordHash(8, false);
$hash = $hasher->HashPassword($password);
Is this doable at all?
thank you,
malax
Hi, how are you inserting other fields? Are you using CSV importer addon? How many users are there?
So far I can insert all the other fields

I think there is a solution without php, just using couch tags, but need more info :)
thnx for replying. Well, I am using php fgetcsv to get the data and then inserting the records into db table, cause I didn't know you could actually use couch tags for this, it would probably be easier. I would really appreciate if you could help me with this.
As for the number of users, ooh there are A LOT of them, now I'm afraid to say how many.. is that important, is there a limit?
...and this password encoding could it be solved too?
Hi, take a look at this
viewtopic.php?f=5&t=8803&p=17456&hilit=csv+reader+addon#p17456

Passwords can be set/generated while creating a user on the fly. Check out a sample dbf form that creates a user here viewtopic.php?f=8&t=11144 and combine it with csv importer code.
OMG, thank you so much!
CSV addon is pretty straight forward.
Just one thing...could you please just clarify this password setting/generating process: is the encoding of (in your case random) password handled through db_persist_form, upon saving the data? If so, is there a couch tag working as simple INSERT INTO SQL syntax? in order to insert values and encode passwords, if there is no form, directly into couch_users table (in my case), or something like that?
malax wrote: encoding handled through db_persist_form

Exactly. 'db_persist_form' tag is used within a databound form (http://docs.couchcms.com/concepts/databound-forms.html)

However, CSV Importer uses a parent tag - 'db_persist' which can be used anywhere anyhow. All the internal processing of validating data and saving into different couch tables is handled by Couch.

There are many samples of 'db_persist' usage in forum, including the one in CSV Imp docs. Also you may see other tag, 'db_delete' to remove pages.

You may find this code useful for db-related operations viewtopic.php?f=8&t=11085
Sorry to bother you again, I just don't know how to make it work. I was trying to to add users, using extended users addon (kinda same as you did in the form), since there is a clonable masterpage (for db_presist), but all I get is data added as a new row in couch_pages table? Could you please help?Thanks
Code: Select all
<cms:db_persist
_invalidate_cache='0'
_masterpage="users/index.php"
_mode='create'
k_page_title = 'xxx'
extended_user_password = 'xxx'
extended_user_password_repeat = 'xxx'
extended_user_email='xxx'
            />
If you followed the extended users tutorial (viewtopic.php?f=5&t=8581) then 'a new record in couch_pages table' is perfectly okay. This page is an 'extention' to the user in couch_users table (which is expected to be auto created by Couch at the same time). It is meant to hold addtitional editable fields that users might have (e.g. birthday or address).

So, it doesn't actually matter where you manually add a user: in Users section of backend or your template, registered as Extended Users template. The counter-part is always created to reflect the change. Automatically adding a user is possible only to extended users' template with 'db_persist'. It means: if you run the code to add a user to EU template and user doesn't appear in Users section of backend (as well as in couch_users table), then extended users addon is not properly working. Did you follow all the steps in tutorial (registering template before editing config in addon's folder)?

I think the first step would be to make sure addon is properly working. Once you add a page in backend to the users template, it should appear in default Users as well (and vice versa).
Ohh, you're right, I haven't checked (tried just the login.php)...
there is an error where there is a data bound form (register, profile):
ERROR: Tag "input" of type 'bound' needs to be within a Data-bound form
I was just fiddling with login.php, with redirect, other files are not changed, downloaded from the same post you cited.
I don't see any fault in these files (register, profile), what could cause this error?
I don't see any faults in files either, because I don't see the files.

The error message you posted means that there is some cms:input type='bound' which should not be there. It can be only within a databound form, but since you are not using a databound form (rather a simple couch form with 'db_persist' in k_success block), the message gives you a hint about what the problem is.
13 posts Page 1 of 2

Who is online

In total there are 4 users online :: 0 registered, 0 hidden and 4 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 4 guests