Forum OpenACS Development: Create a new user

Collapse
Posted by Iuri Sampaio on
I run the code bellow in the shell at my website:

***************************************
set user_name "test-2006-06-22-22-00"
set first_names "test-2006-06-22-22-00"
set last_name "test-2006-06-22-22-00"
set email "mailto:iuri_sampaio@hotmail.com";
set country "brazil"

set password [ad_generate_random_string]
db_transaction {
array set user_new_info [auth::create_user -username user_name -email email -first_names first_names -last_name last_name -password password]
}
set user_id $user_new_info(user_id)

dotlrn_privacy::set_user_guest_p -user_id $user_id -value "t"
dotlrn::user_add -can_browse -user_id $user_id

set admin_user_id [as::actions::get_admin_user_id]
set administration_name [db_string admin_name "select first_names || ' ' || last_name from persons where person_id = :admin_user_id"]
set system_name [ad_system_name]
set system_url [ad_parameter -package_id [ad_acs_kernel_id] SystemURL ""].
set admin_email [db_string unused "select email from parties where party_id = :admin_user_id"]
set message "$first_names $last_name,
You have been added as a user to $system_name
at $system_url
Login information:
Email: $email
Password: $password
(you may change your password after you log in)
Thank you,
$administration_name"
ns_sendmail "$email" "$admin_email" "You have been added as a user to [ad_system_name] at [ad_url]" "$message"

db_dml insert_country {insert into tbl_countries (parent_user_id, country_name) values (:user_id, :country)}

************************

and i got the follow error message:

************************
ERROR:
can't read "user_new_info(user_id)": no such element in array
while executing
"set user_id $user_new_info(user_id)
"
("uplevel" body line 11)
invoked from within
"uplevel 1 $script"

*****************************
I already checked the proc ad::create_user on API docs. I see user_id is generated by the code. I don;t need to declare it.

So why the error is happening?

Collapse
2: Re: Create a new user (response to 1)
Posted by Ryan Gallimore on
Try looking up auth::create_user proc in api-doc.
It will describe the elements of the array it returns.

Cheers.

Collapse
3: Re: Re: Create a new user (response to 2)
Posted by Iuri Sampaio on
well, i just ran on the shell the followed tcl script:

******
set password [ad_generate_random_string]

db_transaction {
array set user_new_info [auth::create_user -username 'test-2006-06-26' -email 'mailto:iuri.sampaio@hotmail.com'; -first_names 'test-2006-06-26' -last_name 'test-2006-06-26' -password $password]
}
set user_id $user_new_info(user_id)
*********

it returns the user-id. So the script is runing fine, but when i run this chunk in a tcl page such as
inser-new-user.tcl
http://www.myybiz.net:8090/insert-new-user

i got the error message:
any idea??

Server Error
/ home / yabtdev / yabtdev / packages / dotlrn / www / dotlrn-master-kelp
There was a server error processing your request. We apologize.

Take me back where I was (before the error)
can't read "user_new_info(user_id)": no such element in array
while executing
"set user_id $user_new_info(user_id)"
("uplevel" body line 6)
invoked from within
"uplevel #$level $new_data"
("1" arm line 597)
invoked from within
"switch $errno {
0 {
# TCL_OK
}
1 {
# TCL_E..."
(procedure "ad_form" line 611)
invoked from within
"ad_form -name add_new_user_form -show_required_p 1 -form {
user_id:key
{
user_name:text(text)
{label "Username"}
{help..."
("uplevel" body line 9)
invoked from within
"uplevel {
ad_page_contract {
This is the form to insert contact information
@author Iuri Sampaio
} {
id:optional
}

ad_form -name add_new_..."
(procedure "code::tcl::/home/yabtdev/yabtdev/www/insert-new-user" line 2)
invoked from within
"code::tcl::$__adp_stub"
invoked from within
"if { [file exists $__adp_stub.tcl] } {

# ensure that data source preparation procedure exists and is up-to-date
adp_init tcl $__adp_stub
..."
("uplevel" body line 3)
invoked from within
"uplevel {

if { [file exists $__adp_stub.tcl] } {

# ensure that data source preparation procedure exists and is up-to-date
adp_init t..."
(procedure "adp_prepare" line 2)
invoked from within
"adp_prepare "
(procedure "template::adp_parse" line 30)
invoked from within
"template::adp_parse [file root [ad_conn file]] {}"
(procedure "adp_parse_ad_conn_file" line 5)
invoked from within
"$handler"
("uplevel" body line 2)
invoked from within
"uplevel $code"
invoked from within
"ad_try {
$handler
} ad_script_abort val {
# do nothing
}"
invoked from within
"rp_serve_concrete_file [ad_conn file]"
(procedure "rp_serve_abstract_file" line 60)
invoked from within
"rp_serve_abstract_file "$root/$path""
("uplevel" body line 2)
invoked from within
"uplevel $code"
invoked from within
"ad_try {
rp_serve_abstract_file "$root/$path"
set tcl_url2file([ad_conn url]) [ad_conn file]
set tcl_url2path_info..."

Collapse
4: Re: Create a new user (response to 1)
Posted by Gustaf Neumann on
the page is evaluated in the ::template namespace. do an "ns_log notice ns=[namespace current]" in both of your cases, and you will see the difference. The problem should go away when you use ::user_new_info on all occurrences.