本文整理汇总了PHP中AuthUser::meta方法的典型用法代码示例。如果您正苦于以下问题:PHP AuthUser::meta方法的具体用法?PHP AuthUser::meta怎么用?PHP AuthUser::meta使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AuthUser
的用法示例。
在下文中一共展示了AuthUser::meta方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: forgot
function forgot () {
// Load Auth app
$auth_app = Frix::app('auth');
// Already authorized?
if ($auth_app->get_user()) {
// Go to the admin home
redir(url(self::$root));
}
// Load AuthUser model
$auth_app->load_model('AuthUser');
// Get model meta
$meta = AuthUser::meta();
$f = new Form;
$f->add_fields(array(
'email' => new CharField('E-mail', array('length' => 100)),
));
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Get form data
$f->input($_POST);
$email = $f->get_email();
// Check for a valid e-mail address.
if (!validate_email($email)) {
self::$context['msg'] = sprintf('Invalid e-mail address "%s"!', $email);
self::$context['msg_type'] = 'err';
}
else {
// Get user by e-mail address
$user = $meta->one(array('email' => $email));
if ($user) {
// Create a new password
$pass = make_pass();
$msg =
'Your new passord is:' . "\n" .
$pass . "\n\n" .
'You can log in using your username:' . "\n" .
$user->username
;
// Send the password to the user
$ok = send_mail('New password', $msg, Frix::app('settings')->get('contact_email'), $user->email);
// Error sending the msg?
if (!$ok) {
self::$context['msg'] =
'Couldn\'t send msg.<br />' .
'Password not changed.'
;
self::$context['msg_type'] = 'err';
}
// Message sucessfully sent?
else {
// Change user password and save
$user->set_password($pass);
$user->save();
// Redirect with a success msg
redir('./?sent=1');
}
}
else {
self::$context['msg'] = sprintf('E-mail address "%s" not found!', $email);
self::$context['msg_type'] = 'err';
}
}
}
else {
if ($_GET['sent']) {
self::$context['msg'] =
'The new password was sent!<br />'.
'Please check your inbox.'
;
self::$context['msg_type'] = 'ok';
}
else {
self::$context['msg'] = 'Type your e-mail to get a new password.';
}
}
self::$context['form'] = $f;
$t = new Template('frix/admin/forgot');
echo $t->render(self::$context);
}