Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 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;
 }