Prepare user

@param int $id
@return mixed
@throws Exception
436164
public function prepareUser($id)
    {
        $userClass = config('auth.providers.users.model');

        if (! class_exists($userClass)) {
            throw new Exception("User class {$userClass} not found.");
        }

        if(! $user = $userClass::whereId($id)->first()) {
            throw new Exception("User by ID {$id} not found.");
        }

        return $user;
    }
972663
public function findUserById($id)
    {
        if ($id instanceof UserInterface) {
            return $id;
        }

        $result =   $this->userProvider->findById($id);
        if ($result) {
            return $result;
        }

        $exceptionMessage   =   "A user with the ID '%(id)s' cannot be found.";

        throw new UserNotFound(isprintf($exceptionMessage, compact('id')));
    }
119126
public function onceUsingId($id)
    {
        $user = $this->provider->retrieveById($id);

        $this->setUser($user);

        return ($user instanceof UserInterface);
    }
229394
public function executePrepared($prepare)
    {
        $execute = $prepare->execute();

        if (!$execute) {
            $errorInfo = $prepare->errorInfo();

            throw new Exception(
                'Cannot execute prepared statement: ' . end($errorInfo) . ' : ' . $prepare->queryString
            );
        }

        return $execute;
    }
978651
protected function preparePath($id) {
		if (! is_scalar($id)) {
			$id = json_encode($id);
		}
		
		$filename = $this->prefix . '_' . md5($id);
		
		return $this->getCachePath() . DIRECTORY_SEPARATOR . $filename;
	}
839038
public static function getById($uid)
    {    
		if ($uid == USER_ANONYMOUS) return new User\Anonymous();
        $fields = self::getDbConnection()->fetchAssoc( 'SELECT * FROM '.User::TABLE.' WHERE id = ?', array( $uid ) );
        if (!$fields) throw new \Exception('User:'.$uid.' is not found'); 
        return self::fetch($fields);    
  	}
1097721
public function activate($id)
    {
        $id = (int) $id;
        if ($id <= 0) {
            throw new Exception('Invalid param id');
        }
        $data = [];
        $data['id'] = $id;
        $data['status'] = 'active';
        return $this->update($data);
    }
98816
public function delPermission($id = 0)
    {
        $model = new Permission($this->db);
        try {
            return $model->delPermission($id);
        } catch (Exception $e) {
            throw new Exception($e->getMessage());
        }
    }
89718
public static function getInstance($id)
    {
        $instance = NULL;
        if (array_key_exists($id, self::$_instances))
        {
            $instance = self::$_instances[$id];
        }
        else
        {
            $instance = self::$_current_instance;
        }

        if (is_null($instance))
        {
            throw new \Exception('No instance found for datatable, you should set a datatable id in your
            action with "setDatatableId" using the id from your view ');
        }

        return $instance;
    }
827755
public function delUserRole($id)
    {
        if (empty($id)) {
            throw new Exception('参数错误');
        }
        $model = new UserRole($this->db);
        if ($model->where('user_id', $id)->delete() === false) {
            throw new Exception('删除用户角色出错');
        }
        return true;
    }
197201
public function switchToUser($id)
    {
        try {
            $user = $this->model->find($id);
            Session::put('original_user', Auth::id());
            Auth::login($user);
            return true;
        } catch (Exception $e) {
            throw new Exception("Error logging in as user", 1);
        }
    }
673428
public function raw(string $id)
    {
        $id = $this->getRealId($id);

        if (array_key_exists($id, $this->definitions)) {
            return $this->definitions[$id];
        }

        throw new Exception\NotFoundException($id);
    }
273057
public function getOneById($id)
    {
        $plugin = $this->getById($id);
        if (!$plugin) {
            throw new Exception(sprintf('Plugin "%s" not found', $id));
        }

        return $plugin;
    }
924641
public function edit(int $id)
    {
        if ($objectInfo = $this->model->findFirst($id)) {
            //update
            if ($objectInfo->update($this->request->getPut(), $this->updateFields)) {
                return $this->response($objectInfo->toArray());
            } else {
                //didnt work
                throw new Exception($objectInfo->getMessages()[0]);
            }
        } else {
            throw new Exception('Record not found');
        }
    }
1136390
public function reset($id)
    {
        $password = Str::random();

        $input = [
            'password' => $password,
        ];

        $rules = [
            'password' => 'required|min:6',
        ];

        $val = UserRepository::validate($input, $rules, true);
        if ($val->fails()) {
            return Redirect::route('users.show', ['users' => $id])->withErrors($val->errors());
        }

        $user = UserRepository::find($id);
        $this->checkUser($user);

        $user->update($input);

        $mail = [
            'password' => $password,
            'email'    => $user->getLogin(),
            'subject'  => Config::get('app.name').' - New Password Information',
        ];

        Mail::queue('credentials::emails.password', $mail, function ($message) use ($mail) {
            $message->to($mail['email'])->subject($mail['subject']);
        });

        return Redirect::route('users.show', ['users' => $id])
            ->with('success', 'The user\'s password has been reset successfully, and has been emailed to them.');
    }
273111
public function onceUsingId($id)
    {
        $this->setUser($this->provider->retrieveById($id));

        return $this->user instanceof UserContract;
    }
90942
public function id($id = null)
    {
        if ($id) {
            if (!$this->isValidId($id)) {
                throw new \InvalidArgumentException('$id may contain only [a-zA-Z0-9-_]');
            }
            if ($this->id) {
                throw new Exception('Cannot set id while session is active');
            }
            $this->requestedId = $id;
        }
        return $this->id;
    }