Beispiel #1
0
 public function login()
 {
     if (!$this->feather->user->is_guest) {
         Url::redirect($this->feather->urlFor('home'), 'Already logged in');
     }
     if ($this->feather->request->isPost()) {
         $this->feather->hooks->fire('login_start');
         $form_username = Utils::trim($this->feather->request->post('req_username'));
         $form_password = Utils::trim($this->feather->request->post('req_password'));
         $save_pass = (bool) $this->feather->request->post('save_pass');
         $user = ModelAuth::get_user_from_name($form_username);
         if (!empty($user->password)) {
             $form_password_hash = Random::hash($form_password);
             // Will result in a SHA-1 hash
             if ($user->password == $form_password_hash) {
                 if ($user->group_id == $this->feather->forum_env['FEATHER_UNVERIFIED']) {
                     ModelAuth::update_group($user->id, $this->feather->forum_settings['o_default_user_group']);
                     if (!$this->feather->cache->isCached('users_info')) {
                         $this->feather->cache->store('users_info', Cache::get_users_info());
                     }
                 }
                 ModelAuth::delete_online_by_ip($this->feather->request->getIp());
                 // Reset tracked topics
                 Track::set_tracked_topics(null);
                 $expire = $save_pass ? $this->feather->now + 1209600 : $this->feather->now + $this->feather->forum_settings['o_timeout_visit'];
                 $expire = $this->feather->hooks->fire('expire_login', $expire);
                 ModelAuth::feather_setcookie($user->id, $form_password_hash, $expire);
                 Url::redirect($this->feather->urlFor('home'), __('Login redirect'));
             }
         }
         throw new Error(__('Wrong user/pass') . ' <a href="' . $this->feather->urlFor('resetPassword') . '">' . __('Forgotten pass') . '</a>', 403);
     } else {
         $this->feather->template->setPageInfo(array('active_page' => 'login', 'title' => array(Utils::escape($this->feather->forum_settings['o_board_title']), __('Login')), 'required_fields' => array('req_username' => __('Username'), 'req_password' => __('Password')), 'focus_element' => array('login', 'req_username')))->addTemplate('login/form.php')->display();
     }
 }
Beispiel #2
0
 public function login($req, $res, $args)
 {
     if (!User::get()->is_guest) {
         return Router::redirect(Router::pathFor('home'), 'Already logged in');
     }
     if (Request::isPost()) {
         Container::get('hooks')->fire('controller.login');
         $form_username = Input::post('req_username');
         $form_password = Input::post('req_password');
         $save_pass = (bool) Input::post('save_pass');
         $user = ModelAuth::get_user_from_name($form_username);
         if (!empty($user->password)) {
             $form_password_hash = Random::hash($form_password);
             // Will result in a SHA-1 hash
             if ($user->password == $form_password_hash) {
                 if ($user->group_id == ForumEnv::get('FEATHER_UNVERIFIED')) {
                     ModelAuth::update_group($user->id, ForumSettings::get('o_default_user_group'));
                     if (!Container::get('cache')->isCached('users_info')) {
                         Container::get('cache')->store('users_info', Cache::get_users_info());
                     }
                 }
                 ModelAuth::delete_online_by_ip(Utils::getIp());
                 // Reset tracked topics
                 Track::set_tracked_topics(null);
                 $expire = $save_pass ? Container::get('now') + 1209600 : Container::get('now') + ForumSettings::get('o_timeout_visit');
                 $expire = Container::get('hooks')->fire('controller.expire_login', $expire);
                 $jwt = ModelAuth::generate_jwt($user, $expire);
                 ModelAuth::feather_setcookie('Bearer ' . $jwt, $expire);
                 return Router::redirect(Router::pathFor('home'), __('Login redirect'));
             } else {
                 throw new Error(__('Wrong user/pass') . ' <a href="' . Router::pathFor('resetPassword') . '">' . __('Forgotten pass') . '</a>', 403);
             }
         }
     } else {
         View::setPageInfo(array('active_page' => 'login', 'title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('Login')), 'required_fields' => array('req_username' => __('Username'), 'req_password' => __('Password')), 'focus_element' => array('login', 'req_username')))->addTemplate('login/form.php')->display();
     }
 }