Index: openacs-4/packages/acs-authentication/tcl/authentication-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-authentication/tcl/authentication-procs.tcl,v diff -u -r1.13 -r1.14 --- openacs-4/packages/acs-authentication/tcl/authentication-procs.tcl 3 Sep 2003 12:37:40 -0000 1.13 +++ openacs-4/packages/acs-authentication/tcl/authentication-procs.tcl 3 Sep 2003 19:45:32 -0000 1.14 @@ -1,5 +1,5 @@ ad_library { - Tcl API for authentication, account management, and password management, + Tcl API for authentication, account management, and account registration. @author Lars Pind (lars@collaobraid.biz) @creation-date 2003-05-13 @@ -8,11 +8,9 @@ namespace eval auth {} namespace eval auth::authentication {} -namespace eval auth::password {} namespace eval auth::registration {} - ##### # # auth namespace public procs @@ -86,10 +84,18 @@ # Concatenate remote account message and local account message into one logical understandable message. # Same with account status: only ok if both are ok. - array set auth_info [auth::authentication::Authenticate \ - -username $username \ - -authority_id $authority_id \ - -password $password] + with_catch errmsg { + array set auth_info [auth::authentication::Authenticate \ + -username $username \ + -authority_id $authority_id \ + -password $password] + } { + set auth_info(auth_status) failed_to_connect + set auth_info(auth_message) "Error invoking the authentication driver." + global errorInfo + ns_log Error "Error invoking authentication driver for authority_id = $authority_id: $errorInfo" + } + # Returns: # auth_info(auth_status) # auth_info(auth_message) @@ -101,7 +107,7 @@ array set default_auth_message { no_account {Unknown username} bad_password {Bad password} - auth_error {Unknown authentication error} + auth_error {Invalid username/password} failed_to_connect {Error communicating with authentication server} } @@ -203,11 +209,14 @@ } ad_proc -public auth::create_user { - {-username:required} - {-password:required} + {-user_id ""} + {-username ""} + {-email ""} {-first_names ""} {-last_name ""} {-email ""} + {-password ""} + {-password_confirm ""} {-url ""} {-secret_question ""} {-secret_answer ""} @@ -218,65 +227,253 @@ @param email_verified_p Whether the local account considers the email to be verified or not. @param member_state Whether the local account has been approved. - + @return Array list containing the following entries:
[auth::authority::get_element -authority_id $authority_id -element pretty_name]: $creation_info(account_message)
[ad_system_name]: $local_account_message
" + } + + # Issue login cookie if login was successful + if { [string equal $creation_info(creation_status) "ok"] && [string equal $creation_info(account_status) "ok"] && [ad_conn user_id] == 0 } { + auth::issue_login -user_id $creation_info(user_id) + } + + return [array get creation_info] } ad_proc -public auth::get_registration_elements { - {-authority_id ""} } { Get the list of required/optional elements for user registration. @return Array-list with two entries, both being a subset of - (username, password_1, password_2, first_names, last_name, email, url, secret_question, secret_answer). + (username, password, first_names, last_name, email, url, secret_question, secret_answer).[_ acs-subsite.lt_Registration_informat_1]
[_ acs-subsite.lt_Please_read_and_follo]
" + + with_catch errmsg { + auth::send_email_verification_email -user_id $user_id + } { + global errorInfo + ns_log Error "auth::get_local_account: Error sending out email verification email to email $email:\n$errorInfo" + set auth_info(account_message) "We got an error sending out the email for email verification" + } + } + + return [array get result] } -ad_proc -public auth::confirm_email { +ad_proc -public auth::set_email_verified { {-user_id:required} } { Update an OpenACS record with the fact that the email address on record was verified. } { db_dml set_email_verified { update users - set email_verified_p = 't' - where user_id = :user_id + set email_verified_p = 't' + where user_id = :user_id } } @@ -449,23 +788,12 @@ # system_name is used in some of the I18N messages set system_name [ad_system_name] switch $member_state { - "approved" { + approved { if { $email_verified_p == "f" } { - - # Lars TODO: Refactor with code in authentication-procs.tcl - - set row_id [auth::get_user_secret_token -user_id $user_id] + set auth_info(account_message) "[_ acs-subsite.lt_Registration_informat]
[_ acs-subsite.lt_Please_read_and_follo]
" - # Send email verification email to user - set confirmation_url [export_vars -base "[ad_url]/register/email-confirm" { row_id }] with_catch errmsg { - ns_sendmail \ - $email \ - $notification_address \ - "[_ acs-subsite.lt_Welcome_to_system_nam]" \ - "[_ acs-subsite.lt_To_confirm_your_regis]" - - set auth_info(account_message) "[_ acs-subsite.lt_Registration_informat]
[_ acs-subsite.lt_Please_read_and_follo]
" + auth::send_email_verification_email -user_id $user_id } { global errorInfo ns_log Error "auth::get_local_account: Error sending out email verification email to email $email:\n$errorInfo" @@ -476,18 +804,21 @@ set auth_info(account_status) "ok" } } - "banned" { + banned { set auth_info(account_message) [_ acs-subsite.lt_Sorry_but_it_seems_th] } - "deleted" { - set auth_info(account_message) "[_ acs-subsite.Welcome_Back_1] [_ acs-subsite.to_site_link_1]." + deleted { + set auth_info(account_message) \ + "[_ acs-subsite.Welcome_Back_1] [_ acs-subsite.to_site_link_1]." } - "rejected" - "needs_approval" { - set auth_info(account_message) "[_ acs-subsite.lt_registration_request_submitted]
[_ acs-subsite.Thank_you]
" + rejected - needs_approval { + set auth_info(account_message) \ + "[_ acs-subsite.lt_registration_request_submitted]
[_ acs-subsite.Thank_you]
" } default { - set auth_info(account_message) "There was a problem authenticating the account: $user_id. Most likely, the database contains users with no user_state." - ns_log Warning "Problem with registration state machine on user-login.tcl" + set auth_info(account_message) \ + "There was a problem authenticating the account: $user_id. Most likely, the database contains users with no member_state." + ns_log Error "Problem with registration state machine: user_id $user_id has member_state '$member_state'" } } set auth_info(user_id) $user_id @@ -503,56 +834,57 @@ return [db_string select_secret_token {}] } +ad_proc -private auth::send_email_verification_email { + -user_id:required +} { + Sends out an email to the user that lets them verify their email. + Throws an error if we couldn't send out the email. +} { + # These are used in the messages below + set token [auth::get_user_secret_token -user_id $user_id] + set confirmation_url [export_vars -base "[ad_url]/register/email-confirm" { token user_id }] + set system_name [ad_system_name] + + ns_sendmail \ + $email \ + [parameter::get -parameter NewRegistrationEmailAddress -default [ad_system_owner]] \ + [_ acs-subsite.lt_Welcome_to_system_nam] \ + [_ acs-subsite.lt_To_confirm_your_regis] +} + + ##### # # auth::authentication # ##### ad_proc -private auth::authentication::Authenticate { - {-authority_id ""} + {-authority_id:required} {-username:required} {-password:required} } { Invoke the Authenticate service contract operation for the given authority. - @param authority_id The ID of the authority to ask to verify the user. Defaults to local authority. + @param authority_id The ID of the authority to ask to verify the user. @param username Username of the user. @param passowrd The password as the user entered it. } { - if { [empty_string_p $authority_id] } { - set authority_id [auth::authority::local] - } { - # Check that the authority exists - set authority_exists_p [db_string authority_exists_p { - select count(*) - from auth_authorities - where authority_id = :authority_id - }] - - if { ! $authority_exists_p } { - set auth_info(auth_status) auth_error - set auth_info(auth_message) "Internal error - authority with id $authority_id does not exist" - - return [array get auth_info] - } - } - - set impl_name [auth::authority::get_element -authority_id $authority_id -element "auth_impl_name"] set impl_id [auth::authority::get_element -authority_id $authority_id -element "auth_impl_id"] if { [empty_string_p $impl_id] } { - # Invalid authority - return {} + # No implementation of authentication + set authority_pretty_name [auth::authority::get_element -authority_id $authority_id -element "pretty_name"] + error "The authority '$authority_pretty_name' doesn't support authentication" } set parameters [auth::driver::get_parameter_values \ -authority_id $authority_id \ -impl_id $impl_id] return [acs_sc::invoke \ - -contract "auth_authentication" \ - -impl $impl_name \ + -error \ + -impl_id $impl_id \ -operation Authenticate \ -call_args [list $username $password $parameters]] } @@ -564,9 +896,9 @@ ##### ad_proc -private auth::registration::Register { - {-authority_id ""} - {-username:required} - {-password:required} + {-authority_id:required} + {-username ""} + {-password ""} {-first_names ""} {-last_name ""} {-email ""} @@ -581,20 +913,21 @@ @secret_question Question to ask on forgotten password @secret_answer Answer to forgotten password question } { - if { [empty_string_p $authority_id] } { - set authority_id [auth::authority::local] + set impl_id [auth::authority::get_element -authority_id $authority_id -element "register_impl_id"] + + if { [empty_string_p $impl_id] } { + # No implementation of authentication + set authority_pretty_name [auth::authority::get_element -authority_id $authority_id -element "pretty_name"] + error "The authority '$authority_pretty_name' doesn't support account registration" } - set impl_name [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_name"] - set impl_id [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_id"] - set parameters [auth::driver::get_parameter_values \ -authority_id $authority_id \ -impl_id $impl_id] return [acs_sc::invoke \ - -contract "auth_registration" \ - -impl $impl_name \ + -error \ + -impl_id $impl_id \ -operation Register \ -call_args [list $parameters \ $username \ @@ -609,575 +942,27 @@ } ad_proc -private auth::registration::GetElements { - {-authority_id ""} -} { - - @author Peter Marklund -} { - if { [empty_string_p $authority_id] } { - set authority_id [auth::authority::local] - } - - set impl_name [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_name"] - set impl_id [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_id"] - - - set parameters [auth::driver::get_parameter_values \ - -authority_id $authority_id \ - -impl_id $impl_id] - - return [acs_sc::invoke \ - -contract "auth_registration" \ - -impl $impl_name \ - -operation GetElements \ - -call_args [list $parameters]] -} - - -##### -# -# auth::password public procs -# -##### - -ad_proc -public auth::password::get_change_url { - {-user_id:required} -} { - Returns the URL to redirect to for changing passwords. If the - user's authority has a "change_pwd_url" set, it'll return that, - otherwise it'll return a link to /user/password-update under the - nearest subsite. - - @param user_id The ID of the user whose password you want to change. - - @return A URL that can be linked to for changing password. -} { - db_1row select_vars { - select aa.change_pwd_url, - u.username - from auth_authorities aa, - users u - where aa.authority_id = u.authority_id - and u.user_id = :user_id - } - - # Interpolate any username variable in URL - regsub -all "{username}" $change_pwd_url $username change_pwd_url - - # Default to the OpenACS change password URL - if { [empty_string_p $change_pwd_url] } { - set change_pwd_url "[subsite::get_element -element url]user/password-update?[export_vars { user_id }]" - } - - return $change_pwd_url -} - -ad_proc -public auth::password::can_change_p { - {-user_id:required} -} { - Returns whether the given user change password. - This depends on the user's authority and the configuration of that authority. - - @param user_id The ID of the user whose password you want to change. - - @return 1 if the user can change password, 0 otherwise. -} { - # TODO: Should we use acs_user::get here? Can we cache that proc? - set authority_id [db_string authority_id_from_user_id { - select authority_id - from users - where user_id = :user_id - }] - - return [auth::password::CanChangePassword -authority_id $authority_id] -} - -ad_proc -public auth::password::change { - {-user_id:required} - {-old_password:required} - {-new_password:required} -} { - Change the user's password. - - @param user_id The ID of the user whose password you want to change. - - @param old_password The current password of that user. This is required for security purposes. - - @param new_password The desired new password of the user. - - @return An array list with the following entries: - ---" -} - -ad_proc -private auth::password::CanChangePassword { - {-authority_id ""} -} { - Can users change password for a given authority. - - @param authority_id The ID of the authority that we are inquiring about. Defaults to local - - @author Peter Marklund -} { - if { [empty_string_p $authority_id] } { - set authority_id [auth::authority::local] + if { [empty_string_p $impl_id] } { + # No implementation of authentication + set authority_pretty_name [auth::authority::get_element -authority_id $authority_id -element "pretty_name"] + error "The authority '$authority_pretty_name' doesn't support account registration" } - set impl_name [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_name"] - set impl_id [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_id"] - - set parameters [auth::driver::get_parameter_values \ -authority_id $authority_id \ -impl_id $impl_id] return [acs_sc::invoke \ - -contract "auth_password" \ - -impl $impl_name \ - -operation CanChangePassword \ + -error \ + -impl_id $impl_id \ + -operation GetElements \ -call_args [list $parameters]] } -ad_proc -private auth::password::CanRetrievePassword { - {-authority_id ""} -} { - Can users retrieve password for a given authority. - @param authority_id The ID of the authority that we are inquiring about. Defaults to local - - @author Peter Marklund -} { - if { [empty_string_p $authority_id] } { - set authority_id [auth::authority::local] - } - - set impl_name [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_name"] - set impl_id [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_id"] - - - set parameters [auth::driver::get_parameter_values \ - -authority_id $authority_id \ - -impl_id $impl_id] - - return [acs_sc::invoke \ - -contract "auth_password" \ - -impl $impl_name \ - -operation CanRetrievePassword \ - -call_args [list $parameters]] -} - -ad_proc -private auth::password::CanResetPassword { - {-authority_id ""} -} { - Can users reset password for a given authority. - - @param authority_id The ID of the authority that we are inquiring about. Defaults to local - - @author Peter Marklund -} { - if { [empty_string_p $authority_id] } { - set authority_id [auth::authority::local] - } - - set impl_name [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_name"] - set impl_id [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_id"] - - set parameters [auth::driver::get_parameter_values \ - -authority_id $authority_id \ - -impl_id $impl_id] - - return [acs_sc::invoke \ - -contract "auth_password" \ - -impl $impl_name \ - -operation CanResetPassword \ - -call_args [list $parameters]] -} - -ad_proc -private auth::password::ChangePassword { - {-username:required} - {-old_password:required} - {-new_password:required} - {-authority_id ""} -} { - Change the password of a user. - - @param username - @param old_password - @param new_password - @param authority_id The ID of the authority the user belongs to. Defaults to local - - @author Peter Marklund -} { - if { [empty_string_p $authority_id] } { - set authority_id [auth::authority::local] - } - - set impl_name [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_name"] - set impl_id [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_id"] - - set parameters [auth::driver::get_parameter_values \ - -authority_id $authority_id \ - -impl_id $impl_id] - - return [acs_sc::invoke \ - -contract "auth_password" \ - -impl $impl_name \ - -operation ChangePassword \ - -call_args [list $username \ - $old_password \ - $new_password \ - $parameters]] -} - -ad_proc -private auth::password::RetrievePassword { - {-username:required} - {-authority_id ""} -} { - Retrieve the password of a user. - - @param username - @param authority_id The ID of the authority the user belongs to. Defaults to local - - @author Peter Marklund -} { - if { [empty_string_p $authority_id] } { - set authority_id [auth::authority::local] - } - - set impl_name [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_name"] - set impl_id [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_id"] - - set parameters [auth::driver::get_parameter_values \ - -authority_id $authority_id \ - -impl_id $impl_id] - - return [acs_sc::invoke \ - -contract "auth_password" \ - -impl $impl_name \ - -operation RetrievePassword \ - -call_args [list $username \ - $parameters]] -} - -ad_proc -private auth::password::ResetPassword { - {-username:required} - {-authority_id ""} -} { - Reset the password of a user. - - @param username - @param authority_id The ID of the authority the user belongs to. Defaults to local - - @author Peter Marklund -} { - if { [empty_string_p $authority_id] } { - set authority_id [auth::authority::local] - } - - set impl_name [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_name"] - set impl_id [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_id"] - - set parameters [auth::driver::get_parameter_values \ - -authority_id $authority_id \ - -impl_id $impl_id] - - return [acs_sc::invoke \ - -contract "auth_password" \ - -impl $impl_name \ - -operation ResetPassword \ - -call_args [list $username \ - $parameters]] -} Index: openacs-4/packages/acs-authentication/tcl/driver-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-authentication/tcl/driver-procs-oracle.xql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/acs-authentication/tcl/driver-procs-oracle.xql 2 Sep 2003 11:35:01 -0000 1.1 +++ openacs-4/packages/acs-authentication/tcl/driver-procs-oracle.xql 3 Sep 2003 19:45:32 -0000 1.2 @@ -3,15 +3,23 @@- $errmsg --
[_ acs-subsite.lt_Registration_informat_1]
[_ acs-subsite.lt_Please_read_and_follo]
" - - set row_id [auth::get_user_secret_token -user_id $user_id] - - # Lars TODO: Refactor with code in authentication-procs.tcl - - # Send email verification email to user - set confirmation_url [export_vars -base "[ad_url]/register/email-confirm" { row_id }] - with_catch errmsg { - ns_sendmail \ - $email \ - $notification_address \ - "[_ acs-subsite.lt_Welcome_to_system_nam]" \ - "[_ acs-subsite.lt_To_confirm_your_regis]" - } { - global errorInfo - ns_log Error "auth::get_local_account: Error sending out email verification email to email $email:\n$errorInfo" - set auth_info(account_message) "We got an error sending out the email for email verification" - } - - } else { - set email_verified_p "t" - } - # Send password confirmation email to user - if { [parameter::get -parameter RegistrationProvidesRandomPasswordP -default 0] || \ + if { $generated_pwd_p || \ + [parameter::get -parameter RegistrationProvidesRandomPasswordP -default 0] || \ [parameter::get -parameter EmailRegistrationConfirmationToUserP -default 0] } { with_catch errmsg { ns_sendmail \ $email \ - $notification_address \ - "[_ acs-subsite.lt_Welcome_to_system_nam]" \ - "[_ acs-subsite.lt_Thank_you_for_visitin]" + [parameter::get -parameter NewRegistrationEmailAddress -default [ad_system_owner]] \ + [_ acs-subsite.lt_Welcome_to_system_nam] \ + [_ acs-subsite.lt_Thank_you_for_visitin] } { - ns_returnerror "500" "$errmsg" - ns_log Warning "Error sending registration confirmation to $email. Error: $errmsg" + # We don't fail hard here, just log an error + global errorInfo + ns_log Error "Error sending registration confirmation to $email.\n$errorInfo" } } # Notify admin on new registration - if {[ad_parameter NotifyAdminOfNewRegistrationsP "security" 0]} { + if { [ad_parameter NotifyAdminOfNewRegistrationsP "security" 0] } { with_catch errmsg { ns_sendmail \ - $notification_address \ + [parameter::get -parameter NewRegistrationEmailAddress -default [ad_system_owner]] \ $email \ - "[_ acs-subsite.lt_New_registration_at_s]" \ - "[_ acs-subsite.lt_first_names_last_name]" + [_ acs-subsite.lt_New_registration_at_s] \ + [_ acs-subsite.lt_first_names_last_name] } { - ns_returnerror "500" "$errmsg" - ns_log Warning "Error sending admin notification to $notification_address. Error: $errmsg" + # We don't fail hard here, just log an error + global errorInfo + ns_log Error "Error sending admin notification to $notification_address.\n$errorInfo" } } - return [array get result] } Index: openacs-4/packages/acs-authentication/tcl/password-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-authentication/tcl/password-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-authentication/tcl/password-procs.tcl 3 Sep 2003 19:45:32 -0000 1.1 @@ -0,0 +1,562 @@ +ad_library { + Tcl API for password management. + + @author Lars Pind (lars@collaobraid.biz) + @creation-date 2003-09-03 + @cvs-id $Id: password-procs.tcl,v 1.1 2003/09/03 19:45:32 lars Exp $ +} + + +namespace eval auth::password {} + + +##### +# +# auth::password public procs +# +##### + +ad_proc -public auth::password::get_change_url { + {-user_id:required} +} { + Returns the URL to redirect to for changing passwords. If the + user's authority has a "change_pwd_url" set, it'll return that, + otherwise it'll return a link to /user/password-update under the + nearest subsite. + + @param user_id The ID of the user whose password you want to change. + + @return A URL that can be linked to for changing password. +} { + db_1row select_vars { + select aa.change_pwd_url, + u.username + from auth_authorities aa, + users u + where aa.authority_id = u.authority_id + and u.user_id = :user_id + } + + # Interpolate any username variable in URL + regsub -all "{username}" $change_pwd_url $username change_pwd_url + + # Default to the OpenACS change password URL + if { [empty_string_p $change_pwd_url] } { + set change_pwd_url "[subsite::get_element -element url]user/password-update?[export_vars { user_id }]" + } + + return $change_pwd_url +} + +ad_proc -public auth::password::can_change_p { + {-user_id:required} +} { + Returns whether the given user change password. + This depends on the user's authority and the configuration of that authority. + + @param user_id The ID of the user whose password you want to change. + + @return 1 if the user can change password, 0 otherwise. +} { + # TODO: Should we use acs_user::get here? Can we cache that proc? + set authority_id [db_string authority_id_from_user_id { + select authority_id + from users + where user_id = :user_id + }] + + return [auth::password::CanChangePassword -authority_id $authority_id] +} + +ad_proc -public auth::password::change { + {-user_id:required} + {-old_password:required} + {-new_password:required} +} { + Change the user's password. + + @param user_id The ID of the user whose password you want to change. + + @param old_password The current password of that user. This is required for security purposes. + + @param new_password The desired new password of the user. + + @return An array list with the following entries: + +++" +} + +ad_proc -private auth::password::CanChangePassword { + {-authority_id ""} +} { + Can users change password for a given authority. + + @param authority_id The ID of the authority that we are inquiring about. Defaults to local + + @author Peter Marklund +} { + if { [empty_string_p $authority_id] } { + set authority_id [auth::authority::local] + } + + set impl_name [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_name"] + set impl_id [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_id"] + + + set parameters [auth::driver::get_parameter_values \ + -authority_id $authority_id \ + -impl_id $impl_id] + + return [acs_sc::invoke \ + -contract "auth_password" \ + -impl $impl_name \ + -operation CanChangePassword \ + -call_args [list $parameters]] +} + +ad_proc -private auth::password::CanRetrievePassword { + {-authority_id ""} +} { + Can users retrieve password for a given authority. + + @param authority_id The ID of the authority that we are inquiring about. Defaults to local + + @author Peter Marklund +} { + if { [empty_string_p $authority_id] } { + set authority_id [auth::authority::local] + } + + set impl_name [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_name"] + set impl_id [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_id"] + + + set parameters [auth::driver::get_parameter_values \ + -authority_id $authority_id \ + -impl_id $impl_id] + + return [acs_sc::invoke \ + -contract "auth_password" \ + -impl $impl_name \ + -operation CanRetrievePassword \ + -call_args [list $parameters]] +} + +ad_proc -private auth::password::CanResetPassword { + {-authority_id ""} +} { + Can users reset password for a given authority. + + @param authority_id The ID of the authority that we are inquiring about. Defaults to local + + @author Peter Marklund +} { + if { [empty_string_p $authority_id] } { + set authority_id [auth::authority::local] + } + + set impl_name [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_name"] + set impl_id [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_id"] + + set parameters [auth::driver::get_parameter_values \ + -authority_id $authority_id \ + -impl_id $impl_id] + + return [acs_sc::invoke \ + -contract "auth_password" \ + -impl $impl_name \ + -operation CanResetPassword \ + -call_args [list $parameters]] +} + +ad_proc -private auth::password::ChangePassword { + {-username:required} + {-old_password:required} + {-new_password:required} + {-authority_id ""} +} { + Change the password of a user. + + @param username + @param old_password + @param new_password + @param authority_id The ID of the authority the user belongs to. Defaults to local + + @author Peter Marklund +} { + if { [empty_string_p $authority_id] } { + set authority_id [auth::authority::local] + } + + set impl_name [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_name"] + set impl_id [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_id"] + + set parameters [auth::driver::get_parameter_values \ + -authority_id $authority_id \ + -impl_id $impl_id] + + return [acs_sc::invoke \ + -contract "auth_password" \ + -impl $impl_name \ + -operation ChangePassword \ + -call_args [list $username \ + $old_password \ + $new_password \ + $parameters]] +} + +ad_proc -private auth::password::RetrievePassword { + {-username:required} + {-authority_id ""} +} { + Retrieve the password of a user. + + @param username + @param authority_id The ID of the authority the user belongs to. Defaults to local + + @author Peter Marklund +} { + if { [empty_string_p $authority_id] } { + set authority_id [auth::authority::local] + } + + set impl_name [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_name"] + set impl_id [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_id"] + + set parameters [auth::driver::get_parameter_values \ + -authority_id $authority_id \ + -impl_id $impl_id] + + return [acs_sc::invoke \ + -contract "auth_password" \ + -impl $impl_name \ + -operation RetrievePassword \ + -call_args [list $username \ + $parameters]] +} + +ad_proc -private auth::password::ResetPassword { + {-username:required} + {-authority_id ""} +} { + Reset the password of a user. + + @param username + @param authority_id The ID of the authority the user belongs to. Defaults to local + + @author Peter Marklund +} { + if { [empty_string_p $authority_id] } { + set authority_id [auth::authority::local] + } + + set impl_name [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_name"] + set impl_id [auth::authority::get_element -authority_id $authority_id -element "pwd_impl_id"] + + set parameters [auth::driver::get_parameter_values \ + -authority_id $authority_id \ + -impl_id $impl_id] + + return [acs_sc::invoke \ + -error \ + -contract "auth_password" \ + -impl $impl_name \ + -operation ResetPassword \ + -call_args [list $username \ + $parameters]] +} Index: openacs-4/packages/acs-authentication/tcl/test/acs-authentication-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-authentication/tcl/test/acs-authentication-procs.tcl,v diff -u -r1.13 -r1.14 --- openacs-4/packages/acs-authentication/tcl/test/acs-authentication-procs.tcl 3 Sep 2003 12:37:40 -0000 1.13 +++ openacs-4/packages/acs-authentication/tcl/test/acs-authentication-procs.tcl 3 Sep 2003 19:45:33 -0000 1.14 @@ -84,7 +84,7 @@ -username $username \ -password $password] - aa_equals "auth_status for bad authority_id authentication" $auth_info(auth_status) "auth_error" + aa_equals "auth_status for bad authority_id authentication" $auth_info(auth_status) "failed_to_connect" aa_true "auth_message for bad authority_id authentication" ![empty_string_p $auth_info(auth_message)] # Closed account status @@ -124,52 +124,88 @@ aa_run_with_teardown \ -rollback \ -test_code { + + # Successful creation + array set user_info [auth::create_user \ + -username "auth_create_user1" \ + -email "auth_create_user1@test_user.com" \ + -first_names "Test" \ + -last_name "User" \ + -password "changeme" \ + -password_confirm "changeme" \ + -secret_question "no_question" \ + -secret_answer "no_answer"] - # Successful creation - array set user_info [auth::create_user \ - -username "auth_create_user1" \ - -email "auth_create_user1@test_user.com" \ - -first_names "Test" \ - -last_name "User" \ - -password "changeme" \ - -secret_question "no_question" \ - -secret_answer "no_answer"] + aa_true "returns creation_status" [info exists user_info(creation_status)] - aa_true "returns user_id" [info exists user_info(user_id)] + if { [info exists user_info(creation_status)] } { + aa_equals "creation_status for successful creation" $user_info(creation_status) "ok" + + if { ![string equal $user_info(creation_status) "ok"] } { + aa_log "Element messages: '$user_info(element_messages)'" + aa_log "Element messages: '$user_info(creation_message)'" + } + } - if { [info exists user_info(user_id)] } { - aa_true "returns integer user_id ([array get user_info])" [regexp {[1-9][0-9]*} $user_info(user_id)] - } + aa_false "No creation_message for successful creation" [exists_and_not_null user_info(creation_message)] + aa_true "returns user_id" [info exists user_info(user_id)] + + if { [info exists user_info(user_id)] } { + aa_true "returns integer user_id ([array get user_info])" [regexp {[1-9][0-9]*} $user_info(user_id)] + } + + + # Missing first_names + array unset user_info + array set user_info [auth::create_user \ + -username "auth_create_user2" \ + -email "auth_create_user2@test_user.com" \ + -first_names "" \ + -last_name "User" \ + -password "changeme" \ + -password_confirm "changeme" \ + -secret_question "no_question" \ + -secret_answer "no_answer"] + + aa_equals "creation_status for missing first names" $user_info(creation_status) "data_error" + + aa_true "element_messages exists" [exists_and_not_null user_info(element_messages)] + if { [exists_and_not_null user_info(element_messages)] } { + array unset elm_msgs + array set elm_msgs $user_info(element_messages) + aa_true "element_message for first_names exists" [exists_and_not_null elm_msgs(first_names)] + + } + + if { [info exists user_info(element_messages)] } { + array set element_message $user_info(element_messages) + aa_log "user_info(element_messages) = '$user_info(element_messages)'" + aa_true "Element message for first_names exists" [exists_and_not_null element_message(first_names)] + } - aa_true "returns creation_status" [info exists user_info(creation_status)] - if { [info exists user_info(creation_status)] } { - aa_equals "creation_status for successful creation" $user_info(creation_status) "ok" - } - - aa_false "No creation_message for successful creation" [exists_and_not_null user_info(creation_message)] + # Duplicate email and username + array unset user_info + array set user_info [auth::create_user \ + -username "auth_create_user1" \ + -email "auth_create_user1@test_user.com" \ + -first_names "Test3" \ + -last_name "User" \ + -password "changeme" \ + -password_confirm "changeme" \ + -secret_question "no_question" \ + -secret_answer "no_answer"] - # Missing first_names - array unset user_info - array set user_info [auth::create_user \ - -username "auth_create_user2" \ - -email "auth_create_user2@test_user.com" \ - -first_names "" \ - -last_name "User" \ - -password "changeme" \ - -secret_question "no_question" \ - -secret_answer "no_answer"] - - aa_equals "creation_status for missing first names" $user_info(creation_status) "data_error" - - aa_true "element_messages exists" [exists_and_not_null user_info(element_messages)] - - if { [info exists user_info(element_messages)] } { - array set element_message $user_info(element_messages) - aa_log "user_info(element_messages) = '$user_info(element_messages)'" - aa_true "Element message for first_names exists" [exists_and_not_null element_message(first_names)] - } - - } + aa_equals "creation_status for duplicate email and username" $user_info(creation_status) "data_error" + + aa_true "element_messages exists" [exists_and_not_null user_info(element_messages)] + if { [exists_and_not_null user_info(element_messages)] } { + array unset elm_msgs + array set elm_msgs $user_info(element_messages) + aa_true "element_message for username exists" [exists_and_not_null elm_msgs(username)] + aa_true "element_message for email exists" [exists_and_not_null elm_msgs(email)] + } + + } } aa_register_case auth_confirm_email { @@ -198,8 +234,10 @@ } { array set element_array [auth::get_registration_elements] - aa_true "there is more than one required element: ($element_array(required))" [expr [llength $element_array(required)] > 0] - aa_true "there is more than one optional element: ($element_array(optional))" [expr [llength $element_array(optional)] > 0] + aa_log "Elements array: '[array get element_array]'" + + aa_true "there is more than one required element" [expr [llength $element_array(required)] > 0] + aa_true "there is more than one optional element" [expr [llength $element_array(optional)] > 0] } aa_register_case auth_get_registration_form_elements { @@ -353,36 +391,45 @@ -test_code { array set test_user { username "test_username" + email "test_username@test.test" password "test_password" first_names "test_first_names" last_name "test_last_name" } array set create_result [auth::create_user \ -username $test_user(username) \ + -email $test_user(email) \ -password $test_user(password) \ -first_names $test_user(first_names) \ - -last_name $test_user(last_name)] + -last_name $test_user(last_name) \ + -secret_question "foo" \ + -secret_answer "bar"] aa_equals "status should be ok for creating user" $create_result(creation_status) "ok" - + if { ![string equal $create_result(creation_status) "ok"] } { + aa_log "Create-result: '[array get create_result]'" + } array set reset_result [auth::password::reset \ -authority_id [auth::authority::local] \ -username $test_user(username)] aa_equals "status should be ok for reseting password" $reset_result(password_status) "ok" - - array set auth_result [auth::authentication::Authenticate \ - -username $test_user(username) \ - -authority_id [auth::authority::local] \ - -password $reset_result(password)] - aa_equals "can authenticate with new password" $auth_result(auth_status) "ok" + aa_true "Result contains new password" [info exists reset_result(password)] - array unset auth_result - array set auth_result [auth::authentication::Authenticate \ - -username $test_user(username) \ - -authority_id [auth::authority::local] \ - -password $test_user(password)] - aa_false "cannot authenticate with old password" [string equal $auth_result(auth_status) "ok"] + if { [info exists reset_result(password)] } { + array set auth_result [auth::authentication::Authenticate \ + -username $test_user(username) \ + -authority_id [auth::authority::local] \ + -password $reset_result(password)] + aa_equals "can authenticate with new password" $auth_result(auth_status) "ok" + + array unset auth_result + array set auth_result [auth::authentication::Authenticate \ + -username $test_user(username) \ + -authority_id [auth::authority::local] \ + -password $test_user(password)] + aa_false "cannot authenticate with old password" [string equal $auth_result(auth_status) "ok"] + } } } @@ -490,79 +537,60 @@ aa_run_with_teardown \ -rollback \ -test_code { - db_1row select_vars { - select auth_impl_id as impl_id, - authority_id - from auth_authorities - where short_name = 'local' - } + auth::authority::get -authority_id [auth::authority::local] -array authority - set key "foo" - set value "bar" + set parameter [ad_generate_random_string] + set value [ad_generate_random_string] - db_dml insert_test_parameter { - insert into auth_driver_params( - impl_id, authority_id, key, value - ) values ( - :impl_id, :authority_id, :key, :value - ) - } + # Set a parameter value + auth::driver::set_parameter_value \ + -authority_id $authority(authority_id) \ + -impl_id $authority(auth_impl_id) \ + -parameter $parameter \ + -value $value - set values [auth::driver::get_parameter_values \ - -impl_id $impl_id \ - -authority_id $authority_id] + set authority_id $authority(authority_id) + set impl_id $authority(auth_impl_id) - aa_true "Did get_parameter return the correct value?" [string equal $values "bar"] - } -} + set db_value [db_string select_value { + select value + from auth_driver_params + where impl_id = :impl_id + and authority_id = :authority_id + and key = :parameter + }] -aa_register_case auth_driver_set_parameter_value { - Test the auth::driver::set_parameter_value proc. + aa_log "Parameter value in DB: '$db_value'" - @author Simon Carstensen (simon@collaboraid.biz) -} { - aa_run_with_teardown \ - -rollback \ - -test_code { - - db_1row select_vars { - select auth_impl_id as impl_id, - authority_id - from auth_authorities - where short_name = 'local' - } + set values [auth::driver::get_parameter_values \ + -authority_id $authority(authority_id) \ + -impl_id $authority(auth_impl_id)] - set key "foo" - set value "bar" + aa_log "auth::driver::get_parameter_values: '$values'" - db_dml insert_test_parameter { - insert into auth_driver_params ( - impl_id, authority_id, key, value - ) values ( - :impl_id, :authority_id, :key, :value - ) - } + aa_true "Did get_parameter return the correct value?" [util_sets_equal_p $values [list $parameter $value]] - set new_value "new_bar" + set new_value [ad_generate_random_string] + auth::driver::set_parameter_value \ - -impl_id $impl_id \ - -authority_id $authority_id \ - -parameter $key \ + -authority_id $authority(authority_id) \ + -impl_id $authority(auth_impl_id) \ + -parameter $parameter \ -value $new_value - set actual_value [db_string select_value { - select value - from auth_driver_params - where impl_id = :impl_id - and authority_id = :authority_id - and key = :key - }] + set values [auth::driver::get_parameter_values \ + -authority_id $authority(authority_id) \ + -impl_id $authority(auth_impl_id)] - aa_equals "Value should be $new_value after update" $new_value $actual_value + aa_log "auth::driver::get_parameter_values: '$values'" + + aa_true "Does it return the new value?" [util_sets_equal_p $values [list $parameter $new_value]] + } } + ##### # # Helper procs+ $errmsg ++