Example #1
0
 function index()
 {
     //判断用户是否是已经登录状态
     $data = role::get_manager();
     if ($data['id'] > 0) {
         $data['success'] = 'true';
         $data['msg'] = 1;
     } else {
         $data['success'] = 'false';
         $data['msg'] = 1;
     }
     $username = $this->input->post('username');
     $password = $this->input->post('password');
     $secode = $this->input->post('secode');
     $remember = $this->input->post('remember');
     $data['success'] = 'false';
     //验证登录
     $manager = role::log_in($username, $password);
     if (isset($manager['username'])) {
         //判断普通账号的状态、权限
         if (!role::is_root($manager['username'])) {
             if ($manager['active'] != 1) {
                 ulog::login($manager['id'], 1);
                 $data['msg'] = Kohana::lang('o_global.account_was_locked');
             }
             $actions = role::manager_actions($manager['id'], TRUE);
             if (count($actions) < 1) {
                 ulog::login($manager['id'], 2);
                 $data['msg'] = Kohana::lang('o_global.account_permission_enough');
             }
         }
         //是否记录用户名
         if ($remember == 1) {
             cookie::set('opococ_username', $username);
         } else {
             cookie::delete('opococ_username');
         }
         //清除记录登录错误记录
         //Session::instance()->delete('login_error_count');
         //记入SESSION
         role::set_manager_session($manager);
         //记录日志
         ulog::login($manager['id']);
         $data['success'] = 'true';
         $data['msg'] = 1;
         /*if(empty($request_url))
         		{
         			remind::set(Kohana::lang('o_global.login_success'), '/index', 'success');
         		}
                    else
                    {
         			$request_url = url::base() . urldecode($request_url);
         			remind::set(Kohana::lang('o_global.login_success'), $request_url, 'success');
         		}*/
     }
     die(json_encode($data));
 }
Example #2
0
 /**
  * change password
  */
 public function change_password()
 {
     if ($_POST) {
         $password = $this->input->post('password');
         $password1 = $this->input->post('password1');
         $password2 = $this->input->post('password2');
         $data = role::get_manager();
         //判断SESSION中的数据是否存在
         if ($data['id'] > 0) {
             if (strlen($password1) < 6) {
                 remind::set(Kohana::lang('o_manage.password_length_error'), 'manage/manager/change_password');
             }
             if ($password1 != $password2) {
                 remind::set(Kohana::lang('o_manage.two_pwd_not_valid'), 'manage/manager/change_password');
             } else {
                 $manager = Mymanager::instance($data['id'])->get();
                 if ($manager['password'] == md5($password)) {
                     $update_data = array();
                     $update_data['password'] = md5($password1);
                     $manager = Mymanager::instance($data['id'])->update($update_data);
                     $is_remember = isset($manager['is_remember']) ? $manager['is_remember'] : 0;
                     //验证是否记住状态
                     $manager['is_remember'] = $is_remember;
                     role::set_manager_session($manager);
                     //记录用户修改密码日志
                     ulog::change_password($this->manager_id, 1);
                     remind::set(Kohana::lang('o_global.update_success'), 'manage/manager/change_password', 'success');
                 } else {
                     //记录用户修改密码日志
                     ulog::change_password($this->manager_id);
                     remind::set(Kohana::lang('o_manage.pwd_is_incorrect'), 'manage/manager/change_password');
                 }
             }
         } else {
             remind::set(Kohana::lang('o_global.login_first'), 'login');
         }
     }
     $this->template->content = new View("manage/manager_change_password");
 }
Example #3
0
 /**
  * log in
  */
 function index()
 {
     $this->logout(FALSE);
     /* 原请求页面 */
     $request_url = $this->input->get('request_url');
     //用户名和密码输入错误三次后就需要输入验证码
     $login_error_count = Session::instance()->get('login_error_count');
     if (!$login_error_count) {
         $login_error_count = 1;
         Session::instance()->set('login_error_count', $login_error_count);
     }
     //判断用户是否是已经登录状态
     $data = role::get_manager();
     //D($data);
     if ($data['id'] > 0) {
         remind::set(Kohana::lang('o_global.current_status_login'), '/', 'success');
     }
     //验证码KEY
     secoder::$seKey = 'opococ.secoder';
     //错误信息
     $message = remind::get_message();
     if (empty($message)) {
         $error_display = "none";
         $error = "";
     } else {
         $error_display = "";
         $error = $message;
     }
     //登录
     if ($_POST) {
         $username = $this->input->post('username');
         $password = $this->input->post('password');
         $secode = $this->input->post('secode');
         $remember = $this->input->post('remember');
         //验证验证码
         if ($login_error_count > 3 && !secoder::check($secode)) {
             remind::set(Kohana::lang('o_global.code_input_error'), 'login');
         }
         //验证登录
         $manager = role::log_in($username, $password);
         if (isset($manager['username'])) {
             //判断普通账号的状态、权限
             if (!role::is_root($manager['username'])) {
                 if ($manager['active'] != 1) {
                     ulog::login($manager['id'], 1);
                     remind::set(Kohana::lang('o_global.account_was_locked'), 'login');
                 }
                 $actions = role::manager_actions($manager['id'], TRUE);
                 if (count($actions) < 1) {
                     ulog::login($manager['id'], 2);
                     remind::set(Kohana::lang('o_global.account_permission_enough'), 'login');
                 }
             }
             /* 是否记录用户名 */
             if ($remember == 1) {
                 cookie::set('opococ_username', $username);
             } else {
                 cookie::delete('opococ_username');
             }
             //清除记录登录错误记录
             Session::instance()->delete('login_error_count');
             //记入SESSION
             role::set_manager_session($manager);
             //记录日志
             ulog::login($manager['id']);
             if (empty($request_url)) {
                 remind::set(Kohana::lang('o_global.login_success'), '/index', 'success');
             } else {
                 $request_url = url::base() . urldecode($request_url);
                 remind::set(Kohana::lang('o_global.login_success'), $request_url, 'success');
             }
         } else {
             ulog::login();
             $login_error_count++;
             Session::instance()->set('login_error_count', $login_error_count);
             remind::set(Kohana::lang('o_global.user_and_password_error'), 'login');
         }
     }
     /* 浏览器记录的用户名 */
     $username = cookie::get('opococ_username');
     $this->template = new View('login');
     $this->template->login_error_count = $login_error_count;
     $this->template->error = $error;
     $this->template->error_display = $error_display;
     $this->template->username = $username;
     $this->template->render(TRUE);
 }