本文整理汇总了PHP中UserModel::GetByUsername方法的典型用法代码示例。如果您正苦于以下问题:PHP UserModel::GetByUsername方法的具体用法?PHP UserModel::GetByUsername怎么用?PHP UserModel::GetByUsername使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserModel
的用法示例。
在下文中一共展示了UserModel::GetByUsername方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Add
/**
* Start a new conversation.
*
* @since 2.0.0
* @access public
*
* @param string $Recipient Username of the recipient.
*/
public function Add($Recipient = '')
{
$this->Form->SetModel($this->ConversationModel);
if ($this->Form->AuthenticatedPostBack()) {
$RecipientUserIDs = array();
$To = explode(',', $this->Form->GetFormValue('To', ''));
$UserModel = new UserModel();
foreach ($To as $Name) {
if (trim($Name) != '') {
$User = $UserModel->GetByUsername(trim($Name));
if (is_object($User)) {
$RecipientUserIDs[] = $User->UserID;
}
}
}
$this->Form->SetFormValue('RecipientUserID', $RecipientUserIDs);
$ConversationID = $this->Form->Save($this->ConversationMessageModel);
if ($ConversationID !== FALSE) {
$Target = $this->Form->GetFormValue('Target', 'messages/' . $ConversationID);
$this->RedirectUrl = Url($Target);
}
} else {
if ($Recipient != '') {
$this->Form->SetValue('To', $Recipient);
}
}
if ($Target = Gdn::Request()->Get('Target')) {
$this->Form->AddHidden('Target', $Target);
}
$this->Title(T('New Conversation'));
$this->SetData('Breadcrumbs', array(array('Name' => T('Inbox'), 'Url' => '/messages/inbox'), array('Name' => $this->Data('Title'), 'Url' => 'messages/add')));
$this->Render();
}
示例2: Add
/**
* Add a new conversations.
*/
public function Add($Recipient = '')
{
$this->Form->SetModel($this->ConversationModel);
if ($this->Form->AuthenticatedPostBack()) {
$RecipientUserIDs = array();
$To = explode(',', $this->Form->GetFormValue('To', ''));
$UserModel = new UserModel();
foreach ($To as $Name) {
if (trim($Name) != '') {
$User = $UserModel->GetByUsername(trim($Name));
if (is_object($User)) {
$RecipientUserIDs[] = $User->UserID;
}
}
}
$this->Form->SetFormValue('RecipientUserID', $RecipientUserIDs);
$ConversationID = $this->Form->Save($this->ConversationMessageModel);
if ($ConversationID !== FALSE) {
$this->RedirectUrl = Url('messages/' . $ConversationID);
}
} else {
if ($Recipient != '') {
$this->Form->SetFormValue('To', $Recipient);
}
}
$this->Render();
}
示例3: DiscussionController_Author_Create
/**
* Handle discussion option menu Change Author action.
*/
public function DiscussionController_Author_Create($Sender, $Args)
{
$DiscussionID = $Sender->Request->Get('discussionid');
$Discussion = $Sender->DiscussionModel->GetID($DiscussionID);
if (!$Discussion) {
throw NotFoundException('Discussion');
}
// Check edit permission
$Sender->Permission('Vanilla.Discussions.Edit', TRUE, 'Category', $Discussion->PermissionCategoryID);
if ($Sender->Form->AuthenticatedPostBack()) {
// Change the author
$Name = $Sender->Form->GetFormValue('Author', '');
$UserModel = new UserModel();
if (trim($Name) != '') {
$User = $UserModel->GetByUsername(trim($Name));
if (is_object($User)) {
if ($Discussion->InsertUserID == $User->UserID) {
$Sender->Form->AddError('That user is already the discussion author.');
} else {
// Change discussion InsertUserID
$Sender->DiscussionModel->SetField($DiscussionID, 'InsertUserID', $User->UserID);
// Update users' discussion counts
$Sender->DiscussionModel->UpdateUserDiscussionCount($Discussion->InsertUserID);
$Sender->DiscussionModel->UpdateUserDiscussionCount($User->UserID, TRUE);
// Increment
// Go to the updated discussion
Redirect(DiscussionUrl($Discussion));
}
} else {
$Sender->Form->AddError('No user with that name was found.');
}
}
} else {
// Form to change the author
$Sender->SetData('Title', $Discussion->Name);
}
$Sender->Render('changeauthor', '', 'plugins/AuthorSelector');
}
示例4: get_user_id_by_username
public function get_user_id_by_username($user_login)
{
// Read the user_id for this login
$UserModel = new UserModel();
$result = $UserModel->GetByUsername($user_login, DATASET_TYPE_ARRAY);
return GetValue('Deleted', $result) === '1' ? FALSE : GetValue('UserID', $result);
}
示例5: Authenticate
public function Authenticate()
{
if (!$this->Request->IsPostBack()) {
throw ForbiddenException($this->Request->RequestMethod());
}
$Args = array_change_key_case($this->Form->FormValues());
$UserModel = new UserModel();
// Look up the user.
$User = NULL;
if ($Email = GetValue('email', $Args)) {
$User = $UserModel->GetByEmail($Email);
} elseif ($Name = GetValue('name', $Args)) {
$User = $UserModel->GetByUsername($Name);
} else {
throw new Gdn_UserException("One of the following parameters required: Email, Name.", 400);
}
if (!$User) {
throw NotFoundException('User');
}
// Check the password.
$PasswordHash = new Gdn_PasswordHash();
$Password = $this->Form->GetFormValue('Password');
try {
$PasswordChecked = $PasswordHash->CheckPassword($Password, GetValue('Password', $User), GetValue('HashMethod', $User));
// Rate limiting
Gdn::UserModel()->RateLimit($User, $PasswordChecked);
if ($PasswordChecked) {
$this->SetData('User', ArrayTranslate((array) $User, array('UserID', 'Name', 'Email', 'PhotoUrl')));
if (GetValue('session', $Args)) {
Gdn::Session()->Start($this->Data('User.UserID'));
$this->SetData('Cookie', array(C('Garden.Cookie.Name') => $_COOKIE[C('Garden.Cookie.Name')]));
}
} else {
throw new Exception(T('Invalid password.'), 401);
// Can't be a user exception.
}
} catch (Gdn_UserException $Ex) {
$this->Form->AddError($Ex);
}
$this->Render();
}
示例6: Add
/**
* Start a new conversation.
*
* @since 2.0.0
* @access public
*
* @param string $Recipient Username of the recipient.
*/
public function Add($Recipient = '')
{
$this->Permission('Conversations.Conversations.Add');
$this->Form->SetModel($this->ConversationModel);
// Set recipient limit
if (!CheckPermission('Garden.Moderation.Manage') && C('Conversations.MaxRecipients')) {
$this->AddDefinition('MaxRecipients', C('Conversations.MaxRecipients'));
$this->SetData('MaxRecipients', C('Conversations.MaxRecipients'));
}
if ($this->Form->AuthenticatedPostBack()) {
$RecipientUserIDs = array();
$To = explode(',', $this->Form->GetFormValue('To', ''));
$UserModel = new UserModel();
foreach ($To as $Name) {
if (trim($Name) != '') {
$User = $UserModel->GetByUsername(trim($Name));
if (is_object($User)) {
$RecipientUserIDs[] = $User->UserID;
}
}
}
// Enforce MaxRecipients
if (!$this->ConversationModel->AddUserAllowed(0, count($RecipientUserIDs))) {
// Reuse the Info message now as an error.
$this->Form->AddError(sprintf(Plural($this->Data('MaxRecipients'), "You are limited to %s recipient.", "You are limited to %s recipients."), C('Conversations.MaxRecipients')));
}
$this->EventArguments['Recipients'] = $RecipientUserIDs;
$this->FireEvent('BeforeAddConversation');
$this->Form->SetFormValue('RecipientUserID', $RecipientUserIDs);
$ConversationID = $this->Form->Save($this->ConversationMessageModel);
if ($ConversationID !== FALSE) {
$Target = $this->Form->GetFormValue('Target', 'messages/' . $ConversationID);
$this->RedirectUrl = Url($Target);
}
} else {
if ($Recipient != '') {
$this->Form->SetValue('To', $Recipient);
}
}
if ($Target = Gdn::Request()->Get('Target')) {
$this->Form->AddHidden('Target', $Target);
}
Gdn_Theme::Section('PostConversation');
$this->Title(T('New Conversation'));
$this->SetData('Breadcrumbs', array(array('Name' => T('Inbox'), 'Url' => '/messages/inbox'), array('Name' => $this->Data('Title'), 'Url' => 'messages/add')));
$this->Render();
}