本文整理汇总了PHP中Model_User::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_User::find方法的具体用法?PHP Model_User::find怎么用?PHP Model_User::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model_User
的用法示例。
在下文中一共展示了Model_User::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set
public static function set($username)
{
$user = \Model_User::find('first', array('where' => array('username' => $username)));
$user->group_id = 1;
$user->save();
echo "{$username} is now an admin.";
}
示例2: action_repass
public function action_repass($onepass)
{
if (!Model_User::count(array('where' => array('onepass' => $onepass)))) {
Response::redirect('user/login/without');
}
if (Input::method() == 'POST') {
$val = Model_User::validate('repass');
$val->add_field('email', 'Eメール', 'required|valid_email');
if ($val->run()) {
$user = Model_User::find('first', array('where' => array('onepass' => $onepass)));
$last_login = mb_substr($user['last_login'], -4);
$reset = Input::post('reset');
if ($last_login == $reset) {
$username = Input::post('username');
$email = Input::post('email');
$password = Input::post('password');
if ($username == $user['username'] && $email == $user['email']) {
$user->onepass = md5(time());
$user->save();
$auth = Auth::instance();
$old = $auth->reset_password($username);
$auth->change_password($old, $password, $username);
Response::redirect('user/login');
} else {
Session::set_flash('na', '<p><span class="alert-error">該当者がいません</span></p>');
}
} else {
Session::set_flash('error', "<p>" . $val->show_errors() . "</p>");
}
}
return Model_User::theme('admin/template', 'user/login/repass');
}
}
示例3: action_delete
public function action_delete($user_id)
{
$user = Model_User::find($user_id);
$user->delete();
Session::set_flash('notice', "User {$user->username} deleted");
Response::redirect('-admin/users');
}
示例4: action_addtask
public function action_addtask($project_id)
{
if (!($project = Model_Project::find($project_id))) {
\Fuel\Core\Session::set_flash('error', "Cannot find the selected project # {$project_id}");
\Fuel\Core\Response::redirect_back('user/projects');
}
$val = Model_Projecttask::validate('create');
if (\Fuel\Core\Input::method() == 'POST') {
if ($val->run()) {
$projecttask = Model_Projecttask::forge(array('project_id' => Input::post('project_id'), 'user_id' => Input::post('user_id'), 'project_task_name_id' => Input::post('project_task_name_id'), 'hourly_rate' => Input::post('hourly_rate'), 'task_status' => 0, 'task_due' => Input::post('task_due'), 'project_task_description' => Input::post('project_task_description'), 'comment' => Input::post('comment'), 'priority' => Input::post('priority')));
if ($projecttask and $projecttask->save()) {
Session::set_flash('success', e('Added task #' . $projecttask->id . '.'));
Response::redirect('user/projects/view/' . $project_id);
} else {
Session::set_flash('error', e('Could not save task.'));
}
} else {
\Fuel\Core\Session::set_flash('error', $val->error());
}
}
$this->load_presenter($project, Model_Projecttask::forge(array('id' => 0, 'project_id' => $project->id, 'user_id' => $this->current_user->id, 'task_status' => 0, 'hourly_rate' => 456, 'task_due' => date('Y-m-d'))));
$this->template->set_global('project_task_names', Model_Projecttaskname::find('all', array('order_by' => array(array('name', 'asc')))));
$this->template->set_global('users', array(Model_User::find($this->current_user->id)));
$this->template->set_global('priorities', THelper::get_priorities());
$this->template->title = 'My Projects';
$this->template->content = Fuel\Core\View::forge('user/projects/addtask');
}
示例5: getAuth
/**
* Возвращаем авторизацию
* @return Model_User
*/
public function getAuth()
{
if ($this->_me === null) {
//Читаем токен
$token = Boot_Cookie::get("auth_token");
//Разбиваем токен
@(list($id, $skey, $sig) = explode("#", $token));
if (!$id || !$skey || !$sig) {
$this->_me = false;
Boot_Cookie::clear("auth_token");
return false;
}
//Получаем юзера
try {
$this->_me = Model_User::find($id);
} catch (Exception $e) {
$this->_me = false;
}
//Проверяем корректность
if ($this->_me == false || $skey != Boot_Skey::get() || $sig != md5($id . $skey . $this->_me->skey)) {
$this->_me = false;
Boot_Cookie::clear("auth_token");
return false;
}
}
return $this->_me;
}
示例6: action_order
public function action_order()
{
define("SECONDS_PER_DAY", 3600 * 24);
$now = time();
$cart = Session::get('cart');
$user = Model_User::find($this->sessUser->id);
$cart_info = [];
$order = Model_Order::forge();
$order->user_id = $user->id;
$order->created_at = $now;
$order->save();
if (!is_null($cart)) {
foreach ($cart as $product_id => $quantity) {
$product = Model_Product::find($product_id);
$order_product = Model_OrderProduct::forge();
$order_product->order_id = $order->id;
$order_product->product_id = $product->id;
$order_product->quantity = $quantity;
$order_product->price = $product->price;
$order_product->save();
}
}
Session::delete('cart');
return Response::redirect('/cart');
}
示例7: post_update_profile
public function post_update_profile($id)
{
$errors = [];
$data = null;
$success = false;
if (count($errors)) {
return $this->error($errors);
}
$obj = Model_User::find($id);
if (!$obj) {
$errors[] = 'Cannot find User with ID: ' . $id;
} else {
if (!$obj->profile) {
if (!Input::post('year_level') || !Input::post('course_id')) {
return $this->error('Student has no profile yet, send data for both year_level and course_id');
} else {
$obj->profile = Model_Student::forge(Input::post());
}
}
foreach (Input::post() as $key => $value) {
if ($key == 'password') {
$value = Auth::instance()->hash_password($value);
}
$obj->{$key} = $value;
$obj->profile->{$key} = $value;
}
$success = $obj->save();
if (!$success) {
$errors[] = 'Could not save User';
} else {
$data = $obj;
}
}
return $this->response(['data' => $data, 'success' => $success, 'errors' => $errors]);
}
示例8: action_subscription
public function action_subscription($id = null)
{
is_null($id) and Response::redirect('');
if (!($user = Model_User::find($id))) {
Messages::error('Could not find user #' . $id);
Response::redirect('');
}
$val = \Model_User::validate_subscription('edit');
if ($val->run()) {
$user->delivery_address = Input::post('delivery_address');
$user->delivery_address_2 = Input::post('delivery_address_2');
$user->delivery_city = Input::post('delivery_city');
$user->delivery_state = Input::post('delivery_state');
$user->delivery_zip_code = Input::post('delivery_zip_code');
if ($user->save()) {
Messages::success('Updated user #' . $id);
} else {
Messages::error('Could not update user #' . $id);
}
\Response::redirect('backend/account/index/subscription');
} else {
if (Input::method() == 'POST') {
$user->delivery_address = $val->validated('delivery_address');
$user->delivery_address_2 = $val->validated('delivery_address_2');
$user->delivery_city = $val->validated('delivery_city');
$user->delivery_state = $val->validated('delivery_state');
Session::set_flash('error', $val->error());
}
$data['user'] = $this->_user;
$this->template->content = View::forge('account/subscription/edit', $data);
}
$this->template->title = "Delivery Settings";
$data['user'] = $this->_user;
$this->template->content = View::forge('account/subscription/edit', $data);
}
示例9: action_login
public function action_login()
{
// Already logged in
Auth::check() and Response::redirect('admin');
$val = Validation::forge();
if (Input::method() == 'POST') {
$val->add('email', 'Email or Username')->add_rule('required');
$val->add('password', 'Password')->add_rule('required');
if ($val->run()) {
if (!Auth::check()) {
if (Auth::login(Input::post('email'), Input::post('password'))) {
// assign the user id that lasted updated this record
foreach (\Auth::verified() as $driver) {
if (($id = $driver->get_user_id()) !== false) {
// credentials ok, go right in
$current_user = Model_User::find($id[1]);
Session::set_flash('success', e('Welcome, ' . $current_user->username));
Response::redirect('admin');
}
}
} else {
$this->template->set_global('login_error', 'Login failed!');
}
} else {
$this->template->set_global('login_error', 'Already logged in!');
}
}
}
$this->template->title = 'Login';
$this->template->content = View::forge('admin/login', array('val' => $val), false);
}
示例10: action_index
public function action_index()
{
$this->template = View::forge("teachers/template");
$this->template->auth_status = false;
$this->template->title = "Forgotpassword";
// login
if (Input::post("email", null) !== null and Security::check_token()) {
$email = Input::post('email', null);
$user = Model_User::find("first", ["where" => [["email", $email]]]);
if ($user != null) {
$token = Model_Forgotpasswordtoken::forge();
$token->user_id = $user->id;
$token->token = sha1("asadsada23424{$user->email}" . time());
$token->save();
$url = Uri::base() . "teachers/forgotpassword/form/{$token->token}";
$body = View::forge("email/forgotpassword", ["url" => $url]);
$sendmail = Email::forge("JIS");
$sendmail->from(Config::get("statics.info_email"), Config::get("statics.info_name"));
$sendmail->to($email);
$sendmail->subject("forgot password");
$sendmail->html_body(htmlspecialchars_decode($body));
$sendmail->send();
}
$view = View::forge("teachers/forgotpassword/sent");
$this->template->content = $view;
} else {
$view = View::forge("teachers/forgotpassword/index");
$this->template->content = $view;
}
}
示例11: action_edit
public function action_edit($id = null)
{
$post = Model_Post::find($id);
$val = Model_Post::validate('edit');
if ($val->run()) {
$post->title = Input::post('title');
//$post->slug = Input::post('slug');
$post->summary = Input::post('summary');
$post->body = Input::post('body');
$post->user_id = Input::post('user_id');
if ($post->save()) {
Session::set_flash('success', 'Updated post #' . $id);
Response::redirect('admin/posts');
} else {
Session::set_flash('error', 'Could not update post #' . $id);
}
} else {
if (Input::method() == 'POST') {
$post->title = $val->validated('title');
$post->slug = $val->validated('slug');
$post->summary = $val->validated('summary');
$post->body = $val->validated('body');
$post->user_id = $val->validated('user_id');
Session::set_flash('error', $val->show_errors());
}
$this->template->set_global('post', $post, false);
}
$this->template->title = "Create Post";
$view = View::forge('admin/posts/create');
// Set some data
$view->set_global('users', Arr::assoc_to_keyval(Model_User::find('all'), 'id', 'username'));
$this->template->content = $view;
}
示例12: action_index
public function action_index()
{
Session::set_flash('success', e('A student is approved by setting a valid year/course.'));
$data['students'] = Model_User::find('all', ['related' => ['profile'], 'where' => ['group' => Model_User::$roles['student']]]);
$this->template->title = "Students";
$this->template->content = View::forge('site/student/index', $data);
}
示例13: openPost
public function openPost($postId)
{
$post = $this->find($postId)->current();
if ($post) {
$mdlContentNode = new Model_PageNode();
$content = $mdlContentNode->fetchContentArray($post->id, null, null, $this->getDefaultLanguage());
$objPost = new stdClass();
$objPost->id = $post->id;
$objPost->title = $post->name;
$objPost->dateCreated = $post->create_date;
$objPost->blogId = $post->parent_id;
if (isset($content['teaser'])) {
$objPost->teaser = $content['teaser'];
} else {
$objPost->teaser = null;
}
if (isset($content['content'])) {
$objPost->content = $content['content'];
} else {
$objPost->content = null;
}
$mdlUser = new Model_User();
$author = $mdlUser->find($post->name)->current();
if ($author) {
$objPost->author = $author->first_name . ' ' . $author->last_name;
} else {
$objPost->author = null;
}
$objPost->name = $post->name;
return $objPost;
} else {
return null;
}
}
示例14: action_new
public function action_new()
{
$data = [];
if (Input::post("firstname", null) != null and Security::check_token()) {
$email = Input::post("email", null);
if ($email != $this->user->email) {
$check_user = Model_User::find("first", ["where" => [["email" => $email]]]);
if ($check_user == null) {
$this->email = $email;
} else {
$data["error"] = "This email is already in use.";
}
}
if (!isset($data["error"])) {
$this->user->firstname = Input::post("firstname", "");
$this->user->middlename = Input::post("middlename", "");
$this->user->lastname = Input::post("lastname", "");
$this->user->google_account = Input::post("google_account", "");
$this->user->password = Auth::instance()->hash_password(Input::post('password', ""));
$this->user->birthday = Input::post("year") . "-" . Input::post("month") . "-" . Input::post("day");
$this->user->google_account = Input::post("google_account");
$this->user->need_reservation_email = Input::post("need_reservation_email");
$this->user->need_news_email = Input::post("need_news_email");
$this->user->timezone = Input::post("timezone");
$this->user->save();
Response::redirect("students");
}
}
$data['pasts'] = Model_Lessontime::find("all", ["where" => [["student_id", $this->user->id], ["status", 2], ["language", Input::get("course", 0)], ["deleted_at", 0]]]);
$data["donetrial"] = Model_Lessontime::find("all", ["where" => [["student_id", $this->user->id], ["status", 2], ["language", Input::get("course", -1)], ["deleted_at", 0]]]);
$view = View::forge("students/setting_new", $data);
$this->template->content = $view;
}
示例15: action_index
public function action_index()
{
$year = Input::get("year", date("Y"));
$month = Input::get("month", date("m"));
$grade = Model_Grade::find("first", ["where" => [["year", $year], ["month", $month]]]);
if ($grade == null) {
$grade = Model_Grade::forge();
$grade->year = $year;
$grade->month = $month;
$grade->grade_1 = Config::get("prices")[0];
$grade->grade_2 = Config::get("prices")[1];
$grade->grade_3 = Config::get("prices")[2];
$grade->grade_4 = Config::get("prices")[3];
$grade->grade_5 = Config::get("prices")[4];
$grade->save();
}
$data["teachers"] = Model_User::find("all", ["where" => [["group_id", 10], ["deleted_at", 0]], "order_by" => [["id", "desc"]]]);
foreach ($data["teachers"] as $teacher) {
$teacher->count = Model_Lessontime::count(["where" => [["deleted_at", 0], ["teacher_id", $teacher->id], ["feedback", "<>", ""], ["freetime_at", ">=", strtotime("{$year}-{$month}-01")], ["freetime_at", "<", strtotime("{$year}-{$month}-01 +1 month")]]]);
}
$data["year"] = $year;
$data["month"] = $month;
$data["grade"] = $grade;
$view = View::forge("admin/fee/index", $data);
$this->template->content = $view;
}