1

Topic: Data submit, login user, how?

Good evening,
we are trying to understand how to submit data to Indicia but we found very few information. We have found only this page http://code.google.com/p/indicia/wiki/D … sionFormat but it's not clear... Anyone could help us to understand how to submit data with API webservice?
Other question: which is the API to call to let user login so to let him post?
Thanks

Carlo Politi - Software Engineer
QuestIT s.r.l.
Home page: www.quest-it.com
E-Mail: politi@quest-it.com - Skype: carlo.politi.questit

2

Re: Data submit, login user, how?

Hi Carlo

Thanks for posting here. Carlo contacted me directly but I asked him to post here so that we could share the answers and get the help of other people on the forum. One piece of information that Carlo did not include is that he wants to submit data from a mobile application.

So far, Carlo, everyone has used the client_helpers library functions in order to submit records to Indicia as shown in the documentation like this.

<?php
if ($_POST) {
  $submission = data_entry_helper::build_sample_occurrence_submission($_POST);
  $response = data_entry_helper::forward_post_to('save', $submission);
  echo data_entry_helper::dump_errors($response);
}
?>

You can examine the source code itself to see exactly what is happening but it looks quite complicated to me and my impression has been that there is more complexity built in to the submission structure than is used so far.

The PlantTracker app posts from the app to an intermediate website (a Drupal website using the iForm module as there is also a web form). The intermediate website takes the post from the app and uses the functions above to forward the record to the Indicia warehouse. The website has to authenticate with the warehouse in order to submit the record but the app user does not log in at all. The records are not associated with a user ID and the person cannot read back their records.

Now the developers at Bristol University are building a new app where the user will be able to login. To do so the user first registers with the intermediate website and establishes a username and password. This website is still using Drupal and can use the EasyLogin module to automatically link the Drupal account to an Indicia user account. The mobile app will still submit records to the intermediate website and it will still forward them to the Warehouse but the app will authenticate with the intermediate website over an https connection and the record will be forwarded with an Indicia User ID.

Since the PlantTracker app needed a website too this was a very efficient solution to the problem. To interface directly with the warehouse you would need to write many of the functions of the client_helpers library within your app so that you could create users, authenticate them and send records. That sounds like quite hard work to me.

Some bits of documentation that might be relevant to logging in a user directly are the user_identifier/get_user_id service for creating users and the login control for authenticating users. Note that all the communication is done under the control of the digest authentication used normally between a website and a warehouse. For an app to do this it would need to have the 'website' password embedded within in it. That poses a modest security issue should the app be reverse engineered.

The developers at Bristol have said several times that they are happy to share their work. This could be very good for you if you are happy with the idea of submitting records via another website rather than direct to the Warehouse.

From this information, Carlo, can you say which method you would like to follow?

Regards,
Jim Bacon.

3

Re: Data submit, login user, how?

Thanks Jim for your reply,
today i was trying to test the login using client_helper but something is not clear. I created the form and the PHP as shown here http://code.google.com/p/indicia/wiki/T … ginControl but the result of  $user_id = $response['user_id']; is always "0" value even if i try with a valid and existing user (i tried with the super user). The version of client_helper is the last, 0.8.1 and the dataware house is the same version. I have seen in "Site building > Modules> List" of Instant Indicia installation the Easy Login is enabled and its version is 6.x-2.0-alpha1
Yesterday we tried to submit an observation following the "TutorialBuildingBasicPage" example but even in this case, nothing arrived on instant indicia or in the datawarehouse. I suppose it's a problem with configuration or maybe the call is filtered...
Any idea? Thanks

Carlo Politi - Software Engineer
QuestIT s.r.l.
Home page: www.quest-it.com
E-Mail: politi@quest-it.com - Skype: carlo.politi.questit

4

Re: Data submit, login user, how?

Hi Carlo

Let us get the Basic Page Tutorial working.
I have just tried it and was successful.
I made some mistakes so it did not work first time.
I found my mistakes by looking in the warehouse log.
The log is in the application\logs folder.
Make sure that $config['log_threshold'] = 4; in the file application\config\config.php
Do you see errors after trying to submit your form?

Jim

5

Re: Data submit, login user, how?

Hi Jim,
i haven't direct access to logs so i cannot verify the errors from form. I continued to try to test the logn page example http://testwarehouse.indicia.org.uk/mod … ontrol.php but i continue to receive a 0 value from response. If i login on Indicia or the warehouse from their login page, all is fine but not from API... I'm in a deadlock...

Carlo Politi - Software Engineer
QuestIT s.r.l.
Home page: www.quest-it.com
E-Mail: politi@quest-it.com - Skype: carlo.politi.questit

6

Re: Data submit, login user, how?

Hi Carlo

You can view the logs online instead. Log in to the warehouse and look in the Admin menu. Select Browse Server Logs.
If it is not present in the menu then ask the warehouse administrator to enable the log_browser module by editing the $config['modules'] array in \application\config.\config.php.

Jim.

7

Re: Data submit, login user, how?

in some way i can login with client_helper method to authenticate, now i have to send observation and image... is there a good/simple example to understand how submit data & image by client_helper?

Carlo Politi - Software Engineer
QuestIT s.r.l.
Home page: www.quest-it.com
E-Mail: politi@quest-it.com - Skype: carlo.politi.questit

8

Re: Data submit, login user, how?

Hi Carlo

Congratulations on getting the login control to work. Can you tell us what the problem was?

Did you get access to the warehouse log?

To send an observation I recommend you continue with the "TutorialBuildingBasicPage". This has been rewritten in the new documentation at https://indicia-docs.readthedocs.org/en … ndex.html. When you have got this working we can add support for images.

Images can be added to samples or occurrences using the file_box method or, if you are adding multiple occurrences with one form, the species_checklist method includes image uploading.

Jim.

9

Re: Data submit, login user, how?

The problem, should be i didn't put the value "email" at the "Identifier Type" in the user in the warehouse. I haven't had access for the moment to all logs so i only made tries with instant indicia and datawarehouse options.

For images, is there a way to send them not picking from a box chooser?

Carlo Politi - Software Engineer
QuestIT s.r.l.
Home page: www.quest-it.com
E-Mail: politi@quest-it.com - Skype: carlo.politi.questit

10

Re: Data submit, login user, how?

Hi

To send an observation using Instant Indicia then I recommend you follow the Tutorial and look at section 5.4.1.

There is a more basic form described in UsingDrupalIForm but this may be out of date.

Have a look at the image_upload method for a simple upload control. This does not allow client-side resizing of images so it hasn't been used for a long time.

Jim.

11

Re: Data submit, login user, how?

I have an other big question related login user. We are seeing that sometimes if we create an user on Instant Indicia, the user is not created on warehoise, if we associate a survey to the user on Instant Indicia, I can see the user on the warehouse but if i try to connect with method  user_helper::authenticate_user from client helper using the username and password in instant indicia, i cannot login  in... any solution? thanks

Carlo Politi - Software Engineer
QuestIT s.r.l.
Home page: www.quest-it.com
E-Mail: politi@quest-it.com - Skype: carlo.politi.questit

12

Re: Data submit, login user, how?

Hi Jim,
the problem is that we should send observation maybe using the client helper via POST so to populate directly from our app, not opening a web form page. So i don't understand if there is a direct call to instant indicia or to warehouse to pas observations...

Carlo Politi - Software Engineer
QuestIT s.r.l.
Home page: www.quest-it.com
E-Mail: politi@quest-it.com - Skype: carlo.politi.questit

13

Re: Data submit, login user, how?

The joy of yesterday is over... i can login via client helper only with an username i don't find in instant indicia or in the warehouse and i cannot see the profile, surely i have deleted it in these days for test but it's the only working user.... neither admin works.... could it be a known issue? is there a workaround? is it possible i'm the only to have problem with login?

Carlo Politi - Software Engineer
QuestIT s.r.l.
Home page: www.quest-it.com
E-Mail: politi@quest-it.com - Skype: carlo.politi.questit

14

Re: Data submit, login user, how?

Hi Carlo.

If you create a Drupal user and you have the EasyLogin moduled enabled then the Drupal user will be associated with an Indicia Warehouse user, if one already exists with a matching email, or a new user will be created. What is the password of that Indicia Warehouse user? I don't know. Maybe there isn't one. Because the user authenticates with Drupal and Drupal authenticates with the Warehouse we have not needed a user password on the warehouse. Without a password user_helper::authenticate_user is not going to work. Maybe you need to create a new function called user_helper::create new user...

As I said in my first post, you may prefer to avoid communicating directly with the warehouse and use an intermediate website, copying the method devloped at Bristol University. The project manager fo the application developement at Bristol is Dave Kilbey.

Is your login problem that you cannot log in to the warehouse website or that you cannot authenticate using the client_helper library?

Jim Bacon.

15

Re: Data submit, login user, how?

Hi Jim, i created an user from instant indicia, set password to him and i can login on instant indicia. on warehouse i don't see this user if i don't set on instant indicia, a survey, for example "Mammiferi" or other and in this case, if i set something, i can see the user in the user list inside warehouse. But... if i try to login with client_helper, i cannot login with any login of any user, the only working is of an user i don't see inside instant indicia and inside warehouse, i don't understand how can client_helper can find this user if i don't see in any lists...

I will try to contact Dave, i'm going mad.....

Carlo Politi - Software Engineer
QuestIT s.r.l.
Home page: www.quest-it.com
E-Mail: politi@quest-it.com - Skype: carlo.politi.questit

16

Re: Data submit, login user, how?

Hi Carlo

You can only login with client_helpers to a user that has a password and that means you may only be able to login to users created on the warehouse directly, not via Instant Indicia.

When an item is deleted from the Indicia Warehouse the database record is marked as deleted but not actually removed. The login module should not allow you to login a user that has been marked as deleted but maybe there is a bug. Since this code is rarely used you may discover problems that no one else has.

Jim.

17

Re: Data submit, login user, how?

Mmmm so if i create an user from Instant Indicia, i cannot use client helper to login? Is it possible the user exists but warehouse doesn't show it to me?

Carlo Politi - Software Engineer
QuestIT s.r.l.
Home page: www.quest-it.com
E-Mail: politi@quest-it.com - Skype: carlo.politi.questit

18

Re: Data submit, login user, how?

Well, I am guessing a little bit but, if you look at the specification of the User Identifier Service used by Easy Login you can see that no password is handed to the warehouse. Obviously without a password you can't use the client helper login. If you like, there is a gap in the code that you may have to fix.

It is unlikely that the user exists but isn't shown. If you had direct access to the warehouse you would look at the users table and see what is actually in the database. Easy login creates the Indicia user on first log in to Drupal I believe. Perhaps you are requesting new accounts, creating a Drupal user, but not logging in as those users.

Jim.

19

Re: Data submit, login user, how?

But it's strange that i cannot login neither with admin account from client helper... and i can login without problem inside instant indicia or warehouse with that account....

Carlo Politi - Software Engineer
QuestIT s.r.l.
Home page: www.quest-it.com
E-Mail: politi@quest-it.com - Skype: carlo.politi.questit

20

Re: Data submit, login user, how?

Hi Carlo
I think because you are trying to get your mobile application connecting directly to the warehouse you are treading on new ground, as other mobile applications developed using Indicia using an intermediary Drupal site as a proxy, so the mobile app logs into Drupal, not the warehouse. At least that is how I understand it.

The user_identifier web service is designed to create a user account on the warehouse effectively to give each recorder a persistent user ID, even across multiple applications. But as Jim pointed out it does not specify the password, as in the usage scenario the user does not actually log in to the warehouse. So, imagine the scenario that we have a website with its own login system, but when the user logs in, the user’s email is sent to the user_identifier web service in order to retrieve a user_id for the warehouse. The website can then keep a copy of that user_id in the user’s account and therefore can submit the user ID with future submissions.

The other web service I see you have been using, site_user/authenticate_user, was actually written by a new developer to the project who wanted to add a facility to allow a warehouse login to be authenticated against from a client website. It is not being used in our sites at the moment though because the user_identifier web service does what we want. So, as I understand it, you are correctly creating a user_id using the user_identifier web service, but then do not have a password so cannot use the authenticate_user web service. If your application development framework has its own login system, then it would make sense to use that and simply store the user_id in the account profile, which is exactly what we do with Drupal. However, if you want to use the warehouse to authenticate as you have been trying, then I suggest you modify the user_identifier service to generate a random password and to return it in the response when a new user is created, thus giving you the ability to log in. If you are able to take a look and submit a patch then let me know.

I hope this all helps,

Best wishes
John

John van Breda
Biodiverse IT

21

Re: Data submit, login user, how?

Hi John,
i should need something to know if an user is or not enabled to submit and then i need to use some information to recognize him so to associate the observation. Regarding creation of user, i create it from the "add user" menu of instant indicia and i set the password from there, not calling directly site_user/authenticate_user. Should i read directly from MySQL table in instant indicia to discover if an user exists and read its ID to use to submit observation? it's just my other idea... i don't know if it can be a right way...

Carlo Politi - Software Engineer
QuestIT s.r.l.
Home page: www.quest-it.com
E-Mail: politi@quest-it.com - Skype: carlo.politi.questit

22

Re: Data submit, login user, how?

Hi Carlo,

When you create a user in Instant Indicia (Drupal) that creates a Drupal user. If you have the Easy Login module enabled then a link to an Indicia warehouse user may be created. This may require that a user is created on the warehouse.

The warehouse username, password and ID is stored in the PostGreSQL database on the warehouse and IS DIFFERENT from the Drupal username, password and ID. You must understand this before you will make things work!!!

A person can register with multiple Instant Indicia websites with different usernames and passwords but EasyLogin ensures that they all use a single warehouse user, provided that the same email address is used at registration.

The User Identifier Service returns the warehouse user ID. The EasyLogin module stores this in the Drupal user profile but it is hidden unless you are logged in to Drupal as administrator. It is this Warehouse user ID that must be submitted with records.

Jim Bacon.

23

Re: Data submit, login user, how?

Hi Jim,
i understand usernames in warehouse are not the same in the instant indicia. Buf if as you say, EasyLogin stores the ID of waerhouse in userprofile, could i read this connecting to instant indicia db, knowing accessing info to its db and reading the ID values to submit when i submit record? is this a possible way or i'm saying silly things? and in case this way is ok, writing my own code to read this ID, the password in instant indicia, is it stored in SHA1 or MD5 or in other ways? if this question is too sensible because regarding security, can you send me a private message? Thanks

Carlo Politi - Software Engineer
QuestIT s.r.l.
Home page: www.quest-it.com
E-Mail: politi@quest-it.com - Skype: carlo.politi.questit

24

Re: Data submit, login user, how?

Hi Carlo,

I am going to use the words Drupal and Warehouse to distinguish between usernames, passwords and IDs. I will not use the words Indicia or Instant Indicia as I think we are getting confused.

Yes, we store the Warehouse User ID in the Drupal user profile so that this value is included when a record is submitted. This happens when data_entry_helper::forward_post_to() callls the function hostsite_get_user_id().

The client_helper library is designed to be independent of the website that uses it (i.e. it does not depend on Drupal) but iform.module provides this function which does exactly what you describe.

You ask about how the "Instant Indicia" (Drupal) password is stored. Drupal is open source so this is not sensitive. But why do you want this? The user submitting the record knows his Drupal password. He may not know his Warehouse password.

If, as John suggested, you modify the user_identifier service to return a random Warehouse password then it would be up to you to store it in Drupal, or any other system, in a safe manner.

Jim Bacon.

25

Re: Data submit, login user, how?

Hi Carlo
One more point to clarify. In order to submit a record, your app will need to know the website ID and password for the website you have registered on the warehouse. In addition, it will need to know the warehouse user ID of the app's user, which as Jim says Drupal stores in the user profile (and it can be obtained via the iform module's hostsite_get_user_id() method).
You will then need to create authentication tokens using the website ID and password. Details on how to do this are at https://indicia-docs.readthedocs.org/en … rview.html
These tokens need to be sent with your submission to the warehouse. You should also attach the warehouse user ID in the URL parameters of the warehouse ID (e.g. the URL of the service call is ...&user_id=10).

Best wishes
John

John van Breda
Biodiverse IT