本文整理汇总了PHP中ca_users::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP ca_users::insert方法的具体用法?PHP ca_users::insert怎么用?PHP ca_users::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ca_users
的用法示例。
在下文中一共展示了ca_users::insert方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
$o_dm = new Datamodel(true);
// PHPUnit seems to barf on the caching code if we don't instanciate a Datamodel instance
$o_dm->getTableNum("ca_objects");
// set up test role
$this->opt_role = new ca_user_roles();
$this->opt_role->setMode(ACCESS_WRITE);
$this->opt_role->set("name", "UnitTestRole");
$this->opt_role->set("code", "unit_test_role");
if (!$this->opt_role->insert()) {
print "ERROR inserting role: " . join(" ", $this->opt_role->getErrors()) . "\n";
}
$this->opt_role->setMode(ACCESS_READ);
// set up test user
$this->ops_username = "unit_test_user";
$this->ops_password = "topsecret";
$this->opt_user = new ca_users();
$this->opt_user->setMode(ACCESS_WRITE);
$this->opt_user->set(array('user_name' => $this->ops_username, 'password' => $this->ops_password, 'email' => 'foo@bar.com', 'active' => 1, 'userclass' => 0, 'fname' => 'Test', 'lname' => "User"));
if (!$this->opt_user->insert()) {
print "ERROR inserting user: " . join(" ", $this->opt_user->getErrors()) . "\n";
}
$this->opt_user->addRoles("unit_test_role");
$this->opt_user->setMode(ACCESS_READ);
global $req, $resp;
$resp = new ResponseHTTP();
$req = new RequestHTTP($resp, array("dont_create_new_session" => true));
$this->assertInstanceOf('ca_users', $this->opt_user);
$this->assertInstanceOf('ca_user_roles', $this->opt_role);
}
示例2: createUser
/**
* Creates a new active user
*
* @param string $user_name user name
* @param string $password password
* @param string $email email address
* @param string $fname first name
* @param string $lname last name
* @return int identifier of the new user
* @throws SoapFault
*/
public function createUser($user_name, $password, $email, $fname, $lname)
{
$t_user = new ca_users();
$t_user->set("user_name", $user_name);
$t_user->set("password", $password);
$t_user->set("email", $email);
$t_user->set("fname", $fname);
$t_user->set("lname", $lname);
$t_user->set("active", 1);
$t_user->setMode(ACCESS_WRITE);
$t_user->insert();
if ($t_user->numErrors()) {
throw new SoapFault("Server", "Could not create user: " . join(" ", $t_user->getErrors()));
}
return $t_user->getPrimaryKey();
}
示例3: createAdminAccount
public function createAdminAccount()
{
require_once __CA_MODELS_DIR__ . "/ca_users.php";
$ps_password = $this->getRandomPassword();
$t_user = new ca_users();
$t_user->setMode(ACCESS_WRITE);
$t_user->set("user_name", 'administrator');
$t_user->set("password", $ps_password);
$t_user->set("email", $this->ops_admin_email);
$t_user->set("fname", 'CollectiveAccess');
$t_user->set("lname", 'Administrator');
$t_user->set("userclass", 0);
$t_user->set("active", 1);
$t_user->insert();
if ($t_user->numErrors()) {
$this->addError("Errors while adding the default administrator account: " . join("; ", $t_user->getErrors()));
return false;
}
return $ps_password;
}
示例4: register
//.........这里部分代码省略.........
break;
# -------------
# -------------
case "userclass":
$t_user->set("userclass", 1);
// 1=public-only
break;
# -------------
# -------------
default:
if (!$va_errors[$vs_f]) {
$t_user->set($vs_f, $_REQUEST[$vs_f]);
# set field values
if ($t_user->numErrors() > 0) {
$va_errors[$vs_f] = join("; ", $t_user->getErrors());
}
}
break;
# -------------
}
}
// Save user profile responses
if (is_array($va_profile_prefs) && sizeof($va_profile_prefs)) {
foreach ($va_profile_prefs as $vs_pref) {
$t_user->setPreference($vs_pref, $this->request->getParameter('pref_' . $vs_pref, pString));
}
}
if (sizeof($va_errors) == 0) {
# --- there are no errors so make new user record
$t_user->setMode(ACCESS_WRITE);
if ($vb_user_exists_but_is_deleted) {
$t_user->update();
} else {
$t_user->insert();
}
$pn_user_id = $t_user->get("user_id");
if ($t_user->numErrors()) {
$va_errors["register"] = join("; ", $t_user->getErrors());
} else {
# --- add default roles
if (($va_default_roles = $this->request->config->getList('registration_default_roles')) && sizeof($va_default_roles)) {
$t_user->addRoles($va_default_roles);
}
# --- user is joining a user group from a supplied link
if ($this->request->session->getVar("join_user_group_id")) {
if (!$t_user->inGroup($this->request->session->getVar("join_user_group_id"))) {
$t_user->addToGroups($this->request->session->getVar("join_user_group_id"));
$this->request->session->setVar("join_user_group_id", "");
$vs_group_message = _t(" You were added to the group");
} else {
$this->request->session->setVar("join_user_group_id", "");
$vs_group_message = _t(" You are already a member of the group");
}
}
# --- send email confirmation
$o_view = new View($this->request, array($this->request->getViewsDirectoryPath()));
# -- generate email subject line from template
$vs_subject_line = $o_view->render("mailTemplates/reg_conf_subject.tpl");
# -- generate mail text from template - get both the text and the html versions
$vs_mail_message_text = $o_view->render("mailTemplates/reg_conf.tpl");
$vs_mail_message_html = $o_view->render("mailTemplates/reg_conf_html.tpl");
caSendmail($t_user->get('email'), $this->request->config->get("ca_admin_email"), $vs_subject_line, $vs_mail_message_text, $vs_mail_message_html);
if ($this->request->config->get("email_notification_for_new_registrations")) {
# --- send email to admin
$o_view = new View($this->request, array($this->request->getViewsDirectoryPath()));
$o_view->setVar("t_user", $t_user);
示例5: Save
public function Save()
{
// Field to user profile preference mapping
$va_mapping = array('billing_organization' => 'user_profile_organization', 'billing_address1' => 'user_profile_address1', 'billing_address2' => 'user_profile_address2', 'billing_city' => 'user_profile_city', 'billing_zone' => 'user_profile_state', 'billing_postal_code' => 'user_profile_postalcode', 'billing_country' => 'user_profile_country', 'billing_phone' => 'user_profile_phone', 'billing_fax' => 'user_profile_fax', 'shipping_organization' => 'user_profile_organization', 'shipping_address1' => 'user_profile_address1', 'shipping_address2' => 'user_profile_address2', 'shipping_city' => 'user_profile_city', 'shipping_zone' => 'user_profile_state', 'shipping_postal_code' => 'user_profile_postalcode', 'shipping_country' => 'user_profile_country', 'shipping_phone' => 'user_profile_phone', 'shipping_fax' => 'user_profile_fax');
$va_errors = array();
$va_failed_insert_list = array();
$va_fields = $this->opt_order->getFormFields();
foreach ($va_fields as $vs_f => $va_field_info) {
switch ($vs_f) {
case 'transaction_id':
// noop
break;
default:
if (isset($_REQUEST[$vs_f])) {
if (!$this->opt_order->set($vs_f, $this->request->getParameter($vs_f, pString))) {
$va_errors[$vs_f] = $this->opt_order->errors();
}
}
break;
}
}
// Set additional fees for order
$va_fees = $this->opo_client_services_config->getAssoc('additional_order_fees');
if (is_array($va_fees)) {
if (!is_array($va_fee_values = $this->opt_order->get('additional_fees'))) {
$va_fee_values = array();
}
foreach ($va_fees as $vs_code => $va_info) {
$va_fee_values[$vs_code] = (double) $this->request->getParameter("additional_fee_{$vs_code}", pString);
}
$this->opt_order->set('additional_fees', $va_fee_values);
}
$this->opt_order->setMode(ACCESS_WRITE);
if ($this->opt_order->getPrimaryKey()) {
$this->opt_order->update();
$vn_transaction_id = $this->opt_order->get('transaction_id');
} else {
// Set transaction
if (!($vn_transaction_id = $this->request->getParameter('transaction_id', pInteger))) {
if (!($vn_user_id = $this->request->getParameter('transaction_user_id', pInteger))) {
if ($vs_user_name = $this->request->getParameter('billing_email', pString)) {
// Try to create user in-line
$t_user = new ca_users();
if ($t_user->load(array('user_name' => $vs_user_name))) {
if ($t_user->get('active') == 1) {
// user is active - if not active don't use
if ($t_user->get('userclass') == 255) {
// user is deleted
$t_user->setMode(ACCESS_WRITE);
$t_user->set('userclass', 1);
// 1=public user (no back-end login)
$t_user->update();
if ($t_user->numErrors()) {
$this->notification->addNotification(_t('Errors occurred when undeleting user: %1', join('; ', $t_user->getErrors())), __NOTIFICATION_TYPE_ERROR__);
} else {
$vn_user_id = $t_user->getPrimaryKey();
}
} else {
$vn_user_id = $t_user->getPrimaryKey();
}
} else {
$t_user->setMode(ACCESS_WRITE);
$t_user->set('active', 1);
$t_user->set('userclass', 1);
// 1=public user (no back-end login)
$t_user->update();
if ($t_user->numErrors()) {
$this->notification->addNotification(_t('Errors occurred when reactivating user: %1', join('; ', $t_user->getErrors())), __NOTIFICATION_TYPE_ERROR__);
} else {
$vn_user_id = $t_user->getPrimaryKey();
}
}
} else {
$t_user->setMode(ACCESS_WRITE);
$t_user->set('user_name', $vs_user_name);
$t_user->set('password', $vs_password = substr(md5(uniqid(microtime())), 0, 6));
$t_user->set('userclass', 1);
// 1=public user (no back-end login)
$t_user->set('fname', $vs_fname = $this->request->getParameter('billing_fname', pString));
$t_user->set('lname', $vs_lname = $this->request->getParameter('billing_lname', pString));
$t_user->set('email', $vs_user_name);
$t_user->insert();
if ($t_user->numErrors()) {
$this->notification->addNotification(_t('Errors occurred when creating new user: %1', join('; ', $t_user->getErrors())), __NOTIFICATION_TYPE_ERROR__);
} else {
$vn_user_id = $t_user->getPrimaryKey();
$this->notification->addNotification(_t('Created new client login for <em>%1</em>. Login name is <em>%2</em> and password is <em>%3</em>', $vs_fname . ' ' . $vs_lname, $vs_user_name, $vs_password), __NOTIFICATION_TYPE_INFO__);
// Create related entity?
}
}
}
}
if ($vn_user_id) {
// try to create transaction
$t_trans = new ca_commerce_transactions();
$t_trans->setMode(ACCESS_WRITE);
$t_trans->set('user_id', $vn_user_id);
$t_trans->set('short_description', "Created on " . date("c"));
$t_trans->set('set_id', null);
$t_trans->insert();
//.........这里部分代码省略.........
示例6: register
//.........这里部分代码省略.........
}
} else {
// already valid login with this user name
$va_errors["email"] = _t("A user has already registered with this email address");
}
}
//if (!sizeof($va_errors)) {
# get names of form fields
$va_fields = $t_user->getFormFields();
# loop through fields
foreach ($va_fields as $vs_f => $va_attr) {
switch ($vs_f) {
case "user_name":
if (!$vb_user_exists_but_is_deleted && !sizeof($va_errors)) {
# set field value
$t_user->set("user_name", $ps_email);
if ($t_user->numErrors() > 0) {
$va_errors[$vs_f] = join("; ", $t_user->getErrors());
}
}
break;
# -------------
# -------------
case "active":
$t_user->set("active", 1);
break;
# -------------
# -------------
case "userclass":
$t_user->set("userclass", 1);
// 1=public-only
break;
# -------------
# -------------
default:
if (!$va_errors[$vs_f]) {
$t_user->set($vs_f, $_REQUEST[$vs_f]);
# set field values
if ($t_user->numErrors() > 0) {
$va_errors[$vs_f] = join("; ", $t_user->getErrors());
}
}
break;
# -------------
}
}
//}
if (sizeof($va_errors) == 0) {
# --- there are no errors so make new user record
$t_user->setMode(ACCESS_WRITE);
if ($vb_user_exists_but_is_deleted) {
$t_user->update();
} else {
$t_user->insert();
}
$pn_user_id = $t_user->get("user_id");
if ($t_user->numErrors()) {
$va_errors["register"] = join("; ", $t_user->getErrors());
} else {
# --- send email confirmation
# -- generate mail text from template
ob_start();
require $this->request->getViewsDirectoryPath() . "/mailTemplates/reg_conf.tpl";
$vs_mail_message = ob_get_contents();
ob_end_clean();
caSendmail($t_user->get('email'), $this->request->config->get("ca_admin_email"), "[" . $this->request->config->get("app_display_name") . "] " . _t("Thank you for registering!"), $vs_mail_message);
$t_user = new ca_users();
# log in the new user
$this->request->doAuthentication(array('dont_redirect' => true, 'user_name' => $ps_email, 'password' => $ps_password));
if ($this->request->isLoggedIn()) {
# --- login successful so redirect to search page
$this->notification->addNotification(_t('Thank you for registering! You are now logged in.'), __NOTIFICATION_TYPE_INFO__);
$vo_session = $this->request->getSession();
$vs_last_page = $vo_session->getVar('site_last_page');
$vo_session->setVar('site_last_page', "");
switch ($vs_last_page) {
case "Sets":
$this->response->setRedirect(caNavUrl($this->request, "", "Sets", "addItem", array("object_id" => $vo_session->getVar('site_last_page_object_id'))));
break;
# --------------------
# --------------------
case "ObjectDetail":
$this->response->setRedirect(caNavUrl($this->request, "Detail", "Object", "Show", array("object_id" => $vo_session->getVar('site_last_page_object_id'))));
break;
# --------------------
# --------------------
default:
$this->response->setRedirect(caNavUrl($this->request, "", "", ""));
break;
# --------------------
}
} else {
$va_errors["register"] = _t("Login failed.");
}
}
} else {
$this->view->setVar('reg_errors', $va_errors);
}
$this->form($t_user);
}