Exemple #1
0
 public function action_index()
 {
     //ログイン用のオブジェクト生成
     $auth = Auth::instance();
     $auth->logout();
     Response::redirect('/');
 }
Exemple #2
0
 public function sidebar($options = array())
 {
     $identifier = array('nav' => array('id' => 'sidebar', 'class' => 'sidebar nav-collapse collapse'), 'ul' => array('id' => 'side-nav', 'class' => 'side-nav'), 'li' => array('id' => '', 'class' => '', 'role' => ''));
     if (isset($options['nav'])) {
         $identifier['nav'] = $options['nav'];
     }
     if (isset($options['ul'])) {
         $identifier['ul'] = $options['ul'];
     }
     if (isset($options['li'])) {
         $identifier['li'] = $options['li'];
     }
     $ul = ' <nav id="' . $identifier['nav']['id'] . '" class="' . $identifier['nav']['class'] . '">
 				<ul id="' . $identifier['ul']['id'] . '" class="' . $identifier['ul']['class'] . '">';
     foreach ($options['data'] as $k => $v) {
         if (isset($v['filter'])) {
             if ($v['filter'] == '*') {
                 $ul .= '<li><a href="' . Uri::base() . $v['link'] . '">' . $v['name'] . '</a></li>';
             } elseif (in_array(\Auth\Auth::instance()->get('group')->id, $v['filter'])) {
                 $ul .= '<li><a href="' . Uri::base() . $v['link'] . '">' . $v['name'] . '</a></li>';
             }
         }
     }
     $ul .= '</ul></nav>';
     return $ul;
 }
Exemple #3
0
 public function before()
 {
     parent::before();
     if (!Auth::check()) {
         Response::redirect('/');
     }
 }
Exemple #4
0
 public function post_login()
 {
     $data = (object) Input::post();
     if (Auth::login($data->username, $data->password)) {
         return \Response::redirect('admin/home');
     }
     return \Response::redirect('admin/login');
 }
Exemple #5
0
 public static function admin_login($username_or_email, $password)
 {
     if (Auth::instance()->login($username_or_email, $password)) {
         list(list(, $group_id)) = Auth::get_groups();
         if ($group_id == 100) {
             return true;
         }
     }
     return false;
 }
Exemple #6
0
 /**
  * Check validation and hashing password
  * @param array $data
  * @return boolean|array errors
  */
 protected function _modify(array $data = null)
 {
     if ($this->is_valid()) {
         if (isset($data['password'])) {
             $this->password = Auth::hash($data['password']);
         }
         return $this->save();
     }
     return $this->errors->full_messages();
 }
Exemple #7
0
 /**
  * Get current user
  * @param string $default // default user
  * @return mixed // instance of model User, default username, or false, if user isn't in database
  */
 public function getUser($default = null)
 {
     if ($this->_user instanceof User) {
         return $this->_user;
     }
     $username = parent::getUser();
     if (!$username) {
         return $default;
     }
     return $this->_getUser($username);
 }
Exemple #8
0
 public function action_logout()
 {
     // remove the remember-me cookie, we logged-out on purpose
     Auth::dont_remember_me();
     // logout
     Auth::logout();
     // inform the user the logout was successful
     //\Messages::success(__('login.logged-out'));
     // and go back to where you came from (or the application
     // homepage if no previous page can be determined)
     Response::redirect('');
 }
 public function before()
 {
     parent::before();
     // Without this line, templating won't work!
     $this->template->head = View::forge('_partial/head');
     $this->template->header = View::forge('_partial/header');
     $this->template->footer = View::forge('_partial/footer');
     if (!Auth::check()) {
         Response::redirect('/auth/login');
     }
     // do stuff
 }
Exemple #10
0
 public function action_index()
 {
     if (\Auth\Auth::member(6)) {
         $data['usuarios'] = \Auth\Model\Auth_Group::find(5)->users;
         $data['texts'] = Model_Text::find('all', ['related' => ['user']]);
     } else {
         $data['texts'] = Model_Text::find('all', ['related' => ['user'], 'where' => ['user_id' => $this->get_current_user_id()]]);
         $data['usuarios'] = \Auth\Model\Auth_Group::find(5)->users;
     }
     $this->template->title = "Texts";
     $this->template->content = View::forge('admin/text/index', $data);
 }
Exemple #11
0
 public function postUserEditPassword(UserEditPasswordRequest $request)
 {
     if (!Auth::checkCurrentPassword($request->old_pass)) {
         return json_encode(['error' => 1, 'message' => 'Mật khẩu không đúng !']);
     }
     if (!($request->new_pass === $request->re_new_pass && strlen($request->new_pass) >= 6)) {
         return json_encode(['error' => 1, 'message' => 'Mật khẩu nhập lại không trùng khớp hoặc quá ngắn']);
     }
     $data = ['password' => bcrypt($request->new_pass)];
     $model = new User();
     if ($model->UserUpdate($request->id, $data)) {
         return json_encode(['error' => '0']);
     } else {
         return json_encode(['error' => '1', 'message' => 'Lỗi! Thêm vào database không thành công.']);
     }
 }
Exemple #12
0
 public function post_update_username()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('username', Lang::get('label.username'), 'required|valid_username|min_length[6]|max_length[50]|unique_username');
     if ($val->run()) {
         $props = array('username' => $val->validated('username'));
         if (Model_Base_User::update($this->user_id, $props)) {
             Auth::force_login($this->user_id);
             $this->data['success'] = Lang::get($this->controller . '.' . $this->action . '.success');
         } else {
             $this->data['error'] = Lang::get($this->controller . '.' . $this->action . '.error');
         }
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }
Exemple #13
0
 public function init()
 {
     View::set_global('controller', $this->controller);
     View::set_global('action', $this->action);
     if (Model_Base_User::is_login()) {
         View::set_global('head', View::forge($this->layout . '/global/head'));
         View::set_global('header', View::forge($this->layout . '/global/header'));
         View::set_global('sidebar', View::forge($this->layout . '/global/sidebar'));
         View::set_global('script', View::forge($this->layout . '/global/script'));
         list(, $auth_id) = Auth::get_user_id();
         $this->user_id = $auth_id;
         $this->user_info = Model_Base_User::get_user_info($auth_id);
         $this->user_fb = Model_Base_User::get_user_fb($auth_id);
         View::set_global('user', $this->user_info);
         View::set_global('user_fb', $this->user_fb);
         View::set_global('base_url', Config::get('base_url'));
     }
 }
Exemple #14
0
 public function before()
 {
     $uri_string = explode('/', Uri::string());
     if (count($uri_string) > 1 and $uri_string[0] == 'user' and $uri_string[1] == 'login') {
         return;
     } else {
         $user_id = \Auth\Auth::instance()->get_user_id()[1];
         /*($user_id);
           exit();*/
         if ($user_id) {
             $user = Model_User::find($user_id);
             if (!$user || $user->group != 100) {
                 Response::redirect('/user/login');
             }
         } else {
             Response::redirect('/user/login');
         }
     }
 }
Exemple #15
0
 /**
  * ユーザ登録
  * @return \Fuel\Core\View
  */
 public function post_create()
 {
     if ($_POST) {
         //POSTデータを受け取る
         $username = Input::post('username');
         $password = Input::post('password');
         $email = Input::post('mail');
         $gender = Input::post('gender');
         $age = Input::post('age');
         $profile['gender'] = $gender;
         $profile['age'] = $age;
         //ユーザー登録
         $id = Auth::create_user($username, $password, $email);
         if (!empty($id)) {
             $result = Model_Users::find_by_pk($id)->set(array('age' => $age, 'gender' => $gender))->save();
             Auth::login($username, $password);
         }
     }
     Response::redirect('top');
 }
Exemple #16
0
 public function post_add()
 {
     $requestData = Input::json();
     $auth = Auth::instance();
     $userData = $auth->get_user_array();
     $post = $requestData['data'];
     $post['Author'] = $userData['screen_name'];
     //Session::get('user.name');
     $date = new \DateTime();
     $post['DateCreate'] = date_format($date, 'Y-m-d H:i:s');
     $post['Tag'] = '';
     $post['Views'] = 0;
     $storyManager = new StoryManager();
     if ($storyManager->createNewStory($post)) {
         Session::set_flash('success', 'Success create new story!');
     } else {
         Session::set_flash('error', 'Server error! Please try again later or contact administrator!');
     }
     Response::redirect('admin/modules/news/add');
 }
Exemple #17
0
 public function action_index()
 {
     //すでにログイン済であればログイン後のページへリダイレクト
     Auth::check() and Response::redirect('top');
     //エラーメッセージ用変数初期化
     $error = null;
     //ログイン用のオブジェクト生成
     $auth = Auth::instance();
     //ログインボタンが押されたら、ユーザ名、パスワードをチェックする
     if (Input::post()) {
         if ($auth->login(Input::post('username'), Input::post('password'))) {
             // ログイン成功時、ログイン後のページへリダイレクト
             Response::redirect('top');
         } else {
             // ログイン失敗時、エラーメッセージ作成
             $error = 'ユーザ名かパスワードに誤りがあります';
         }
     }
     //ビューテンプレートを呼び出し
     $this->template->content = View::forge('login/index');
     //エラーメッセージをビューにセット
     $this->template->content->set('error', $error);
     $this->template->title = "login";
 }
Exemple #18
0
 /**
  * Verify Acl access
  *
  * @param	mixed	condition to validate
  * @param	string	acl driver id or null to check all
  * @param	array	user identifier to check in form array(driver_id, user_id)
  * @return	bool
  */
 public function has_access($condition, $driver = null, $entity = null)
 {
     $entity = $entity ?: $this->get_user_id();
     if ($driver === null) {
         foreach (\Auth::acl(true) as $acl) {
             if ($acl->has_access($condition, $entity)) {
                 return true;
             }
         }
         return false;
     }
     return \Auth::acl($driver)->has_access($condition, $entity);
 }
Exemple #19
0
 /**
  * @return array
  *
  */
 private function _user_info()
 {
     $group = \Auth\Auth::instance()->get_groups();
     $data = array('id' => \Auth\Auth::instance()->get('id'), 'username' => \Auth\Auth::instance()->get_screen_name(), 'email' => \Auth\Auth::instance()->get_email());
     return $data;
 }
Exemple #20
0
 public function action_index()
 {
     Auth::create_user('longnd', '123456', '*****@*****.**', 1, array('fullname' => 'Nguyen Duy Long'));
     exit;
 }
Exemple #21
0
 /**
  * Force login user
  *
  * @param   string
  * @return  bool
  */
 public function force_login($member_id = '')
 {
     // bail out if we don't have a user
     if (empty($member_id)) {
         return false;
     }
     // get the user we need to login
     if (!$member_id instanceof \Model_Member) {
         $this->member = self::get_member4id($member_id);
     } else {
         $this->member = $member_id;
     }
     // did we find it
     if ($this->member and !$this->member->is_new()) {
         // store the logged-in user and it's hash in the session
         //\Session::set('username', $this->user->username);
         \Session::set('member_id', $this->member->id);
         \Session::set('login_hash', $this->create_login_hash());
         // reset login failed count.
         if (\Config::get('uzuraauth.accountLock.isEnabled')) {
             \Session::delete('login_failed');
         }
         // and rotate the session id, we've elevated rights
         \Session::instance()->rotate();
         // register so Auth::logout() can find us
         \Auth\Auth::_register_verified($this);
         return true;
     }
     // force a logout
     $this->logout();
     // and signal a failed login
     return false;
 }
Exemple #22
0
?>
        </ol>
    </div>

    <div class="col-md-3">
        <h3>System Users</h3>

        <p><?php 
echo \Fuel\Core\Html::anchor('admin/users/create', 'New System User', array('class' => 'btn btn-success btn-xs'));
?>
</p>

        <ol>
            <?php 
foreach (\Auth\Model\Auth_User::find('all', array('where' => array(array('id', '>', 0)))) as $user) {
    ?>
                <li>
                    <?php 
    echo \Fuel\Core\Html::anchor("admin/users/edit/{$user->id}", $user->fullname);
    ?>
                    <?php 
    echo \Auth\Auth::get('id') == $user->id ? '<span class="glyphicon glyphicon-user"></span>' : '';
    ?>
                </li>
            <?php 
}
?>
        </ol>
    </div>
</div>
Exemple #23
0
 public function action_signout()
 {
     Auth::dont_remember_me();
     Auth::logout();
     Response::redirect('/admin/signin');
 }
Exemple #24
0
 function getNavTop()
 {
     if (Auth::check()) {
         return ['view' => 'nav_top_logged.php', 'name' => Auth::user()->name];
     }
     return ['view' => 'nav_top_not_login.php'];
 }
Exemple #25
0
 public function action_file($folder = null, $size = null, $crop = 'no')
 {
     try {
         if (is_null($folder)) {
             throw new Exception('Folder name is not given!');
         }
         if (is_null($size)) {
             throw new Exception('Image file name is not given!');
         }
         if (!strpos($size, 'x')) {
             throw new Exception('Image size is not given!');
         }
         if (!\Fuel\Core\Input::get('image')) {
             throw new Exception('Image is not given!');
         }
         $file = \Fuel\Core\Input::get('image');
         /** @var  $upload_path */
         $upload_path = '/var/www/html/' . $this->_dir;
         /** @var  $file_path */
         $file_path = $folder . '/' . $file;
         /** @var  $real_path */
         $real_path = $upload_path . '/' . $file_path;
         /** @var  $new_name */
         $new_name = $size . '_' . $file;
         /** @var  $resize_path : Path for resize only */
         $resize_path = $upload_path . '/' . $folder . '/resize/';
         /** @var  $resize_file */
         $resize_file = $upload_path . '/' . $folder . '/resize/' . $new_name;
         /** @var  $crop_path : Path for crop only */
         $crop_path = $upload_path . '/' . $folder . '/crop/';
         /** @var  $crop_file */
         $crop_file = $upload_path . '/' . $folder . '/crop/' . $new_name;
         /** @var  $image */
         $image = \Fuel\Core\Image::forge(array('driver' => 'gd', 'bgcolor' => null, 'quality' => 100));
         /** @var  $where_are_file */
         $where_are_file = '';
         /** @var  $where_are_path */
         $where_are_path = '';
         if ($crop == 'no') {
             $where_are_file = $resize_file;
             $where_are_path = $resize_path;
         } else {
             $where_are_file = $crop_file;
             $where_are_path = $crop_path;
         }
         if (!file_exists($where_are_file)) {
             /**
              *  Check if not dir then make it.
              */
             if (!is_dir($where_are_path)) {
                 if (!mkdir($where_are_path, 0777)) {
                     throw new Exception('Permission denied!');
                 }
             }
             /** @var  $size */
             $size = explode('x', $size);
             if ($crop == 'crop') {
                 /**
                  *  Chaining to crop_resize() function
                  */
                 $image->load($real_path)->crop_resize($size[0], $size[1])->save($where_are_file);
             } else {
                 /**
                  *  Chaining to resize() function
                  */
                 $image->load($real_path)->resize($size[0], $size[1], true, false)->save($where_are_file);
             }
             /**
              *  Load file and output image.
              */
             $image->load($where_are_file)->output();
         } else {
             /**
              *  If file exist force output to show image.
              */
             if (\Fuel\Core\Input::get('action') == 'delete') {
                 if (\Auth\Auth::instance()->get('group') == 100) {
                     $model = Model_Filemanager::find_by_value($file);
                     if ($model) {
                         $model->deleted_at = time();
                         $model->value = null;
                         if ($model->save()) {
                             \Fuel\Core\File::delete($where_are_file);
                             \Fuel\Core\File::delete($real_path);
                             \Fuel\Core\Response::redirect('filemanager/folder/' . $folder);
                         } else {
                             throw new Exception('Cannot delete in database!');
                         }
                     } else {
                         throw new Exception('Image not found!');
                     }
                 } else {
                     throw new Exception('You are not an Administrator!');
                 }
             } else {
                 $image->load($where_are_file)->output();
             }
         }
     } catch (Exception $e) {
         /** @var  $error */
         $error = '<ul>';
         $error .= '<li>' . $e->getLine() . '</li>';
         $error .= '<li>' . $e->getFile() . '</li>';
         $error .= '<li>' . $e->getMessage() . '</li>';
         $error .= '</ul>';
         return $error;
     }
     exit;
 }
Exemple #26
0
 /**
  * 登录后的session
  */
 public function auth()
 {
     $auth = Auth::getInstance();
     if ($auth->hasIdentity()) {
         return $auth->getIdentity();
     } else {
         return false;
     }
 }
 public function action_forgot()
 {
     \Auth\Auth::check() and \Fuel\Core\Response::redirect("user");
     $val = \Fuel\Core\Validation::forge('forgot');
     if (\Fuel\Core\Input::method() == "POST") {
         if ($val->run()) {
             try {
                 $username = \Fuel\Core\Input::post('email');
                 $user = Model_User::find('first', array('where' => array(array('username', 'LIKE', "{$username}"), 'or' => array(array('email', 'LIKE', "{$username}")))));
                 if (!$user) {
                     throw new \Auth\SimpleUserUpdateException("Invalid username or email");
                 }
                 $old_password = \Auth\Auth::reset_password($user->username);
                 $new_password = \Fuel\Core\Str::random();
                 \Auth\Auth::update_user(array('password' => $new_password, 'old_password' => $old_password), $user->username);
                 // Create an instance
                 $email = \Email\Email::forge();
                 // Set the from address
                 $email->from('*****@*****.**', 'ITNT Time Sheets');
                 // Set the to address
                 $email->to($user->email, $user->first_name . " " . $user->last_name);
                 // Set a subject
                 $email->subject('ITNT Time Sheets Password Reset');
                 // Set multiple to addresses
                 //                            $email->bcc(array(
                 //                                '*****@*****.**' => 'Gavin Murambadoro',
                 //                            ));
                 // Set a html body message
                 $email->html_body(\View::forge('includes/email/forgot', array('user' => $user, 'password' => $new_password)));
                 if ($email->send()) {
                     $this->template->set_global('login_success', "Your password has been reset and an email was sent to {$user->email}");
                 } else {
                     $this->template->set_global('login_error', "Your password was reset but we could not send you an email. Your new password is {$new_password}. Make sure that you copy this before leaving this page.");
                 }
             } catch (\SimpleUserUpdateException $exception) {
                 $this->template->set_global('login_error', "User Error: {$exception->getMessage()}");
             } catch (\EmailValidationFailedException $exception) {
                 $this->template->set_global('login_error', "Mail Validation Error: {$exception->getMessage()}");
             } catch (\EmailSendingFailedException $exception) {
                 $this->template->set_global('login_error', "Mail Error: {$exception->getMessage()}");
             } catch (Exception $exception) {
                 $this->template->set_global('login_error', "General Error: {$exception->getMessage()}");
             }
         } else {
             $this->template->set_global('login_error', $val->error());
         }
     }
     $this->template->set_global('val', $val, false);
     $this->template->title = 'Forgot Password';
     $this->template->content = View::forge('user/forgot');
 }
Exemple #28
0
 /**
  * @param array $users
  * @return void
  */
 public function __construct(array $users = null)
 {
     parent::__construct();
     $this->_users = $users;
 }