I am building a app using Ocsigen
, this app will not be connected to a database and the goal is to copy the content from the main website to here. (i am using curl to do Get requests)
So my problem here is, I am trying to do a "log in" with a user, and I want to build a service that saves to my code the username
and the password
that is introduced by the user. Then I could use the username
and the password
to do the GET request to the main website.
My problem it's only one, I have tried a lot of ways to build a service that saves this two strings but I can't figure out a way.
I did a lot of diferent tries and my last one I did something like the following:
let save_data =
Eliom_registration.Action.create
~meth:
(Eliom_service.Post
(Eliom_parameter.unit,
Eliom_parameter.string "username"))
~path:Eliom_service.No_path
(fun () username -> username)
Based on an example that Ocsigen has on their website but I doesn't work...
I created a form that is successfully executing the services I created, but the service is never doing what I need.
Sorry if I explained badly the situation... Is any idea how to solve this problem? I am going in the wrong way?
Thnx!
PS: I have also tried to edit the Os_services.connect_service form the Ocsigen-Start src folder, and I guess that I have to do a Post Service to this case, but again I failed to do what I want.
I think what you are looking for is Eliom_reference, that is if you wish to keep the information stored for later.
https://ocsigen.org/eliom/api/server/Eliom_reference
I'm a little bit rusty when it comes to Eliom but it would look like this:
let current_username : string option Eliom_reference.eref =
Eliom_reference.eref ~scope:Eliom_common.default_process_scope None
let save_data = Eliom_registration.Action.create
~meth:(Eliom_service.Post
(Eliom_parameter.unit,
Eliom_parameter.string "username"))
~path:(Eliom_service.No_path)
(fun () username -> Eliom_reference.set current_username (Some username))