public function action_create() { $val = Model_User::validate('create'); if (Input::method() == 'POST') { if ($val->run()) { $user = Model_User::forge(array('username' => \Fuel\Core\Input::post('username'), 'email' => \Fuel\Core\Input::post('email'), 'group' => \Fuel\Core\Input::post('group'), 'password' => \Fuel\Core\Input::post('password'), 'first_name' => \Fuel\Core\Input::post('first_name'), 'last_name' => \Fuel\Core\Input::post('last_name'), 'target_billable' => \Fuel\Core\Input::post('target_billable'), 'target_unbillable' => \Fuel\Core\Input::post('target_unbillable'))); try { if ($user and Auth\Auth::create_user($user->username, $user->password, $user->email, $user->group, array('fullname' => ''))) { Session::set_flash('success', e('Added user #' . $user->id . '.')); Response::redirect('admin/users'); } else { Session::set_flash('error', e('Could not save user.')); } } catch (\SimpleUserUpdateException $ex) { // duplicate email address if ($ex->getCode() == 2) { Fuel\Core\Session::set_flash('error', 'Email already exists.'); } elseif ($ex->getCode() == 3) { Fuel\Core\Session::set_flash('error', 'Username already exists.'); } else { Fuel\Core\Session::set_flash('error', $ex->getMessage()); } } } else { Session::set_flash('error', $val->error()); } } $this->template->set_global('user', new Model_User(array('id' => 0)), false); $this->template->set_global('val', $val, false); $this->template->set_global('groups', $this->get_groups_list()); $this->template->title = "Users"; $this->template->content = View::forge('admin/users/create'); }
/** * Validate password * * @access public * @author Dao Anh Minh */ public static function _validation_change_pass($old_pass, $account_id) { Validation::active()->set_message('change_pass', 'Mật khẩu cũ không đúng'); $account = Model_Account::query()->where('id', $account_id)->where('password', Auth\Auth::instance()->hash_password($old_pass))->count(); if ($account > 0) { return true; } else { return false; } }
<?php require 'init.php'; if (!empty($_GET['mail']) && !empty($_GET['pass']) && !empty($_GET['pass2']) && !empty($_GET['name'])) { var_dump(Auth\Auth::register($_GET['mail'], $_GET['name'], $_GET['pass'], $_GET['pass2'])); } ?> <form> <label>mail</label> <input type="email" name="mail"> <label>name</label> <input type="text" name="name"> <label>pass</label> <input type="password" name="pass"> <label>pass2</label> <input type="password" name="pass2"> <input type="submit"> </form>
public function action_logtimes($timestamp = null) { if (!Auth\Auth::has_access('timesheets.read')) { Fuel\Core\Session::set_flash('error', 'You do not have access to view timesheets'); Fuel\Core\Response::redirect('user'); } if (!$timestamp) { $timestamp = \Fuel\Core\Date::forge()->get_timestamp(); // today } if (Fuel\Core\Input::method() == 'POST') { try { // start a db transaction \Fuel\Core\DB::start_transaction(); // find all logs for this task for this day $date = date('Y-m-d', $timestamp); $starts = date('Y-m-d 00:00:00', $timestamp); $ends = date('Y-m-d 23:59:59', $timestamp); $project_task_logs = Model_Projecttasklog::find('all', array('related' => array('project_task'), 'where' => array(array('project_task.user_id', $this->current_user->id), array('task_started', 'BETWEEN', array($starts, $ends))))); foreach ($project_task_logs as $log) { $date_starts = date('Y-m-d', $timestamp); $date_ends = date('Y-m-d 23:59:59', $timestamp); if ($log->get_project_task()->user_id == $this->current_user->id) { if (in_array(strtotime($log->task_started), range(strtotime($date_starts), strtotime($date_ends)))) { // delete the logs $log->delete(); } } } // insert new logs if (Fuel\Core\Input::post('timeslots')) { $date = date('Y-m-d', $timestamp); $last_comment = ''; $last_task_id = ''; foreach (Fuel\Core\Input::post('timeslots') as $str) { $times = explode('_', $str); $is_billable = 0; $task_started = $date . ' ' . $times[0] . ':00'; $task_completed = $date . ' ' . $times[1] . ':00'; $project_task_id_array = Fuel\Core\Input::post('project_task_id'); $task_id = $project_task_id_array["'{$str}'"]; if (Fuel\Core\Input::post('comment_' . $str) != '') { $last_comment = Fuel\Core\Input::post('comment_' . $str); } if (intval(Fuel\Core\Input::post('is_billable_' . $str, '0')) == 1) { $is_billable = 1; } if (empty($task_id)) { $task_id = $last_task_id; } else { $last_task_id = $task_id; } if (empty($task_id)) { continue; // todo - display error } $task_log = Model_Projecttasklog::forge(array('project_task_id' => $task_id, 'comment' => $last_comment, 'task_started' => $task_started, 'task_completed' => $task_completed, 'is_billable' => $is_billable)); $task_log->save(); } } // commit to database \Fuel\Core\DB::commit_transaction(); \Fuel\Core\Session::set_flash('success', 'Time logs saved successfully.'); Fuel\Core\Response::redirect('user/timesheets/index/' . $timestamp); } catch (Exception $ex) { // rollback on error \Fuel\Core\DB::rollback_transaction(); \Fuel\Core\Session::set_flash('error', $ex->getMessage()); Fuel\Core\Response::redirect('user/timesheets/advanced/logtimes/' . $timestamp); } } $now = \Fuel\Core\Date::forge($timestamp)->format('mysql'); $day_starts = date('Y-m-d 00:00:00', strtotime($now)); $day_ends = date('Y-m-d 23:59:59', strtotime($now)); $today_logs = Model_Projecttasklog::find('all', array('related' => array('project_task', 'project_task.project', 'project_task.project_task_name', 'project_task.user'), 'where' => array(array('task_started', 'BETWEEN', array($day_starts, $day_ends)), array('project_task.user_id', $this->current_user->id)), 'order_by' => array(array('task_started', 'asc')))); // todo: use DB::query() instead $this->template->set_global('today_logs', $today_logs); $this->template->set_global('projects', Model_Project::find('all', array('order_by' => array(array('name', 'asc'))))); $this->template->set_global('timezones', Model_Timezone::find('all', array('order_by' => array(array('starts', 'asc'))))); $this->template->set_global('my_tasks', Model_Projecttask::find('all', array('where' => array(array('user_id', $this->current_user->id)), 'related' => array('project_task_name'), 'order_by' => array(array('project_task_description', 'asc'))))); $this->template->set_global('timestamp', $timestamp); $this->template->set_global('date', \Fuel\Core\Date::forge($timestamp)->format('mysql_date')); $this->template->title = 'Timesheets'; $this->template->content = View::forge('user/timesheets/advanced/_advanced_form'); }
<?php require 'init.php'; if (!Auth\Auth::check()) { die('error'); } $user = Auth\Auth::get(); var_dump(Auth\Auth::edit($user->id, $_GET['mail'], $_GET['name'], isset($_GET['pass']) ? $_GET['pass'] : $_GET['pass'], isset($_GET['pass2']) ? $_GET['pass2'] : $_GET['pass2'])); ?> <form> <label>mail</label> <input type="email" name="mail" value="<?php echo $user->mail; ?> "> <label>name</label> <input type="text" name="name" value="<?php echo $user->name; ?> "> <label>pass</label> <input type="password" name="pass"> <label>pass2</label> <input type="password" name="pass2"> <input type="submit"> </form>
<?php require 'init.php'; Auth\Auth::remove();
protected function check_user_is_admin() { return Auth\Auth::check() && Auth\Auth::get('group', -1) == 100; }
/** * Check permission * * @param string $area * @param string $controller * @param string $action * @return boolean true|false * * @access protected * @author Dao Anh Minh */ protected function check_permisstion($area, $controller, $action) { if (Auth\Auth::instance()->has_access("{$area}.{$controller}.[{$action}]")) { return true; } else { return false; } }
/** * Edit account * * @param integer $account_id account id * * @access public * @author Dao Anh Minh */ public function action_edit($account_id) { $view = View::forge('admin/account/edit'); $account = Model_Account::query()->where('id', $account_id)->get_one(); if (empty($account)) { Session::set_flash('error', 'Tài khoản không tồn tại'); Response::redirect('admin/account'); } $view->err = array(); $validate = Model_Account::validate($account_id); if (Input::method() == 'POST') { if ($validate->run()) { $account->set('password', Auth\Auth::instance()->hash_password(Input::post('confirm_pass')))->save(); Session::set_flash('success', 'Đổi mật khẩu thành công'); Response::redirect('admin/account'); } else { Session::set_flash('error', 'Có lỗi xảy ra'); $view->err = $validate->error_message(); } } $this->template->title = 'Đổi mật khẩu'; $this->template->content = $view; }
<?php require 'init.php'; Auth\Auth::install();
public function action_view($task_id = null) { // if POST then get task id if (Fuel\Core\Input::method() == 'POST') { $task_id = Fuel\Core\Input::post('project_task_id'); } if (!($task = Model_Projecttask::find($task_id))) { Fuel\Core\Session::set_flash('error', 'Cannot find task #' . $task_id); Fuel\Core\Response::redirect_back('admin/projects'); } if (Fuel\Core\Input::method() == 'POST') { $val = Model_Projecttaskcomment::validate('create'); if ($val->run()) { // save this comment $comment = Model_Projecttaskcomment::forge(array('user_id' => \Fuel\Core\Input::post('user_id'), 'project_task_id' => $task_id, 'comment' => \Fuel\Core\Input::post('comment'))); if ($comment->save()) { Fuel\Core\Session::set_flash('success', 'Saved comment # ' . $comment->id); } else { Fuel\Core\Session::set_flash('error', 'Cannot save comment.'); } } else { Fuel\Core\Session::set_flash('error', $val->error()); } } $view = Fuel\Core\View::forge('user/timesheets/view'); $view->set_global('task', $task); $view->set_global('user_id', Auth\Auth::get('id')); $view->set_global('show_comment_delete_link', false); $this->template->user_is_admin = $this->check_user_is_admin(); $this->template->title = 'Timesheets'; $this->template->content = $view; }
<?php use Crypto\Password; require 'init.php'; if (!empty($_GET['mail']) && !empty($_GET['pass'])) { var_dump(Auth\Auth::login($_GET['mail'], $_GET['pass'])); } ?> <form> <label>mail</label> <input type="email" name="mail"> <label>pass</label> <input type="password" name="pass"> <input type="submit"> </form>