ad_library { Community routines (dealing with users, parties, etc.). @author Jon Salz (jsalz@arsdigita.com) @creation-date 11 Aug 2000 @cvs-id $Id: community-core-procs.tcl,v 1.62.2.11 2017/05/12 15:47:00 gustafn Exp $ } namespace eval party {} namespace eval person {} namespace eval acs_user {} ad_proc -deprecated -private cc_lookup_screen_name_user { screen_name } { @see acs_user::get_user_id_by_screen_name } { return [db_string user_select {} -default {}] } ad_proc -deprecated cc_screen_name_user { screen_name } { @return Returns the user ID for a particular screen name, or an empty string if none exists. @see acs_user::get_user_id_by_screen_name } { return [util_memoize [list cc_lookup_screen_name_user $screen_name]] } ad_proc -deprecated -private cc_lookup_email_user { email } { Return the user_id of a user given the email. Returns the empty string if no such user exists. @see party::get_by_email } { return [db_string user_select {} -default {}] } ad_proc -public -deprecated cc_email_from_party { party_id } { @return The email address of the indicated party. @see party::email } { return [db_string email_from_party {} -default {}] } ad_proc -deprecated cc_email_user { email } { @return Returns the user ID for a particular email address, or an empty string if none exists. @see party::get_by_email } { return [util_memoize [list cc_lookup_email_user $email]] } ad_proc -deprecated -private cc_lookup_name_group { name } { @see group::get_id } { return [db_string group_select {} -default {}] } ad_proc -deprecated cc_name_to_group { name } { Returns the group ID for a particular name, or an empty string if none exists. @see group::get_id } { return [util_memoize [list cc_lookup_name_group $name]] } ad_proc -deprecated ad_user_new { email first_names last_name password password_question password_answer {url ""} {email_verified_p "t"} {member_state "approved"} {user_id ""} {username ""} {authority_id ""} {screen_name ""} } { Creates a new user in the system. The user_id can be specified as an argument to enable double click protection. If this procedure succeeds, returns the new user_id. Otherwise, returns 0. @see auth::create_user @see auth::create_local_account } { return [auth::create_local_account_helper \ $email \ $first_names \ $last_name \ $password \ $password_question \ $password_answer \ $url \ $email_verified_p \ $member_state \ $user_id \ $username \ $authority_id \ $screen_name] } ad_proc -public person::person_p { {-party_id:required} } { is this party a person? Cached } { return [util_memoize [list ::person::person_p_not_cached -party_id $party_id]] } ad_proc -private person::person_p_not_cached { {-party_id:required} } { is this party a person? Cached } { if {[db_0or1row contact_person_exists_p {select '1' from persons where person_id = :party_id}]} { return 1 } else { return 0 } } ad_proc -public person::new { {-first_names:required} {-last_name:required} {-email {}} } { create a new person } { set extra_vars [ns_set create] ns_set put $extra_vars first_names $first_names ns_set put $extra_vars last_name $last_name ns_set put $extra_vars email $email set object_type "person" return [package_instantiate_object -extra_vars $extra_vars $object_type] } ad_proc -public person::delete { {-person_id:required} } { delete a person } { db_exec_plsql delete_person {} } ad_proc -public person::get { {-person_id:required} } { get info for a person as a Tcl array in list form } { db_1row get_person {} set person(person_id) $person_id set person(first_names) $first_names set person(last_name) $last_name return [array get person] } ad_proc -public person::name { {-person_id ""} {-email ""} } { get the name of a person. Cached. } { if {$person_id eq "" && $email eq ""} { error "You need to provide either person_id or email" } elseif {"" ne $person_id && "" ne $email } { error "Only provide provide person_id OR email, not both" } else { return [util_memoize [list person::name_not_cached -person_id $person_id -email $email]] } } ad_proc -public person::name_flush { {-person_id:required} {-email ""} } { Flush the person::name cache. } { util_memoize_flush [list person::name_not_cached -person_id $person_id -email $email] acs_user::flush_cache -user_id $person_id } ad_proc -private person::name_not_cached { {-person_id ""} {-email ""} } { get the name of a person } { if {$email eq ""} { db_1row get_person_name {} } else { # As the old functionality returned an error, but I want an empty string for e-mail # Therefore for emails we use db_string set person_name [db_string get_party_name {} -default ""] } return $person_name } ad_proc -public person::update { {-person_id:required} {-first_names:required} {-last_name:required} } { update the name of a person } { db_dml update_person {} db_dml update_object_title {} name_flush -person_id $person_id } # DRB: Though I've moved the bio field to type specific rather than generic storage, I've # maintained the API semantics exactly as they were before mostly in order to make upgrade # possible. In the future, the number of database hits can be diminished by getting rid of # the separate queries for bio stuff. However, I have removed bio_mime_type because it's # unused and unsupported in the existing code. ad_proc -public person::get_bio { {-person_id {}} {-exists_var {}} } { Get the value of the user's bio(graphy) field. @option person_id The person_id of the person to get the bio for. Leave blank for currently logged in user. @option exists_var The name of a variable in the caller's namespace, which will be set to 1 if the bio column is not null. Leave blank if you're not interested in this information. @return The bio of the user as a text string. @author Lars Pind (lars@collaboraid.biz) } { if { $person_id eq "" } { set person_id [ad_conn user_id] } if { $exists_var ne "" } { upvar $exists_var exists_p } db_1row select_bio {} set exists_p [expr {$bio ne ""}] return $bio } ad_proc -public person::update_bio { {-person_id:required} {-bio:required} } { Update the bio for a person. @param person_id The ID of the person to edit bio for @param bio The new bio for the person @author Lars Pind (lars@collaboraid.biz) } { db_dml update_bio {} } ad_proc -public acs_user::change_state { {-user_id:required} {-state:required} } { Change the membership state of a user. } { set rel_id [db_string select_rel_id {} -default {}] if {$rel_id eq ""} { return } membership_rel::change_state -rel_id $rel_id -state $state } ad_proc -public acs_user::approve { {-user_id:required} } { Approve a user } { change_state -user_id $user_id -state "approved" } ad_proc -public acs_user::ban { {-user_id:required} } { Ban a user } { change_state -user_id $user_id -state "banned" } ad_proc -public acs_user::reject { {-user_id:required} } { Reject a user } { change_state -user_id $user_id -state "rejected" } ad_proc -public acs_user::delete { {-user_id:required} {-permanent:boolean} } { Delete a user @param permanent If provided the user will be deleted permanently from the database. Otherwise the user state will merely be set to "deleted". } { if { ! $permanent_p } { change_state -user_id $user_id -state "deleted" acs_user::flush_cache -user_id $user_id } else { db_exec_plsql permanent_delete {} } } ad_proc -public acs_user::unapprove { {-user_id:required} } { Unapprove a user } { change_state -user_id $user_id -state "needs approval" } ad_proc -public acs_user::get_by_username { {-authority_id ""} {-username:required} } { Returns user_id from authority and username. Returns the empty string if no user found. @param authority_id The authority. Defaults to local authority. @param username The username of the user you're trying to find. @return user_id of the user, or the empty string if no user found. } { # Default to local authority if { $authority_id eq "" } { set authority_id [auth::authority::local] } set user_id [util_memoize [list acs_user::get_by_username_not_cached -authority_id $authority_id -username $username]] if {$user_id eq ""} { util_memoize_flush [list acs_user::get_by_username_not_cached -authority_id $authority_id -username $username] } return $user_id } ad_proc -private acs_user::get_by_username_not_cached { {-authority_id:required} {-username:required} } { Returns user_id from authority and username. Returns the empty string if no user found. @param authority_id The authority. Defaults to local authority. @param username The username of the user you're trying to find. @return user_id of the user, or the empty string if no user found. } { return [db_string user_id_from_username {} -default {}] } ad_proc -public acs_user::get { {-user_id {}} {-authority_id {}} {-username {}} {-array} {-include_bio:boolean} } { Get basic information about a user. Uses util_memoize to cache info from the database. You may supply either user_id, or username. If you supply username, you may also supply authority_id, or you may leave it out, in which case it defaults to the local authority. If you supply neither user_id nor username, and we have a connection, the currently logged in user will be assumed. @option user_id The user_id of the user to get the bio for. Leave blank for current user. @option include_bio Whether to include the bio in the user information @param array The name of an array into which you want the information put. The attributes returned are: