本文整理汇总了PHP中User::getByUserName方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getByUserName方法的具体用法?PHP User::getByUserName怎么用?PHP User::getByUserName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User
的用法示例。
在下文中一共展示了User::getByUserName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCanCurrentUserAccessAllComponentsWithLimitedAccessUser
public function testCanCurrentUserAccessAllComponentsWithLimitedAccessUser()
{
Yii::app()->user->userModel = User::getByUserName('bobby');
$componentForms = array();
$filter = new FilterForReportForm('AccountsModule', 'Account', Report::TYPE_ROWS_AND_COLUMNS);
$filter->attributeIndexOrDerivedType = 'officePhone';
$filter->operator = OperatorRules::TYPE_EQUALS;
$filter->value = '123456789';
$componentForms[] = $filter;
$this->assertFalse(ReportSecurityUtil::canCurrentUserAccessAllComponents($componentForms));
Yii::app()->user->userModel->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS);
Yii::app()->user->userModel->save();
$this->assertTrue(ReportSecurityUtil::canCurrentUserAccessAllComponents($componentForms));
//Test that bobby cannot access the related contacts
$filter2 = new FilterForReportForm('AccountsModule', 'Account', Report::TYPE_ROWS_AND_COLUMNS);
$filter2->attributeIndexOrDerivedType = 'contacts___website';
$filter2->operator = OperatorRules::TYPE_EQUALS;
$filter2->value = 'zurmo.com';
$componentForms[] = $filter2;
$this->assertFalse(ReportSecurityUtil::canCurrentUserAccessAllComponents($componentForms));
//Now add access, and bobby can.
Yii::app()->user->userModel->setRight('ContactsModule', ContactsModule::RIGHT_ACCESS_CONTACTS);
Yii::app()->user->userModel->save();
$this->assertTrue(ReportSecurityUtil::canCurrentUserAccessAllComponents($componentForms));
}
示例2: on_submit
function on_submit()
{
$status = (int) Url::get('status');
$sms_total = (int) Url::get('sms_total');
$user_name = Url::get('user_name', '');
$note = Url::get('note', '');
if ($user_name != '') {
if (DB::select("sms_user_active", "user_name='{$user_name}'")) {
$this->setFormError("user_name", "Thành viên này đã tồn tại trong danh sách quản lý THÀNH VIÊN CHỨNG THỰC");
} else {
if ($status == 1) {
//Kích hoạt
$user = User::getByUserName($user_name);
$this->a_row['a_time'] = TIME_NOW;
if ($user) {
if ($user['level'] == 0) {
DB::query("UPDATE account SET level = 1 WHERE id={$user['id']}");
if (MEMCACHE_ON) {
$user['level'] = 1;
eb_memcache::do_put("user:{$user['id']}", $user);
}
}
} else {
$this->setFormError('', "Tài khoản không tồn tại!");
}
} else {
//Bỏ Kích hoạt
$this->a_row['a_time'] = 0;
$user = User::getByUserName($user_name);
if ($user) {
if ($user['level'] == 1) {
DB::query("UPDATE account SET level = 0 WHERE id={$user['id']}");
if (MEMCACHE_ON) {
$user['level'] = 0;
eb_memcache::do_put("user:{$user['id']}", $user);
}
}
} else {
$this->setFormError('', "Tài khoản không tồn tại!");
}
}
if (!$this->errNum) {
$this->a_row['user_id'] = $user['id'];
$this->a_row['user_name'] = $user['user_name'];
$this->a_row['sms_total'] = (int) ($sms_total <= 0 ? 0 : $sms_total);
$this->a_row['status'] = $status;
$this->a_row['note'] = $note;
DB::insert("sms_user_active", $this->a_row);
Url::redirect_current();
}
}
} else {
$this->setFormError('user_name', "Bạn chưa nhập vào tài khoản!");
}
}
示例3: newUserWithClientData
public static function newUserWithClientData($username, $password)
{
$user = User::getByUserName($username);
if ($user == 0) {
$instance = new self();
$instance->username = $username;
$instance->password = md5($password);
$instance->token = md5(uniqid($username, true));
return $instance;
}
return false;
}
示例4: testAddingComments
/**
* @depends testCreateAndGetSocialItemById
*/
public function testAddingComments()
{
$socialItems = SocialItem::getAll();
$this->assertEquals(1, count($socialItems));
$socialItem = $socialItems[0];
$steven = User::getByUserName('steven');
$latestStamp = $socialItem->latestDateTime;
//latestDateTime should not change when just saving the social item
$this->assertTrue($socialItem->save());
$this->assertEquals($latestStamp, $socialItem->latestDateTime);
sleep(2);
// Sleeps are bad in tests, but I need some time to pass
//Add comment, this should update the latestDateTime,
$comment = new Comment();
$comment->description = 'This is my first comment';
$socialItem->comments->add($comment);
$this->assertTrue($socialItem->save());
$this->assertNotEquals($latestStamp, $socialItem->latestDateTime);
}
示例5: testCopyingAModelOwnedByAnotherUserWhereYouHaveRestrictedAccess
/**
* Ensures another user can 'clone' an account they can see, but is not necessarily the owner and does not have
* super privileges.
*/
public function testCopyingAModelOwnedByAnotherUserWhereYouHaveRestrictedAccess()
{
Yii::app()->user->userModel = User::getByUsername('super');
$account = AccountTestHelper::createAccountByNameForOwner('a super account', Yii::app()->user->userModel);
//This will simulate sally having access to 'clone' the account.
$sally = User::getByUserName('sally');
$account->addPermissions($sally, Permission::READ);
$account->save();
AllPermissionsOptimizationUtil::securableItemGivenReadPermissionsForUser($account, $sally);
Yii::app()->user->userModel = User::getByUsername('sally');
$copyOfAccount = new Account();
ZurmoCopyModelUtil::copy($account, $copyOfAccount);
$saved = $copyOfAccount->save();
$this->assertTrue($saved);
}
示例6:
<?php
require_once "../config.php";
$userName = $_POST['username'];
$password = $_POST['password'];
if ($userName != null && $password != null) {
$user = User::getByUserName($userName);
if ($user == false) {
http_response_code(402);
echo json_encode(array('error' => "This username not found."));
} else {
$md5 = md5($password);
if ($user->password == $md5) {
echo json_encode(array('id' => $user->id, 'username' => $user->username, 'password' => $user->password, 'token' => $user->token));
} else {
http_response_code(402);
echo json_encode(array('error' => "Password is wrong."));
}
}
} else {
http_response_code(402);
echo json_encode(array('error' => "Username or password missing."));
}
示例7: add_user_payandship
function add_user_payandship()
{
$username = Url::get('username');
$status = Url::get('status');
$create_date = Url::get('create_date');
$contract = Url::get('contract');
$add_type = Url::get('add_type');
$add_gold = Url::get('add_gold');
$add_month = Url::get('add_month');
if (!$username) {
echo 'err_username';
exit;
}
$user_detail = User::getByUserName($username);
if (!$user_detail) {
echo "not_exist";
exit;
}
$exist_user = DB::fetch("SELECT account_id FROM account_payship WHERE account_name = " . "'" . $username . "'");
if ($exist_user) {
echo "exist_user";
exit;
}
$admin_user = User::user_name();
if ($create_date) {
$date_arr = explode('-', $create_date);
if (isset($date_arr[0]) && isset($date_arr[1]) && isset($date_arr[2])) {
$create_date = mktime(23, 59, 59, (int) $date_arr[1], (int) $date_arr[0], (int) $date_arr[2]);
} else {
$create_date = TIME_NOW;
}
} else {
$create_date = TIME_NOW;
}
if (!empty($add_type)) {
$time_start1 = date("Y-m-d-H-m-s");
$time_start2 = explode('-', $time_start1);
$time_start = mktime((int) $time_start2[3], (int) $time_start2[4], (int) $time_start2[5], (int) $time_start2[1], (int) $time_start2[2], (int) $time_start2[0]);
$time_end1 = strtotime('+' . $add_month . ' month', strtotime($time_start1));
$time_end2 = date("Y-m-d-H-m-s", $time_end1);
$time_end3 = explode('-', $time_end2);
$time_end = mktime((int) $time_end3[3], (int) $time_end3[4], (int) $time_end3[5], (int) $time_end3[1], (int) $time_end3[2], (int) $time_end3[0]);
$type_payship = 3;
$user_golddetail = DB::fetch("SELECT * FROM account WHERE user_name = '{$username}' LIMIT 1");
if ($user_golddetail["gold"] < $add_gold) {
echo "exit_gold";
exit;
}
DB::query("UPDATE `account` SET payship = {$type_payship}, gold = gold - {$add_gold} WHERE user_name = '{$username}' LIMIT 1");
$data_gold_log = array('user_id' => $user_detail['id'], 'user_name' => $user_detail['user_name'], 'time' => TIME_NOW, 'gold' => -$add_gold, 'gold_before' => $user_golddetail["gold"], 'gold_after' => $user_golddetail["gold"] - $add_gold, 'type_use' => '14', 'type_gold' => '2', 'note' => 'Trừ ' . $add_gold . ' gold của user đăng tin sử dụng tools quản lý');
DB::insert('gold_log', $data_gold_log);
} else {
$add_type = 1;
DB::query("UPDATE `account` SET payship = 1 WHERE user_name = '{$username}' LIMIT 1");
}
$data = array('account_id' => $user_detail['id'], 'account_name' => $user_detail['user_name'], 'email' => $user_detail['email'], 'address' => $user_detail['address'], 'mobile_phone' => $user_detail['mobile_phone'], 'user_modifie' => $admin_user, 'created_date' => $create_date, 'modifie_date' => TIME_NOW, 'contract' => $contract, 'type' => $add_type, 'time_start' => $time_start, 'time_end' => $time_end, 'status' => $status);
DB::insert('account_payship', $data);
if (MEMCACHE_ON) {
eb_memcache::do_remove("user:" . $user_golddetail['id']);
}
// User::getUser($user_detail['id'],1);
echo "success";
exit;
}
示例8: check_get_user
static function check_get_user()
{
if (Url::get('user_id')) {
if (User::is_login() && User::id() == Url::get('user_id')) {
CGlobal::$user_profile = User::$current->data;
} else
CGlobal::$user_profile = User::getUser(Url::get('user_id'));
}
if (!CGlobal::$user_profile && Url::get('user_name')) {
if (User::is_login() && User::user_name() == Url::get('user_name')) {
CGlobal::$user_profile = User::$current->data;
} else {
CGlobal::$user_profile = User::getByUserName(Url::get('user_name'));
}
}
/*if(!CGlobal::$user_profile && Url::get('id')){
if(User::is_login() && User::user_name()==Url::get('id')){
CGlobal::$user_profile = User::$current->data;
}
else{
CGlobal::$user_profile = User::getByUserName(Url::get('id'));
}
}*/
if (!CGlobal::$user_profile && User::is_login() && in_array(EClass::$page['name'], array('personal', 'message', 'cart', 'gold_history'))) {
CGlobal::$user_profile = User::$current->data;
}
if (!CGlobal::$user_profile) {
Url::access_denied();
}
}
示例9: testAddingComments
/**
* @depends testCreateAndGetConversationById
*/
public function testAddingComments()
{
$conversations = Conversation::getAll();
$this->assertEquals(1, count($conversations));
$conversation = $conversations[0];
$steven = User::getByUserName('steven');
$latestStamp = $conversation->latestDateTime;
//latestDateTime should not change when just saving the conversation
$conversation->conversationParticipants->offsetGet(0)->hasReadLatest = true;
$conversation->ownerHasReadLatest = true;
$this->assertTrue($conversation->save());
$this->assertEquals($latestStamp, $conversation->latestDateTime);
$this->assertEquals(1, $conversation->ownerHasReadLatest);
sleep(2);
// Sleeps are bad in tests, but I need some time to pass
//Add comment, this should update the latestDateTime,
//and also it should reset hasReadLatest on conversation participants
$comment = new Comment();
$comment->description = 'This is my first comment';
$conversation->comments->add($comment);
$this->assertTrue($conversation->save());
$this->assertNotEquals($latestStamp, $conversation->latestDateTime);
$this->assertEquals(0, $conversation->conversationParticipants->offsetGet(0)->hasReadLatest);
//super made the comment, so this should remain the same.
$this->assertEquals(1, $conversation->ownerHasReadLatest);
//set it to read latest
$conversation->conversationParticipants->offsetGet(0)->hasReadLatest = true;
$this->assertTrue($conversation->save());
$this->assertEquals(1, $conversation->conversationParticipants->offsetGet(0)->hasReadLatest);
//have steven make the comment. Now the ownerHasReadLatest should set to false, and hasReadLatest should remain true
Yii::app()->user->userModel = $steven;
$conversation = Conversation::getById($conversation->id);
$comment = new Comment();
$comment->description = 'This is steven`\\s first comment';
$conversation->comments->add($comment);
$this->assertTrue($conversation->save());
$this->assertEquals(1, $conversation->conversationParticipants->offsetGet(0)->hasReadLatest);
$this->assertEquals(0, $conversation->ownerHasReadLatest);
}
示例10: testUserCanAccessAccountsButCannotCreateAccountShowConvertAction
/**
* @depends testUserHasNoAccessToAccountsAndTriesToConvertWhenAccountIsOptional
*/
public function testUserCanAccessAccountsButCannotCreateAccountShowConvertAction()
{
$super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
$belina = User::getByUserName('belina');
$lead = LeadTestHelper::createLeadbyNameForOwner('BelinaLead1', $belina);
$belina->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS, Right::ALLOW);
$this->assertTrue($belina->save());
$belina = $this->logoutCurrentUserLoginNewUserAndGetByUsername('belina');
$convertToAccountSetting = LeadsModule::getConvertToAccountSetting();
$this->assertEquals(Right::DENY, $belina->getEffectiveRight('AccountsModule', AccountsModule::RIGHT_CREATE_ACCOUNTS));
//The convert view should load up normally, except the option to create an account will not be pressent.
//This tests that the view does in fact come up.
$this->setGetArray(array('id' => $lead->id));
$this->runControllerWithNoExceptionsAndGetContent('leads/default/convert');
}
示例11: _do_massCreateUsers
function _do_massCreateUsers()
{
$aIds = KTUtil::arrayGet($_REQUEST, 'id');
$oSource =& KTAuthenticationSource::get($_REQUEST['source_id']);
$oAuthenticator = $this->getAuthenticator($oSource);
$aNames = array();
foreach ($aIds as $sId) {
$aResults = $oAuthenticator->getUser($sId);
$dn = $sId;
$sUserName = $aResults[$this->aAttributes[1]];
// With LDAP, if the 'uid' is null then try using the 'givenname' instead.
// See activedirectoryauthenticationprovider.inc.php and ldapauthenticationprovider.inc.php for details.
if ($this->sAuthenticatorClass == "KTLDAPAuthenticator" && empty($sUserName)) {
$sUserName = strtolower($aResults[$this->aAttributes[2]]);
}
$sName = $aResults[$this->aAttributes[0]];
$sEmailAddress = $aResults[$this->aAttributes[4]];
$sMobileNumber = $aResults[$this->aAttributes[5]];
// If the user already exists append some text so the admin can see the duplicates.
$appending = true;
while ($appending) {
if (!PEAR::isError(User::getByUserName($sUserName))) {
$sUserName = $sUserName . "_DUPLICATE";
$appending = true;
} else {
$appending = false;
}
}
$oUser = User::createFromArray(array("Username" => $sUserName, "Name" => $sName, "Email" => $sEmailAddress, "EmailNotification" => true, "SmsNotification" => false, "MaxSessions" => 3, "authenticationsourceid" => $oSource->getId(), "authenticationdetails" => $dn, "authenticationdetails2" => $sUserName, "password" => ""));
$aNames[] = $sName;
}
$this->successRedirectToMain(_kt("Added users") . ": " . join(', ', $aNames));
}
示例12: testSavePermission
public function testSavePermission()
{
$account = new Account();
$account->name = 'Yooples';
$account->addPermissions(User::getByUserName('billy'), Permission::READ);
$this->assertTrue($account->save());
}
示例13: draw
function draw()
{
global $display;
$this->beginForm();
$join_field = '';
$join = '';
$where_join = '';
$where = '';
$order_by = Url::get('order_by', 1);
$time = "sms_user_active.c_time";
if ($order_by == 1) {
$order = ' ORDER BY sms_user_active.id DESC';
} elseif ($order_by == 2) {
$order = ' ORDER BY sms_user_active.a_time,sms_user_active.id';
$time = "sms_user_active.a_time";
} elseif ($order_by == 3) {
$order = ' ORDER BY sms_user_active.c_time,sms_user_active.id';
} elseif ($order_by == 4) {
$order = ' ORDER BY sms_user_active.l_time,sms_user_active.id';
$time = "sms_user_active.l_time";
} elseif ($order_by == 5) {
$order = ' ORDER BY sms_user_active.sms_total DESC,sms_user_active.id';
$time = "sms_user_active.l_time";
} elseif ($order_by == 6) {
$order = ' ORDER BY sms_user_active.sms_total,sms_user_active.id';
$time = "sms_user_active.l_time";
}
$page = Url::get('page', 1);
$a_id = Url::get('a_id', 0);
$m_user_name = Url::get('m_user_name', '');
$user_name = Url::get('user_name');
$status = Url::get('status', 0);
if ($user_name) {
$user = User::getByUserName($user_name);
if ($user) {
$where .= ($where != '' ? ' AND ' : 'WHERE ') . " sms_user_active.user_id = '{$user['id']}'";
} else {
$where .= ($where != '' ? ' AND ' : 'WHERE ') . " 0 ";
}
}
if ($m_user_name) {
$where .= ($where != '' ? ' AND ' : 'WHERE ') . " sms_user_active.m_user_name = '{$m_user_name}'";
}
if ($a_id) {
$where .= ($where != '' ? ' AND ' : 'WHERE ') . " sms_user_active.id = {$a_id}";
}
if ($status == 3) {
$where .= ($where != '' ? ' AND ' : 'WHERE ') . " sms_user_active.status = 0";
} elseif ($status == 4) {
$join_field = ", account.level";
$join = " LEFT JOIN account ON account.id = sms_user_active.user_id";
$where_join = ($where != '' ? ' AND ' : 'WHERE ') . " sms_user_active.status = 1 AND (account.level < 1 OR account.level IS NULL)";
//$where.=($where!=''?' AND ':'WHERE ')." (status = 1 AND user_id IN (SELECT id FROM account WHERE level < 1))";
} elseif ($status) {
$where .= ($where != '' ? ' AND ' : 'WHERE ') . " sms_user_active.status = {$status}";
}
$date_start = Url::get('date_start');
$date_end = Url::get('date_end');
if ($date_start) {
$arr = explode('-', $date_start);
$where .= ($where != '' ? ' AND ' : 'WHERE ') . " {$time}>=" . mktime(0, 0, 0, $arr[1], $arr[0], $arr[2]);
}
if ($date_end) {
$arr = explode('-', $date_end);
$where .= ($where != '' ? ' AND ' : 'WHERE ') . " {$time}<=" . mktime(23, 59, 59, $arr[1], $arr[0], $arr[2]);
}
$display->add('a_id', $a_id);
$display->add('date_start', $date_start);
$display->add('date_end', $date_end);
$display->add('m_user_name', $m_user_name);
$display->add('order_by', $order_by);
$display->add('user_name', $user_name);
$display->add('status', $status);
$total = DB::fetch("SELECT COUNT(*) AS total_row FROM sms_user_active {$join} {$where} {$where_join}", 'total_row', 0);
$display->add('total', $total);
$pagging = '';
$items = array();
$sms_rows = array();
$item_ids = '';
if ($total) {
//----- Pagging ---------------
$limit = '';
require_once ROOT_PATH . 'core/ECPagging.php';
$pagging = ECPagging::pagingSE($limit, $total, 50, 10, 'page_no', true, ' Thành viên');
//----- Pagging ---------------
// Lấy danh sách user_id để kiểm tra xem user đã thực sự được active trong bảng account hay chưa
$lstIDs = '';
$sql = "SELECT user_id FROM sms_user_active {$where} {$order} {$limit}";
$reIDs = DB::query($sql);
if ($reIDs) {
$lstECSActive = '';
while ($row = mysql_fetch_assoc($reIDs)) {
$lstECSActive .= $lstECSActive ? ',' : '';
$lstECSActive .= $row['user_id'];
}
if ($reIDs) {
$sql = "SELECT id FROM account WHERE level > 0 AND id IN(" . $lstECSActive . ")";
$reActiveIDs = DB::query($sql);
if ($reActiveIDs) {
while ($row = mysql_fetch_assoc($reActiveIDs)) {
//.........这里部分代码省略.........
示例14: draw
//.........这里部分代码省略.........
$od_by = Url::get('order_by');
$od_dir = Url::get('order_dir', 'DESC');
if ($od_by == 'name') {
$order_by = ' ORDER BY user_name ' . $od_dir;
} elseif ($od_by == 'id') {
$order_by = ' ORDER BY id ' . $od_dir;
} elseif ($od_by == 'time') {
$order_by = ' ORDER BY create_time ' . $od_dir;
} elseif ($last_log) {
$order_by = ' ORDER BY last_login ' . $od_dir;
}
if (Url::get('ava')) {
$search_value .= ' AND avatar_url != ""';
$display->add('ava_checked', 'checked');
} else {
$display->add('ava_checked', '');
}
// search ô textbox ID
$id_search = (int) Url::get('id_search', 0);
if ($id_search) {
$search_value .= ' AND id=' . $id_search;
}
if ($id_search == 0) {
$id_search = '';
}
$display->add('id_search', $id_search);
// search ô textbox tài khoản
if (Url::get('text_value') != '') {
$text_value = trim(Url::get('text_value'));
$display->add('text_value', $text_value);
$str_search = str_replace("'", '"', $text_value);
$str_search = str_replace("'", '"', $str_search);
$str_search = str_replace(""", '"', $str_search);
$s_user = User::getByUserName($str_search, true);
if ($s_user) {
$search_value .= " AND id='{$s_user['id']}' ";
} else {
$search_value .= " AND 0 ";
}
}
$cid = 0;
if (Url::get('cid') != 0) {
$cid = trim(Url::get('cid'));
$search_value .= ' AND (CONCAT(",", class_id, ",") LIKE "%,' . $cid . ',%") ';
}
$display->add('id_phone', Url::get('id_phone'));
$item_per_page = Url::get('item_per_page', 50);
$sql_count = 'SELECT COUNT(id) AS total_item FROM account WHERE ' . $search_value;
$total = DB::fetch($sql_count, 'total_item', 0);
$items = array();
$str_id = '';
$uids = '';
if ($total) {
$limit = '';
require_once ROOT_PATH . 'core/ECPagging.php';
$paging = ECPagging::pagingSE($limit, $total, $item_per_page, 10, 'page_no', true, 'Thành viên', 'Trang');
$sql = 'SELECT * FROM account WHERE ' . $search_value . ' ' . $order_by . $limit;
$result = DB::query($sql);
if ($result) {
while ($row = mysql_fetch_assoc($result)) {
$row['create_time'] = date('d/m/y H:i', $row['create_time']);
if ($row['last_login']) {
$row['last_login'] = date('d/m/y H:i', $row['last_login']);
} else {
$row['last_login'] = false;
}
示例15:
/**
* start a root session.
*
* @author KnowledgeTree Team
* @access public
* @return object $session The KTAPI_SystemSession
*/
public function &start_system_session($username = null)
{
if (is_null($username)) {
$user = User::get(1);
} else {
$user = User::getByUserName($username);
}
if (PEAR::isError($user)) {
return new PEAR_Error('Username invalid');
}
$session =& new KTAPI_SystemSession($this, $user);
$this->session =& $session;
return $session;
}