本文整理汇总了PHP中app\models\User::findByPk方法的典型用法代码示例。如果您正苦于以下问题:PHP User::findByPk方法的具体用法?PHP User::findByPk怎么用?PHP User::findByPk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\User
的用法示例。
在下文中一共展示了User::findByPk方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionDelete
public function actionDelete()
{
$models = User::findAllByPk($_POST['User']);
$number = 0;
$names = [];
foreach ($models as $model) {
$names[] = $model->name;
$number += (int) $model->delete();
}
User::findByPk(WebApp::get()->user()->id)->logAction(UserHistory::ACTION_ADMINDELETE, "Users: \n", implode("\n ", $names));
if (1 !== $number) {
Messages::get()->success("User deleted!");
} else {
Messages::get()->success("{$number} users deleted!");
}
$this->getRequest()->goBack();
}
示例2: actionIndex
public function actionIndex()
{
$user = User::findByPk($this->container->user->getID(), $this->container);
if (!$user) {
$this->redirect('/logout');
}
/** @var array $setup */
if ($setup = $this->container->request->post('Setup')) {
if (!empty($setup['pass'])) {
$user->pass = md5($setup['pass']);
}
if (!empty($setup['fio'])) {
$user->fio = $setup['fio'];
}
$user->save();
}
$v = new View($this->container);
$v->addParameter('user', $user);
return $v;
}
示例3: actionDeleteUser
public function actionDeleteUser($id)
{
User::findByPk($id)->delete();
$this->redirect('/admin/users');
}
示例4: checkGoogle
public function checkGoogle($force = false)
{
if (is_null($client = $this->getGoogleClient($force))) {
return null;
}
if (!isset($_GET['code']) || isset($_GET['state'])) {
return null;
}
$this->debug($_GET['code']);
$client->authenticate($_GET['code']);
$user = $this->googleOauth->userinfo->get();
$details = ['id' => $user['id'], 'name' => filter_var($user['name'], FILTER_SANITIZE_SPECIAL_CHARS), 'email' => filter_var($user['email'], FILTER_SANITIZE_EMAIL), 'profile_url' => filter_var($user['link'], FILTER_VALIDATE_URL), 'image_url' => filter_var($user['picture'], FILTER_VALIDATE_URL)];
if ($force) {
$user = User::findByPk($this->id);
$user->google_id = $details['id'];
UserConfig::set('GOOGLE_NAME', $details['name']);
UserConfig::set('GOOGLE_EMAIL', $details['email']);
UserConfig::set('GOOGLE_PROFILE', $details['profile_url']);
UserConfig::set('GOOGLE_IMAGE', $details['image_url']);
return $user->save(false);
}
if (!is_null($user = User::findByAttributes(['google_id' => $details['id']]))) {
return $user;
}
return User::googleRegister($details);
}
示例5: getRules
public static function getRules()
{
return array(array('name, email, comment', 'required, safe', 'on' => 'admin-insert'), array('name, email, newPassword, repeatedPassword', 'required, safe', 'on' => 'register'), array('email, newEmail', 'unique, email', 'column' => 'email', 'on' => 'register, change-email'), array('name', 'safe', 'on' => 'user-edit'), array('name, newPassword, repeatedPassword', 'safe, required', 'on' => 'register-auto'), array('name, email, groupIDs, status, title_id', 'safe', 'on' => 'admin-edit'), array('name, password', 'required, safe', 'on' => 'login'), array('name', 'unique', 'on' => 'register'), array('newEmail, oldPassword', 'required', 'on' => 'change-email'), array('email', 'required', 'on' => 'forgot-password'), array('oldPassword, newPassword, repeatedPassword', 'required', 'on' => 'change-password'), array('repeatedPassword', 'compare', 'column' => 'newPassword'), array('oldPassword', function (Validator $validator, $field, $options, $label, $message) {
// check if old password is correct
if (User::hashPassword($validator->getValue($field)) == User::findByPk(WebApp::get()->user()->id)->password) {
return true;
}
throw new \Exception($message ? $message : $validator->translate($label . ' is wrong!'));
}, 'on' => 'change-password, change-email'));
}
示例6: actionValidateEmail
/**
* Sends a request to User to validate new email
* @param $code
*/
public function actionValidateEmail($code)
{
list($id, $code) = explode(".", $code, 2);
$user = \app\models\User::findByPk($id);
if (!$user) {
$this->assign('error', true);
return;
}
if ($user->validateEmail($code, true)) {
$this->assign('success', true);
$this->assign('error', false);
return;
}
$this->assign('error', true);
}