Beispiel #1
0
 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.";
 }
Beispiel #2
0
 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');
     }
 }
Beispiel #3
0
 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');
 }
 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');
 }
Beispiel #5
0
 /**
  * Возвращаем авторизацию
  * @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;
 }
Beispiel #6
0
 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');
 }
Beispiel #7
0
 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]);
 }
Beispiel #8
0
 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);
 }
Beispiel #9
0
 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);
 }
 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;
     }
 }
Beispiel #11
0
 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;
 }
Beispiel #12
0
 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);
 }
Beispiel #13
0
 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;
     }
 }
Beispiel #14
0
 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;
 }
Beispiel #15
0
 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;
 }
 /**
  * 特定の出店予約にメールを送信する
  *
  * @access public
  * @param
  * @return void
  * @author ida
  */
 public function action_sendmail()
 {
     $this->template = '';
     $entry_id = \Input::get('entry_id');
     $mails = \Input::get('mails');
     $status = 400;
     if (!empty($entry_id) && !empty($mails)) {
         try {
             $entry = \Model_Entry::find($entry_id);
             $user = \Model_User::find($entry->user_id);
             foreach ($mails as $mail) {
                 switch ($mail) {
                     case 'reservation':
                         $entry->sendmail($user, 'reservation');
                         break;
                     default:
                         break;
                 }
             }
             $status = 200;
         } catch (\Exception $e) {
             $status = 400;
         }
     }
     return $this->responseJson(array('status' => $status));
 }
Beispiel #17
0
 public function action_list()
 {
     $page = $this->get_query('page', 1);
     $user_list = Model_User::find(array(), $page);
     $this->template_data['total'] = Model_User::count();
     $this->template_data['user_list'] = $user_list;
     $this->template_data['title'] = __('admin.user.list.user_list');
 }
Beispiel #18
0
 public static function get_user_info($id)
 {
     $user = Model_User::find($id);
     if ($user) {
         $user_config = Model_Service_Util::get_app_config('user');
         return array('username' => $user->username, 'email' => $user->email, 'group' => $user->group, 'group_display' => $user_config['group'][$user->group], 'full_name' => $user->full_name, 'gender' => $user->gender, 'gender_display' => $user_config['gender'][$user->gender], 'birthday' => $user->birthday, 'address' => $user->address, 'telephone' => $user->telephone, 'user_photo' => $user->user_photo, 'user_photo_display' => empty($user->user_photo) ? _PATH_NO_ICON_ : _PATH_ICON_ . $user->user_photo);
     }
     return false;
 }
Beispiel #19
0
 public function action_editores($empresa)
 {
     $editores = Model_User::find('all', array('where' => array(array('group', '=', 50), array('padre', '=', 0), array('empresa', 'like', $empresa))));
     $select_editores = array();
     foreach ($editores as $e) {
         $select_editores[$e->id] = $e->username;
     }
     $this->response(array('select_editores' => $select_editores, 'empty' => null));
 }
Beispiel #20
0
 public function action_index()
 {
     $is_chenged = false;
     if ($this->user->bank == null) {
         $this->user->bank = Model_Bank::forge();
         $this->user->bank->user_id = $this->user->id;
         $this->user->bank->save();
     }
     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.";
             }
         }
         $config = ["path" => DOCROOT . "assets/img/pictures/", 'randomize' => true, 'auto_rename' => true, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png')];
         Upload::process($config);
         if (Upload::is_valid()) {
             Upload::save();
             $saved_result = Upload::get_files();
             $file_name = $saved_result[0]['saved_as'];
             $image = Image::load($config["path"] . $file_name);
             $image->crop_resize(200, 200)->save($config["path"] . "m_" . $file_name);
             $image->crop_resize(86, 86)->save($config["path"] . "s_" . $file_name);
             $this->user->img_path = $file_name;
         } else {
             $error = Upload::get_errors();
         }
         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->pr = Input::post("pr", "");
             $this->user->educational_background = Input::post("educational_background", "");
             $this->user->enchantJS = Input::post("enchantJS", 0);
             $this->user->trial = Input::post("trial", 0);
             $this->user->save();
             $this->user->bank->name = Input::post("bank_name", "");
             $this->user->bank->branch = Input::post("bank_branch", "");
             $this->user->bank->account = Input::post("bank_account", "");
             $this->user->bank->number = Input::post("bank_number", "");
             $this->user->bank->etc = Input::post("bank_etc", "");
             $this->user->bank->type = Input::post("bank_type", 0);
             $this->user->bank->save();
             $is_chenged = true;
         }
     }
     $data["user"] = $this->user;
     $data["is_chenged"] = $is_chenged;
     $view = View::forge("teachers/profile", $data);
     $this->template->content = $view;
 }
Beispiel #21
0
 public function action_delete($id = null)
 {
     if ($user = Model_User::find($id)) {
         $user->delete();
         Session::set_flash('success', e('Deleted user #' . $id));
     } else {
         Session::set_flash('error', e('Could not delete user #' . $id));
     }
     Response::redirect('admin/user');
 }
Beispiel #22
0
 public function action_index()
 {
     $data["subnav"] = array('login' => 'active');
     $this->template->title = 'Users';
     $this->template->byline = 'List of all users';
     //$this->template->content = View::forge('admin/users/index', $data);
     $data['users'] = Model_User::find('all');
     //var_dump($data['users']);
     $this->template->content = View::forge('admin/users/index', $data);
 }
Beispiel #23
0
 /**
  * Store a new user. This creates a new AuthVimeo record, but also
  * a new user record.
  * @param String $vimeoId Vimeo user id
  * @param Zend_Oauth_Token_Access $accessToken oAuth access token
  * @param Array $props Properties received from Vimeo
  * @return Garp_Db_Table_Row The new user data
  */
 public function createNew($vimeoId, Zend_Oauth_Token_Access $accessToken, array $props)
 {
     // first save the new user
     $userModel = new Model_User();
     $userId = $userModel->insert($props);
     $userData = $userModel->find($userId)->current();
     $this->insert(array('vimeo_id' => $vimeoId, 'access_token' => $accessToken->getToken(), 'access_token_secret' => $accessToken->getTokenSecret(), 'user_id' => $userId));
     $this->getObserver('Authenticatable')->updateLoginStats($userId);
     return $userData;
 }
Beispiel #24
0
 /**
  * Store a new user. This creates a new auth_openid record, but also
  * a new users record.
  * @param String $openid
  * @param Array $props Properties fetched thru Sreg
  * @return Garp_Db_Table_Row The new user data
  */
 public function createNew($openid, array $props)
 {
     // first save the new user
     $userModel = new Model_User();
     $userId = $userModel->insert($props);
     $userData = $userModel->find($userId)->current();
     $this->insert(array('openid' => $openid, 'user_id' => $userId));
     $this->getObserver('Authenticatable')->updateLoginStats($userId);
     return $userData;
 }
Beispiel #25
0
 public static function userdata()
 {
     //data配列の初期化
     $data = array();
     //Authのインスタンス化
     $auth = Auth::instance();
     $email = $auth->get_email();
     $data = Model_User::find('first', array('where' => array('email' => $email)));
     return $data;
 }
Beispiel #26
0
 public function action_detail($id = 0)
 {
     $student = Model_User::find($id);
     if ($student == null) {
         Response::redirect("_404_");
     }
     $data["user"] = $student;
     $view = View::forge("teachers/students/detail", $data);
     $this->template->content = $view;
 }
Beispiel #27
0
 /**
  * Check if the user is logged in and fetches their information
  * if not then assign the guest info and pass it to the views.
  */
 private function _get_user()
 {
     if (Cookie::get('_sess') and $user = Model_User::find('first', array('where' => array('login_hash' => Crypt::decode(Cookie::get('_sess')))))) {
         $this->current_user = $user;
         $this->current_user->_set_logged_in(true);
     } else {
         $this->current_user = Model_User::forge(array('username' => 'Guest', 'group_id' => 5));
         $this->current_user->_set_logged_in(false);
     }
     $this->template->set_global('current_user', $this->current_user);
 }
Beispiel #28
0
 /**
  * Store a new user. This creates a new auth_facebook record, but also
  * a new user record.
  * @param Array $authData Data for the new Auth record
  * @param Array $userData Data for the new User record
  * @return Garp_Db_Table_Row The new user data
  */
 public function createNew(array $authData, array $userData)
 {
     // first save the new user
     $userModel = new Model_User();
     $userId = $userModel->insert($userData);
     $userData = $userModel->find($userId)->current();
     $authData['user_id'] = $userId;
     $this->insert($authData);
     $this->getObserver('Authenticatable')->updateLoginStats($userId);
     return $userData;
 }
Beispiel #29
0
 /**
  * Store a new user. This creates a new auth_linkedin record, but also
  * a new user record.
  * @param String $linkedinId LinkedIn user id
  * @param Array $props Properties received from LinkedIn
  * @return Garp_Db_Table_Row The new user data
  */
 public function createNew($linkedinId, array $props)
 {
     //print($linkedinId . '<pre>' . print_r($props, true));
     // first save the new user
     $userModel = new Model_User();
     $userId = $userModel->insert($props);
     $userData = $userModel->find($userId)->current();
     $this->insert(array('linkedin_uid' => $linkedinId, 'user_id' => $userId));
     $this->getObserver('Authenticatable')->updateLoginStats($userId);
     return $userData;
 }
Beispiel #30
0
 public function action_delete($id = null)
 {
     is_null($id) and Response::redirect('users');
     if ($user = Model_User::find($id)) {
         $user->delete();
         Session::set_flash('success', 'Deleted user #' . $id);
     } else {
         Session::set_flash('error', 'Could not delete user #' . $id);
     }
     Response::redirect('users');
 }