public function login() { $account = Input::get('account', ''); $pass = Input::get('pass', ''); try { $admin = SysUser::where('account', '=', $account)->where('is_del', '=', 0)->where('status', '=', 1)->first(); if (empty($admin)) { throw new Exception("没有找到可用的用户", 10003); } if (!Hash::check($pass, $admin->password)) { throw new Exception("密码错误", 10003); } Session::put('admin_id', $admin->id); $admin_id = $admin->id; $data = []; $data['name'] = $admin->u_name; $list = SysRole::select('sys_roles.*')->join('sys_user_roles', function ($q) use($admin_id) { $q->on('sys_roles.id', '=', 'sys_user_roles.r_id')->where('sys_user_roles.admin_id', '=', $admin_id); })->get(); $roles = []; foreach ($list as $key => $role) { $roles[] = $role->showInList(); } $data['roles'] = $roles; $re = Tools::reTrue('登录成功', $data); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '登录失败:' . $e->getMessage()); } return Response::json($re); }
public function editUser() { $now = new DateTime(); // chk exist $chk = SysUser::where('account', '=', $this->account)->where('id', '<>', $this->id)->first(); if (!empty($chk)) { throw new Exception("账号已经存在", 10001); } $this->password = Hash::make($this->password); $this->last_time = $now->format('Y-m-d H:i:s'); $this->save(); return $this->id; }
public static function getTreeByAdmin($admin_id = -1) { if ($admin_id == -1) { $admin = new SysUser(); $admin->account = 'root'; } else { $admin = SysUser::find($admin_id); if (empty($admin)) { throw new Exception("没有查找到admin数据", 10003); } } if ($admin->account == 'root') { $list = SysMenu::get(); } else { $list = SysMenu::select('sys_menus.*', 'sys_role_menus.r_id AS checked')->join('sys_role_menus', function ($q) { $q->on('sys_menus.id', '=', 'sys_role_menus.m_id'); })->join('sys_user_roles', function ($q) use($admin_id) { $q->on('sys_user_roles.r_id', '=', 'sys_role_menus.r_id')->where('sys_user_roles.admin_id', '=', $admin_id); })->groupBy('sys_menus.id')->get(); } $re = SysMenu::makeTree($list); return $re['tree']; }
}); Route::get('/banner/1', 'HomeController@banner1'); Route::get('/banner/2', 'HomeController@banner2'); Route::get('about', 'HomeController@about'); Route::get('/test', 'HomeController@test'); /* handling files */ Route::pattern('any', '(.*)'); Route::get('css/{any}', 'MiscFileController@getCSS'); Route::get('js/{any}', 'MiscFileController@getJS'); Route::get('images/{any}', 'MiscFileController@getImg'); Route::get('addons/{any}', 'MiscFileController@getAddOn'); /*********** FILTER ***********/ Route::filter('office', function () { $path = Request::path(); if ($path != 'office/login') { if (!SysUser::chkLogin()) { $re = Tools::reFalse(10003, '请先登录'); return Response::json($re); } } }); Route::when('office/*', 'office'); /*********** FILTER ***********/ /*********** IMG ***********/ Route::post('img', 'ImgController@postImg'); /*********** IMG ***********/ /*********** API ***********/ /* V1 */ Route::group(['domain' => Config::get('app.subdomain.api')], function () { /* APP START*/ Route::get('app/config', 'AppController@getConfig');
public static function getSysUserInfo() { $info = array(); $users = SysUser::model()->findAll(array('select' => 'id,name')); foreach ($users as $user) { $info[$user['id']] = $user['name']; } return $info; }
/** * @return \yii\db\ActiveQuery */ public function getUser() { return $this->hasOne(SysUser::className(), ['id' => 'user_ID']); }
/** * @param SysUser $user * @return Dfi_Auth_Adapter_AdapterInterface * @throws Exception */ private function getAdapter(SysUser $user) { $adapter = $user->getAuthAdapter(); $adapter->setPassword($this->password); return $adapter; }
public function listUserRole($id) { $per_page = Input::get('per_page', null); try { $admin = SysUser::find($id); if (empty($admin)) { throw new Exception("没有找到用户", 10001); } $query = SysRole::select('sys_roles.*')->join('sys_user_roles', function ($q) use($id) { $q->on('sys_roles.id', '=', 'sys_user_roles.r_id')->where('sys_user_roles.admin_id', '=', $id); }); $list = $query->paginate($per_page); $data['rows'] = []; foreach ($list as $key => $role) { $data['rows'][] = $role->showInList(); } $data['total'] = $list->getTotal(); $re = Tools::reTrue('获取角色成功', $data, $list); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '获取角色失败:' . $e->getMessage()); } return Response::json($re); }