local-procs.tcl

Procs for local authentication.

Location:
packages/acs-authentication/tcl/local-procs.tcl
Created:
2003-05-13
Author:
Lars Pind <lars@collaobraid.biz>
CVS Identification:
$Id: local-procs.tcl,v 1.47.2.8 2022/09/19 13:24:22 antoniop Exp $

Procedures in this file

Detailed information

auth::local::authentication::Authenticate (private)

 auth::local::authentication::Authenticate username password \
    [ parameters ] [ authority_id ]

Implements the Authenticate operation of the auth_authentication service contract for the local account implementation.

Parameters:
username
password
parameters (optional)
authority_id (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_acs_sc_impl_new_from_spec acs_sc_impl_new_from_spec (test acs-service-contract) auth::local::authentication::Authenticate auth::local::authentication::Authenticate test_acs_sc_impl_new_from_spec->auth::local::authentication::Authenticate _ _ (public) auth::local::authentication::Authenticate->_ acs_user::get_by_username acs_user::get_by_username (public) auth::local::authentication::Authenticate->acs_user::get_by_username ad_check_password ad_check_password (public) auth::local::authentication::Authenticate->ad_check_password auth::authority::local auth::authority::local (public) auth::local::authentication::Authenticate->auth::authority::local AcsSc.auth_authentication.authenticate.local AcsSc.auth_authentication.authenticate.local (private) AcsSc.auth_authentication.authenticate.local->auth::local::authentication::Authenticate auth::local::authentication::register_impl auth::local::authentication::register_impl (private) auth::local::authentication::register_impl->auth::local::authentication::Authenticate

Testcases:
acs_sc_impl_new_from_spec

auth::local::authentication::GetParameters (private)

 auth::local::authentication::GetParameters

Implements the GetParameters operation of the auth_authentication service contract for the local account implementation.

Partial Call Graph (max 5 caller/called nodes):
%3 test_acs_sc_impl_new_from_spec acs_sc_impl_new_from_spec (test acs-service-contract) auth::local::authentication::GetParameters auth::local::authentication::GetParameters test_acs_sc_impl_new_from_spec->auth::local::authentication::GetParameters AcsSc.auth_authentication.getparameters.local AcsSc.auth_authentication.getparameters.local (private) AcsSc.auth_authentication.getparameters.local->auth::local::authentication::GetParameters auth::local::authentication::register_impl auth::local::authentication::register_impl (private) auth::local::authentication::register_impl->auth::local::authentication::GetParameters

Testcases:
acs_sc_impl_new_from_spec

auth::local::authentication::MergeUser (private)

 auth::local::authentication::MergeUser from_user_id to_user_id \
    [ authority_id ]

Merge Implementation of local authentication. This will merge the names, emails, usernames, permissions, etc of the two users to merge.

Parameters:
from_user_id
to_user_id
authority_id (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_auth_authentication_implementations auth_authentication_implementations (test acs-authentication) auth::local::authentication::MergeUser auth::local::authentication::MergeUser test_auth_authentication_implementations->auth::local::authentication::MergeUser acs_user::update acs_user::update (public) auth::local::authentication::MergeUser->acs_user::update db_string db_string (public) auth::local::authentication::MergeUser->db_string db_transaction db_transaction (public) auth::local::authentication::MergeUser->db_transaction membership_rel::change_state membership_rel::change_state (public) auth::local::authentication::MergeUser->membership_rel::change_state party::update party::update (public) auth::local::authentication::MergeUser->party::update AcsSc.auth_authentication.mergeuser.local AcsSc.auth_authentication.mergeuser.local (private) AcsSc.auth_authentication.mergeuser.local->auth::local::authentication::MergeUser auth::local::authentication::register_impl auth::local::authentication::register_impl (private) auth::local::authentication::register_impl->auth::local::authentication::MergeUser

Testcases:
auth_authentication_implementations

auth::local::authentication::register_impl (private)

 auth::local::authentication::register_impl

Register the 'local' implementation of the 'auth_authentication' service contract.

Returns:
impl_id of the newly created implementation.

Partial Call Graph (max 5 caller/called nodes):
%3 auth::local::install auth::local::install (private) auth::local::authentication::register_impl auth::local::authentication::register_impl auth::local::install->auth::local::authentication::register_impl acs_sc::impl::new_from_spec acs_sc::impl::new_from_spec (public) auth::local::authentication::register_impl->acs_sc::impl::new_from_spec auth::local::authentication::Authenticate auth::local::authentication::Authenticate (private) auth::local::authentication::register_impl->auth::local::authentication::Authenticate auth::local::authentication::GetParameters auth::local::authentication::GetParameters (private) auth::local::authentication::register_impl->auth::local::authentication::GetParameters auth::local::authentication::MergeUser auth::local::authentication::MergeUser (private) auth::local::authentication::register_impl->auth::local::authentication::MergeUser

Testcases:
No testcase defined.

auth::local::authentication::unregister_impl (private)

 auth::local::authentication::unregister_impl

Unregister the 'local' implementation of the 'auth_authentication' service contract.

Partial Call Graph (max 5 caller/called nodes):
%3 auth::local::uninstall auth::local::uninstall (private) auth::local::authentication::unregister_impl auth::local::authentication::unregister_impl auth::local::uninstall->auth::local::authentication::unregister_impl acs_sc::impl::delete acs_sc::impl::delete (public) auth::local::authentication::unregister_impl->acs_sc::impl::delete

Testcases:
No testcase defined.

auth::local::install (private)

 auth::local::install

Register local service contract implementations, and update the local authority with live information.

Partial Call Graph (max 5 caller/called nodes):
%3 auth::package_install auth::package_install (private) auth::local::install auth::local::install auth::package_install->auth::local::install ad_system_name ad_system_name (public) auth::local::install->ad_system_name auth::authority::edit auth::authority::edit (public) auth::local::install->auth::authority::edit auth::authority::local auth::authority::local (public) auth::local::install->auth::authority::local auth::local::authentication::register_impl auth::local::authentication::register_impl (private) auth::local::install->auth::local::authentication::register_impl auth::local::password::register_impl auth::local::password::register_impl (private) auth::local::install->auth::local::password::register_impl

Testcases:
No testcase defined.

auth::local::password::CanChangePassword (private)

 auth::local::password::CanChangePassword [ parameters ]

Implements the CanChangePassword operation of the auth_password service contract for the local account implementation.

Parameters:
parameters (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_auth_password_implementations auth_password_implementations (test acs-authentication) auth::local::password::CanChangePassword auth::local::password::CanChangePassword test_auth_password_implementations->auth::local::password::CanChangePassword AcsSc.auth_password.canchangepassword.local AcsSc.auth_password.canchangepassword.local (private) AcsSc.auth_password.canchangepassword.local->auth::local::password::CanChangePassword auth::local::password::register_impl auth::local::password::register_impl (private) auth::local::password::register_impl->auth::local::password::CanChangePassword

Testcases:
auth_password_implementations

auth::local::password::CanResetPassword (private)

 auth::local::password::CanResetPassword [ parameters ]

Implements the CanResetPassword operation of the auth_password service contract for the local account implementation.

Parameters:
parameters (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_auth_password_implementations auth_password_implementations (test acs-authentication) auth::local::password::CanResetPassword auth::local::password::CanResetPassword test_auth_password_implementations->auth::local::password::CanResetPassword AcsSc.auth_password.canresetpassword.local AcsSc.auth_password.canresetpassword.local (private) AcsSc.auth_password.canresetpassword.local->auth::local::password::CanResetPassword auth::local::password::register_impl auth::local::password::register_impl (private) auth::local::password::register_impl->auth::local::password::CanResetPassword

Testcases:
auth_password_implementations

auth::local::password::CanRetrievePassword (private)

 auth::local::password::CanRetrievePassword [ parameters ]

Implements the CanRetrievePassword operation of the auth_password service contract for the local account implementation.

Parameters:
parameters (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_auth_password_implementations auth_password_implementations (test acs-authentication) auth::local::password::CanRetrievePassword auth::local::password::CanRetrievePassword test_auth_password_implementations->auth::local::password::CanRetrievePassword AcsSc.auth_password.canretrievepassword.local AcsSc.auth_password.canretrievepassword.local (private) AcsSc.auth_password.canretrievepassword.local->auth::local::password::CanRetrievePassword auth::local::password::register_impl auth::local::password::register_impl (private) auth::local::password::register_impl->auth::local::password::CanRetrievePassword

Testcases:
auth_password_implementations

auth::local::password::ChangePassword (private)

 auth::local::password::ChangePassword username new_password \
    [ old_password ] [ parameters ] [ authority_id ]

Implements the ChangePassword operation of the auth_password service contract for the local account implementation.

Parameters:
username
new_password
old_password (optional)
parameters (optional)
authority_id (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_auth_password_implementations auth_password_implementations (test acs-authentication) auth::local::password::ChangePassword auth::local::password::ChangePassword test_auth_password_implementations->auth::local::password::ChangePassword _ _ (public) auth::local::password::ChangePassword->_ acs_mail_lite::send acs_mail_lite::send (public) auth::local::password::ChangePassword->acs_mail_lite::send acs_user::get_by_username acs_user::get_by_username (public) auth::local::password::ChangePassword->acs_user::get_by_username acs_user::get_user_info acs_user::get_user_info (public) auth::local::password::ChangePassword->acs_user::get_user_info ad_acs_kernel_id ad_acs_kernel_id (public) auth::local::password::ChangePassword->ad_acs_kernel_id AcsSc.auth_password.changepassword.local AcsSc.auth_password.changepassword.local (private) AcsSc.auth_password.changepassword.local->auth::local::password::ChangePassword auth::local::password::register_impl auth::local::password::register_impl (private) auth::local::password::register_impl->auth::local::password::ChangePassword

Testcases:
auth_password_implementations

auth::local::password::GetParameters (private)

 auth::local::password::GetParameters

Implements the GetParameters operation of the auth_password service contract for the local account implementation.

Partial Call Graph (max 5 caller/called nodes):
%3 test_auth_password_implementations auth_password_implementations (test acs-authentication) auth::local::password::GetParameters auth::local::password::GetParameters test_auth_password_implementations->auth::local::password::GetParameters AcsSc.auth_password.getparameters.local AcsSc.auth_password.getparameters.local (private) AcsSc.auth_password.getparameters.local->auth::local::password::GetParameters auth::local::password::register_impl auth::local::password::register_impl (private) auth::local::password::register_impl->auth::local::password::GetParameters

Testcases:
auth_password_implementations

auth::local::password::ResetPassword (private)

 auth::local::password::ResetPassword username parameters \
    [ authority_id ]

Implements the ResetPassword operation of the auth_password service contract for the local account implementation.

Parameters:
username
parameters
authority_id (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_auth_password_implementations auth_password_implementations (test acs-authentication) auth::local::password::ResetPassword auth::local::password::ResetPassword test_auth_password_implementations->auth::local::password::ResetPassword acs_user::get_by_username acs_user::get_by_username (public) auth::local::password::ResetPassword->acs_user::get_by_username ad_change_password ad_change_password (public) auth::local::password::ResetPassword->ad_change_password ad_generate_random_string ad_generate_random_string (public) auth::local::password::ResetPassword->ad_generate_random_string AcsSc.auth_password.resetpassword.local AcsSc.auth_password.resetpassword.local (private) AcsSc.auth_password.resetpassword.local->auth::local::password::ResetPassword auth::local::password::register_impl auth::local::password::register_impl (private) auth::local::password::register_impl->auth::local::password::ResetPassword

Testcases:
auth_password_implementations

auth::local::password::RetrievePassword (private)

 auth::local::password::RetrievePassword username parameters

Implements the RetrievePassword operation of the auth_password service contract for the local account implementation.

Parameters:
username
parameters

Partial Call Graph (max 5 caller/called nodes):
%3 test_auth_password_implementations auth_password_implementations (test acs-authentication) auth::local::password::RetrievePassword auth::local::password::RetrievePassword test_auth_password_implementations->auth::local::password::RetrievePassword _ _ (public) auth::local::password::RetrievePassword->_ acs_mail_lite::send acs_mail_lite::send (public) auth::local::password::RetrievePassword->acs_mail_lite::send ad_outgoing_sender ad_outgoing_sender (public) auth::local::password::RetrievePassword->ad_outgoing_sender ad_system_name ad_system_name (public) auth::local::password::RetrievePassword->ad_system_name ad_url ad_url (public) auth::local::password::RetrievePassword->ad_url AcsSc.auth_password.retrievepassword.local AcsSc.auth_password.retrievepassword.local (private) AcsSc.auth_password.retrievepassword.local->auth::local::password::RetrievePassword auth::local::password::register_impl auth::local::password::register_impl (private) auth::local::password::register_impl->auth::local::password::RetrievePassword

Testcases:
auth_password_implementations

auth::local::password::register_impl (private)

 auth::local::password::register_impl

Register the 'local' implementation of the 'auth_password' service contract.

Returns:
impl_id of the newly created implementation.

Partial Call Graph (max 5 caller/called nodes):
%3 auth::local::install auth::local::install (private) auth::local::password::register_impl auth::local::password::register_impl auth::local::install->auth::local::password::register_impl acs_sc::impl::new_from_spec acs_sc::impl::new_from_spec (public) auth::local::password::register_impl->acs_sc::impl::new_from_spec auth::local::password::CanChangePassword auth::local::password::CanChangePassword (private) auth::local::password::register_impl->auth::local::password::CanChangePassword auth::local::password::CanResetPassword auth::local::password::CanResetPassword (private) auth::local::password::register_impl->auth::local::password::CanResetPassword auth::local::password::CanRetrievePassword auth::local::password::CanRetrievePassword (private) auth::local::password::register_impl->auth::local::password::CanRetrievePassword auth::local::password::ChangePassword auth::local::password::ChangePassword (private) auth::local::password::register_impl->auth::local::password::ChangePassword

Testcases:
No testcase defined.

auth::local::password::unregister_impl (private)

 auth::local::password::unregister_impl

Unregister the 'local' implementation of the 'auth_password' service contract.

Partial Call Graph (max 5 caller/called nodes):
%3 auth::local::uninstall auth::local::uninstall (private) auth::local::password::unregister_impl auth::local::password::unregister_impl auth::local::uninstall->auth::local::password::unregister_impl acs_sc::impl::delete acs_sc::impl::delete (public) auth::local::password::unregister_impl->acs_sc::impl::delete

Testcases:
No testcase defined.

auth::local::registration::GetElements (private)

 auth::local::registration::GetElements [ parameters ]

Implements the GetElements operation of the auth_registration service contract for the local account implementation.

Parameters:
parameters (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_auth_registration_implementations auth_registration_implementations (test acs-authentication) auth::local::registration::GetElements auth::local::registration::GetElements test_auth_registration_implementations->auth::local::registration::GetElements ad_acs_kernel_id ad_acs_kernel_id (public) auth::local::registration::GetElements->ad_acs_kernel_id ad_conn ad_conn (public) auth::local::registration::GetElements->ad_conn auth::UseEmailForLoginP auth::UseEmailForLoginP (public) auth::local::registration::GetElements->auth::UseEmailForLoginP parameter::get parameter::get (public) auth::local::registration::GetElements->parameter::get AcsSc.auth_registration.getelements.acs_testing AcsSc.auth_registration.getelements.acs_testing (private) AcsSc.auth_registration.getelements.acs_testing->auth::local::registration::GetElements AcsSc.auth_registration.getelements.local AcsSc.auth_registration.getelements.local (private) AcsSc.auth_registration.getelements.local->auth::local::registration::GetElements auth::local::registration::register_impl auth::local::registration::register_impl (private) auth::local::registration::register_impl->auth::local::registration::GetElements

Testcases:
auth_registration_implementations

auth::local::registration::GetParameters (private)

 auth::local::registration::GetParameters

Implements the GetParameters operation of the auth_registration service contract for the local account implementation.

Partial Call Graph (max 5 caller/called nodes):
%3 test_auth_registration_implementations auth_registration_implementations (test acs-authentication) auth::local::registration::GetParameters auth::local::registration::GetParameters test_auth_registration_implementations->auth::local::registration::GetParameters AcsSc.auth_registration.getparameters.acs_testing AcsSc.auth_registration.getparameters.acs_testing (private) AcsSc.auth_registration.getparameters.acs_testing->auth::local::registration::GetParameters AcsSc.auth_registration.getparameters.local AcsSc.auth_registration.getparameters.local (private) AcsSc.auth_registration.getparameters.local->auth::local::registration::GetParameters auth::local::registration::register_impl auth::local::registration::register_impl (private) auth::local::registration::register_impl->auth::local::registration::GetParameters

Testcases:
auth_registration_implementations

auth::local::registration::Register (private)

 auth::local::registration::Register parameters username authority_id \
    first_names last_name screen_name email url password \
    secret_question secret_answer

Implements the Register operation of the auth_registration service contract for the local account implementation.

Parameters:
parameters
username
authority_id
first_names
last_name
screen_name
email
url
password
secret_question
secret_answer

Partial Call Graph (max 5 caller/called nodes):
%3 test_auth_registration_implementations auth_registration_implementations (test acs-authentication) auth::local::registration::Register auth::local::registration::Register test_auth_registration_implementations->auth::local::registration::Register acs_mail_lite::send acs_mail_lite::send (public) auth::local::registration::Register->acs_mail_lite::send acs_user::get_by_username acs_user::get_by_username (public) auth::local::registration::Register->acs_user::get_by_username ad_change_password ad_change_password (public) auth::local::registration::Register->ad_change_password ad_conn ad_conn (public) auth::local::registration::Register->ad_conn ad_generate_random_string ad_generate_random_string (public) auth::local::registration::Register->ad_generate_random_string AcsSc.auth_registration.register.local AcsSc.auth_registration.register.local (private) AcsSc.auth_registration.register.local->auth::local::registration::Register auth::local::registration::register_impl auth::local::registration::register_impl (private) auth::local::registration::register_impl->auth::local::registration::Register

Testcases:
auth_registration_implementations

auth::local::registration::register_impl (private)

 auth::local::registration::register_impl

Register the 'local' implementation of the 'auth_registration' service contract.

Returns:
impl_id of the newly created implementation.

Partial Call Graph (max 5 caller/called nodes):
%3 auth::local::install auth::local::install (private) auth::local::registration::register_impl auth::local::registration::register_impl auth::local::install->auth::local::registration::register_impl acs_sc::impl::new_from_spec acs_sc::impl::new_from_spec (public) auth::local::registration::register_impl->acs_sc::impl::new_from_spec auth::local::registration::GetElements auth::local::registration::GetElements (private) auth::local::registration::register_impl->auth::local::registration::GetElements auth::local::registration::GetParameters auth::local::registration::GetParameters (private) auth::local::registration::register_impl->auth::local::registration::GetParameters auth::local::registration::Register auth::local::registration::Register (private) auth::local::registration::register_impl->auth::local::registration::Register

Testcases:
No testcase defined.

auth::local::registration::unregister_impl (private)

 auth::local::registration::unregister_impl

Unregister the 'local' implementation of the 'auth_register' service contract.

Partial Call Graph (max 5 caller/called nodes):
%3 auth::local::uninstall auth::local::uninstall (private) auth::local::registration::unregister_impl auth::local::registration::unregister_impl auth::local::uninstall->auth::local::registration::unregister_impl acs_sc::impl::delete acs_sc::impl::delete (public) auth::local::registration::unregister_impl->acs_sc::impl::delete

Testcases:
No testcase defined.

auth::local::search::GetParameters (private)

 auth::local::search::GetParameters

Implements the GetParameters operation of the auth_search service contract for the local account implementation.

Partial Call Graph (max 5 caller/called nodes):
%3

Testcases:
No testcase defined.

auth::local::search::Search (private)

 auth::local::search::Search search_text [ parameters ]

Implements the Search operation of the auth_search service contract for the local account implementation.

Parameters:
search_text
parameters (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 auth::authority::local auth::authority::local (public) db_list db_list (public) auth::local::search::Search auth::local::search::Search auth::local::search::Search->auth::authority::local auth::local::search::Search->db_list

Testcases:
No testcase defined.

auth::local::uninstall (private)

 auth::local::uninstall

Unregister the local service contract implementation, and update the local authority to reflect that.

Partial Call Graph (max 5 caller/called nodes):
%3 auth::package_uninstall auth::package_uninstall (private) auth::local::uninstall auth::local::uninstall auth::package_uninstall->auth::local::uninstall auth::authority::edit auth::authority::edit (public) auth::local::uninstall->auth::authority::edit auth::authority::local auth::authority::local (public) auth::local::uninstall->auth::authority::local auth::local::authentication::unregister_impl auth::local::authentication::unregister_impl (private) auth::local::uninstall->auth::local::authentication::unregister_impl auth::local::password::unregister_impl auth::local::password::unregister_impl (private) auth::local::uninstall->auth::local::password::unregister_impl auth::local::registration::unregister_impl auth::local::registration::unregister_impl (private) auth::local::uninstall->auth::local::registration::unregister_impl

Testcases:
No testcase defined.

auth::local::user_info::GetParameters (private)

 auth::local::user_info::GetParameters

Implements the GetParameters operation of the auth_user_info service contract for the local account implementation.

Partial Call Graph (max 5 caller/called nodes):
%3 test_auth_user_info_implementations auth_user_info_implementations (test acs-authentication) auth::local::user_info::GetParameters auth::local::user_info::GetParameters test_auth_user_info_implementations->auth::local::user_info::GetParameters auth::local::user_info::register_impl auth::local::user_info::register_impl (private) auth::local::user_info::register_impl->auth::local::user_info::GetParameters

Testcases:
auth_user_info_implementations

auth::local::user_info::GetUserInfo (private)

 auth::local::user_info::GetUserInfo username [ parameters ]

Implements the GetUserInfo operation of the auth_user_info service contract for the local account implementation.

Parameters:
username
parameters (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_auth_user_info_implementations auth_user_info_implementations (test acs-authentication) auth::local::user_info::GetUserInfo auth::local::user_info::GetUserInfo test_auth_user_info_implementations->auth::local::user_info::GetUserInfo acs_user::get_by_username acs_user::get_by_username (public) auth::local::user_info::GetUserInfo->acs_user::get_by_username auth::get_local_account_status auth::get_local_account_status (public) auth::local::user_info::GetUserInfo->auth::get_local_account_status db_1row db_1row (public) auth::local::user_info::GetUserInfo->db_1row auth::local::user_info::register_impl auth::local::user_info::register_impl (private) auth::local::user_info::register_impl->auth::local::user_info::GetUserInfo

Testcases:
auth_user_info_implementations

auth::local::user_info::register_impl (private)

 auth::local::user_info::register_impl

Register the 'local' implementation of the 'auth_user_info' service contract.

Returns:
impl_id of the newly created implementation.

Partial Call Graph (max 5 caller/called nodes):
%3 auth::local::install auth::local::install (private) auth::local::user_info::register_impl auth::local::user_info::register_impl auth::local::install->auth::local::user_info::register_impl acs_sc::impl::new_from_spec acs_sc::impl::new_from_spec (public) auth::local::user_info::register_impl->acs_sc::impl::new_from_spec auth::local::user_info::GetParameters auth::local::user_info::GetParameters (private) auth::local::user_info::register_impl->auth::local::user_info::GetParameters auth::local::user_info::GetUserInfo auth::local::user_info::GetUserInfo (private) auth::local::user_info::register_impl->auth::local::user_info::GetUserInfo

Testcases:
No testcase defined.

auth::local::user_info::unregister_impl (private)

 auth::local::user_info::unregister_impl

Unregister the 'local' implementation of the 'auth_user_info' service contract.

Partial Call Graph (max 5 caller/called nodes):
%3 acs_sc::impl::delete acs_sc::impl::delete (public) auth::local::user_info::unregister_impl auth::local::user_info::unregister_impl auth::local::user_info::unregister_impl->acs_sc::impl::delete

Testcases:
No testcase defined.
[ hide source ]

Content File Source

ad_library {
    Procs for local authentication.

    @author Lars Pind (lars@collaobraid.biz)
    @creation-date 2003-05-13
    @cvs-id $Id: local-procs.tcl,v 1.47.2.8 2022/09/19 13:24:22 antoniop Exp $
}

namespace eval auth {}
namespace eval auth::local {}
namespace eval auth::local::authentication {}
namespace eval auth::local::password {}
namespace eval auth::local::registration {}
namespace eval auth::local::user_info {}
namespace eval auth::local::search {}

#####
#
# auth::local
#
#####

ad_proc -private auth::local::install {} {
    Register local service contract implementations,
    and update the local authority with live information.
} {
    db_transaction {
        # Register the local service contract implementations
        set row(auth_impl_id) [auth::local::authentication::register_impl]
        set row(pwd_impl_id) [auth::local::password::register_impl]
        set row(register_impl_id) [auth::local::registration::register_impl]
        set row(user_info_impl_id) [auth::local::user_info::register_impl]

        # Set the authority pretty-name to be the system name
        set row(pretty_name) [ad_system_name]

        auth::authority::edit \
            -authority_id [auth::authority::local] \
            -array row
    }
}

ad_proc -private auth::local::uninstall {} {
    Unregister the local service contract implementation, and update the
    local authority to reflect that.
} {
    db_transaction {
        # Update the local authority to reflect the loss of the implementations
        set row(auth_impl_id) {}
        set row(pwd_impl_id) {}
        set row(register_impl_id) {}

        auth::authority::edit \
            -authority_id [auth::authority::local] \
            -array row

        # Unregister the implementations
        auth::local::authentication::unregister_impl
        auth::local::password::unregister_impl
        auth::local::registration::unregister_impl
    }
}




#####
#
# auth::local::authentication
#
#####
#
# The 'auth_authentication' service contract implementation
#

ad_proc -private auth::local::authentication::register_impl {} {
    Register the 'local' implementation of the 'auth_authentication' service contract.

    @return impl_id of the newly created implementation.
} {
    set spec {
        contract_name "auth_authentication"
        owner "acs-authentication"
        name "local"
        pretty_name "Local"
        aliases {
            MergeUser auth::local::authentication::MergeUser
            Authenticate auth::local::authentication::Authenticate
            GetParameters auth::local::authentication::GetParameters
        }
    }

    return [acs_sc::impl::new_from_spec -spec $spec]
}

ad_proc -private auth::local::authentication::unregister_impl {} {
    Unregister the 'local' implementation of the 'auth_authentication' service contract.
} {
    acs_sc::impl::delete -contract_name "auth_authentication" -impl_name "local"
}

d_proc -private auth::local::authentication::MergeUser {
    from_user_id
    to_user_id
    {authority_id ""}
} {
    Merge Implementation of local authentication. This will
    merge the names, emails, usernames, permissions, etc
    of the two users to merge.
} {
    ns_log Notice "Starting auth::local::authentication::MergeUser"
    db_transaction {
        ns_log Notice "  Merging user portraits"

        ns_log notice "  Merging username, email and basic info in general"

        set new_username "merged_$from_user_id"
        append new_username "_$to_user_id"

        # Shall we keep the domain for email?
        # Actually, the username 'merged_xxx_yyy'
        # won't be an email, so we will keep it without
        # domain
        set new_email $new_username

        set rel_id [db_string getrelid {}]
        membership_rel::change_state -rel_id $rel_id -state "merged"

        acs_user::update -user_id $from_user_id -username "$new_username" -screen_name "$new_username"
        party::update -party_id $from_user_id -email "$new_email"

    }
    ns_log notice "Finishing auth::local::authentication::MergeUser"
}


d_proc -private auth::local::authentication::Authenticate {
    username
    password
    {parameters {}}
    {authority_id {}}
} {
    Implements the Authenticate operation of the auth_authentication
    service contract for the local account implementation.
} {
    array set auth_info [list]

    if {$authority_id eq ""} {
        set authority_id [auth::authority::local]
    }

    set user_id [acs_user::get_by_username -authority_id $authority_id -username $username]
    if { $user_id eq "" } {
        set result(auth_status) "no_account"
        return [array get result]
    }

    if { [ad_check_password $user_id $password] } {
        set auth_info(auth_status) "ok"
    } else {
        set auth_info(auth_status) "bad_password"
        set auth_info(auth_message) [_ acs-authentication.Invalid_username_or_password]
        return [array get auth_info]
    }

    # We set 'external' account status to 'ok', because the
    # local account status will be checked anyways by the framework
    set auth_info(account_status) ok

    return [array get auth_info]
}

ad_proc -private auth::local::authentication::GetParameters {} {
    Implements the GetParameters operation of the auth_authentication
    service contract for the local account implementation.
} {
    # No parameters
    return [list]
}


#####
#
# auth::local::password
#
#####
#
# The 'auth_password' service contract implementation
#

ad_proc -private auth::local::password::register_impl {} {
    Register the 'local' implementation of the 'auth_password' service contract.

    @return impl_id of the newly created implementation.
} {
    set spec {
        contract_name "auth_password"
        owner "acs-authentication"
        name "local"
        pretty_name "Local"
        aliases {
            CanChangePassword auth::local::password::CanChangePassword
            ChangePassword auth::local::password::ChangePassword
            CanRetrievePassword auth::local::password::CanRetrievePassword
            RetrievePassword auth::local::password::RetrievePassword
            CanResetPassword auth::local::password::CanResetPassword
            ResetPassword auth::local::password::ResetPassword
            GetParameters auth::local::password::GetParameters
        }
    }
    return [acs_sc::impl::new_from_spec -spec $spec]
}

ad_proc -private auth::local::password::unregister_impl {} {
    Unregister the 'local' implementation of the 'auth_password' service contract.
} {
    acs_sc::impl::delete -contract_name "auth_password" -impl_name "local"
}


d_proc -private auth::local::password::CanChangePassword {
    {parameters ""}
} {
    Implements the CanChangePassword operation of the auth_password
    service contract for the local account implementation.
} {
    # Yeah, we can change your password
    return 1
}

d_proc -private auth::local::password::CanRetrievePassword {
    {parameters ""}
} {
    Implements the CanRetrievePassword operation of the auth_password
    service contract for the local account implementation.
} {
    # passwords are stored hashed, so we send the hash and let the user choose a new password
    return 1
}

d_proc -private auth::local::password::CanResetPassword {
    {parameters ""}
} {
    Implements the CanResetPassword operation of the auth_password
    service contract for the local account implementation.
} {
    # Yeah, we can reset for you.
    return 1
}

d_proc -private auth::local::password::ChangePassword {
    username
    new_password
    {old_password ""}
    {parameters {}}
    {authority_id {}}
} {
    Implements the ChangePassword operation of the auth_password
    service contract for the local account implementation.
} {
    array set result {
        password_status {}
        password_message {}
    }

    set user_id [acs_user::get_by_username -authority_id $authority_id -username $username]
    if { $user_id eq "" } {
        set result(password_status) "no_account"
        return [array get result]
    }

    if { $old_password ne "" } {
        if { ![ad_check_password $user_id $old_password] } {
            set result(password_status) "old_password_bad"
            return [array get result]
        }
    }

    ad_try {
        ad_change_password $user_id $new_password
    } on error {errorMsg} {
        set result(password_status) "change_error"
        ad_log Error "Error changing local password for username $username, user_id $user_id: $errorMsg"
        return [array get result]
    }

    set result(password_status) "ok"

    if { [parameter::get -parameter EmailAccountOwnerOnPasswordChangeP -package_id [ad_acs_kernel_id] -default 1] } {
        ad_try {
            set user_id [acs_user::get_by_username \
                             -username $username \
                             -authority_id $authority_id]
            set user_email [party::get -party_id $user_id -element email]

            set system_name [ad_system_name]
            set pvt_home_name [ad_pvt_home_name]
            set password_update_link_text [_ acs-subsite.Change_my_Password]

            if { [auth::UseEmailForLoginP] } {
                set account_id_label [_ acs-subsite.Email]
                set account_id $user_email
            } else {
                set account_id_label [_ acs-subsite.Username]
                set account_id [acs_user::get_user_info \
                                    -user_id $user_id \
                                    -element username]
            }

            set subject [_ acs-subsite.Password_changed_subject]
            set body [_ acs-subsite.Password_changed_body]

            acs_mail_lite::send \
                -send_immediately \
                -to_addr $user_email \
                -from_addr [ad_outgoing_sender] \
                -subject $subject \
                -body $body
        } on error {errorMsg} {
            ad_log Error "Error sending out password changed notification to account owner with user_id $user_id, email $user_email: $errorMsg"
        }
    }

    return [array get result]
}

d_proc -private auth::local::password::RetrievePassword {
    username
    parameters
} {
    Implements the RetrievePassword operation of the auth_password
    service contract for the local account implementation.
} {
    set result(password_status) "ok"
    set result(password_message) [_ acs-subsite.Request_Change_Password_token_email]

    db_1row get_usr_id_and_password_hash {SELECT user_id, password as password_hash FROM users WHERE username = :username}

    set email [party::email -party_id $user_id]
    # TODO: This email message text should go in the recipient user language, english or every language supported
    set subject "[ad_system_name]: [_ acs-subsite.change_password_email_subject] $username"
    set body "[_ acs-subsite.change_password_email_body_0]\n\n[export_vars -base "[ad_url]/user/password-reset" {user_id password_hash}]\n\n[_ acs-subsite.change_password_email_body_1]"

    acs_mail_lite::send \
        -send_immediately \
        -to_addr $email \
        -from_addr [ad_outgoing_sender] \
        -subject $subject \
        -body $body

    return [array get result]
}

d_proc -private auth::local::password::ResetPassword {
    username
    parameters
    {authority_id {}}
} {
    Implements the ResetPassword operation of the auth_password
    service contract for the local account implementation.
} {
    array set result {
        password_status ok
        password_message {}
    }

    set user_id [acs_user::get_by_username -authority_id $authority_id -username $username]
    if { $user_id eq "" } {
        set result(password_status) "no_account"
        return [array get result]
    }

    # Reset the password
    set password [ad_generate_random_string]

    ad_change_password $user_id $password

    # We return the new password here and let the OpenACS framework send the email with the new password
    set result(password) $password
    return [array get result]
}

ad_proc -private auth::local::password::GetParameters {} {
    Implements the GetParameters operation of the auth_password
    service contract for the local account implementation.
} {
    # No parameters
    return [list]
}


#####
#
# auth::local::register
#



#####
#
# The 'auth_registration' service contract implementation
#

ad_proc -private auth::local::registration::register_impl {} {
    Register the 'local' implementation of the 'auth_registration' service contract.

    @return impl_id of the newly created implementation.
} {
    set spec {
        contract_name "auth_registration"
        owner "acs-authentication"
        name "local"
        pretty_name "Local"
        aliases {
            GetElements auth::local::registration::GetElements
            Register auth::local::registration::Register
            GetParameters auth::local::registration::GetParameters
        }
    }
    return [acs_sc::impl::new_from_spec -spec $spec]
}

ad_proc -private auth::local::registration::unregister_impl {} {
    Unregister the 'local' implementation of the 'auth_register' service contract.
} {
    acs_sc::impl::delete -contract_name "auth_registration" -impl_name "local"
}

d_proc -private auth::local::registration::GetElements {
    {parameters ""}
} {
    Implements the GetElements operation of the auth_registration
    service contract for the local account implementation.
} {
    set result(required) {}
    if { ![auth::UseEmailForLoginP] } {
        set result(required) username
    }

    lappend result(required) email first_names last_name
    set result(optional) { url }

    if { ![parameter::get -package_id [ad_conn subsite_id] -parameter RegistrationProvidesRandomPasswordP -default 0] } {
        lappend result(optional) password
    }

    if { [parameter::get -package_id [ad_acs_kernel_id] -parameter RequireQuestionForPasswordResetP -default 0] &&
         [parameter::get -package_id [ad_acs_kernel_id] -parameter UseCustomQuestionForPasswordReset -default 0] } {
        lappend result(required) secret_question secret_answer
    }

    return [array get result]
}

d_proc -private auth::local::registration::Register {
    parameters
    username
    authority_id
    first_names
    last_name
    screen_name
    email
    url
    password
    secret_question
    secret_answer
} {
    Implements the Register operation of the auth_registration
    service contract for the local account implementation.
} {
    array set result {
        creation_status "ok"
        creation_message {}
        element_messages {}
        account_status "ok"
        account_message {}
        generated_pwd_p 0
        password {}
    }

    # We don't create anything here, so creation always succeeds
    # And we don't check local account, either

    set subsite_id [ad_conn subsite_id]

    # LARS TODO: Move this out of the local driver and into the auth framework
    # Generate random password?
    set generated_pwd_p 0
    if { $password eq ""
         || [parameter::get \
                 -package_id $subsite_id \
                 -parameter RegistrationProvidesRandomPasswordP \
                 -default 0]
     } {
        set password [ad_generate_random_string]
        set generated_pwd_p 1
    }
    set result(generated_pwd_p) $generated_pwd_p
    set result(password) $password

    # Set user's password
    set user_id [acs_user::get_by_username -authority_id $authority_id -username $username]
    ad_change_password $user_id $password

    # Used in messages below
    set system_name [ad_system_name]
    set system_url [ad_url]

    # LARS TODO: Move this out of the local driver and into the auth framework
    # Send password confirmation email to user
    if { [parameter::get \
              -parameter EmailRegistrationConfirmationToUserP \
              -package_id $subsite_id -default 1] } {
        ad_try {
            auth::password::email_password \
                -username $username \
                -authority_id $authority_id \
                -password $password \
                -from [parameter::get \
                           -parameter NewRegistrationEmailAddress \
                           -package_id $subsite_id \
                           -default [ad_system_owner]] \
                -subject_msg_key "acs-subsite.email_subject_Registration_password" \
                -body_msg_key "acs-subsite.email_body_Registration_password"
        } on error {errorMsg} {
            # We don't fail hard here, just log an error
            ad_log Error "Error sending registration confirmation to $email: $errorMsg"
        }
    }

    # LARS TODO: Move this out of the local driver and into the auth framework
    # Notify admin on new registration
    if { [parameter::get \
              -parameter NotifyAdminOfNewRegistrationsP \
              -package_id $subsite_id \
              -default 0] } {
        ad_try {
            set admin_email [parameter::get \
                                 -parameter NewRegistrationEmailAddress \
                                 -package_id $subsite_id \
                                 -default [ad_system_owner]]
            set admin_id [party::get_by_email -email $admin_email]
            if { $admin_id eq "" } {
                set admin_locale [lang::system::site_wide_locale]
            } else {
                set admin_locale [lang::user::locale -user_id $admin_id]
            }

            set system_url [ad_url]

            acs_mail_lite::send \
                -send_immediately \
                -to_addr $admin_email \
                -from_addr [ad_outgoing_sender] \
                -subject [lang::message::lookup $admin_locale acs-subsite.lt_New_registration_at_s] \
                -body [lang::message::lookup $admin_locale acs-subsite.lt_first_names_last_name]
        } on error {errorMsg} {
            # We don't fail hard here, just log an error
            ad_log Error "Error sending admin notification to $admin_email: $errorMsg"
        }
    }

    return [array get result]
}

ad_proc -private auth::local::registration::GetParameters {} {
    Implements the GetParameters operation of the auth_registration
    service contract for the local account implementation.
} {
    # No parameters
    return [list]
}

#####
#
# The 'auth_user_info' service contract implementation
#

ad_proc -private auth::local::user_info::register_impl {} {
    Register the 'local' implementation of the 'auth_user_info' service contract.

    @return impl_id of the newly created implementation.
} {
    set spec {
        contract_name "auth_user_info"
        owner "acs-authentication"
        name "local"
        pretty_name "Local"
        aliases {
            GetUserInfo auth::local::user_info::GetUserInfo
            GetParameters auth::local::user_info::GetParameters
        }
    }
    return [acs_sc::impl::new_from_spec -spec $spec]
}

ad_proc -private auth::local::user_info::unregister_impl {} {
    Unregister the 'local' implementation of the 'auth_user_info' service contract.
} {
    acs_sc::impl::delete -contract_name "auth_user_info" -impl_name "local"
}

d_proc -private auth::local::user_info::GetUserInfo {
    username
    {parameters ""}
} {
    Implements the GetUserInfo operation of the auth_user_info
    service contract for the local account implementation.
} {
    set user_id [acs_user::get_by_username -username $username]
    set result(info_status) [auth::get_local_account_status -user_id $user_id]
    set result(info_message) ""
    db_1row get_user_info {} -column_array user_info
    set result(user_info) [array get user_info]

    return [array get result]
}

ad_proc -private auth::local::user_info::GetParameters {} {
    Implements the GetParameters operation of the auth_user_info
    service contract for the local account implementation.
} {
    # No parameters
    return [list]
}

d_proc -private auth::local::search::Search {
    search_text
    {parameters ""}
} {
    Implements the Search operation of the auth_search
    service contract for the local account implementation.
} {
    set authority_id [auth::authority::local]
    return [db_list user_search {
        select distinct username
        from   cc_users u
        where  authority_id = :authority_id
               and upper(coalesce(u.first_names || ' ', '')  ||
                         coalesce(u.last_name || ' ', '') ||
                         u.email || ' ' ||
                         u.username || ' ' ||
                         coalesce(u.screen_name, '')) like upper('%'||:search_text||'%')
        order  by username
    }]
}

ad_proc -private auth::local::search::GetParameters {} {
    Implements the GetParameters operation of the auth_search
    service contract for the local account implementation.
} {
    # No parameters
    return [list]
}

# Local variables:
#    mode: tcl
#    tcl-indent-level: 4
#    indent-tabs-mode: nil
# End: