<commit_before><?php
/**
 * ownCloud - impersonate
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright <NAME> 2015
 */

namespace OCA\Impersonate\Controller;


use OCP\AppFramework\Http\JSONResponse;
use \OCP\IRequest;
use \OCP\AppFramework\Controller;
use OCP\IUserManager;
use OCP\IUserSession;

class SettingsController extends Controller {

    /**
     * @var IUserManager
     */
    private $userManager;
    /**
     * @var IUserSession
     */
    private $userSession;

    public function __construct($appName, IRequest $request, IUserManager $userManager, IUserSession $userSession){
        parent::__construct($appName, $request);
        $this->userManager = $userManager;
        $this->userSession = $userSession;
    }



    /**
     * become another user
     * @UseSession
     */
    public function impersonate($userid) {
        $user = $this->userManager->get($userid);
        $this->userSession->setUser($user);
        return new JSONResponse();
    }


}<commit_msg>Implemented user search to avoid errors occuring due to non-existant usernames and case-sensitive usernames<commit_after>﻿<?php
/**
 * ownCloud - impersonate
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright <NAME> 2015
 */

namespace OCA\Impersonate\Controller;


use OCP\AppFramework\Http\JSONResponse;
use \OCP\IRequest;
use \OCP\AppFramework\Controller;
use OCP\IUserManager;
use OCP\IUserSession;

class SettingsController extends Controller {

	/**
	 * @var IUserManager
	 */
	private $userManager;
	/**
	 * @var IUserSession
	 */
	private $userSession;

	public function __construct($appName, IRequest $request, IUserManager $userManager, IUserSession $userSession) {
		parent::__construct($appName, $request);
		$this->userManager = $userManager;
		$this->userSession = $userSession;
	}

	/**
	 * become another user
	 * @UseSession
	 */
	public function impersonate($userid) {
		$users = $this->userManager->search($userid, 1, 0);
		if (count($users) > 0) {
			$user = array_shift($users);
			if (strcasecmp($user->getUID(),$userid) === 0) {
				$this->userSession->setUser($user);
			}
		}
		return new JSONResponse();
	}
}

{'fraction_non_alphanumeric': 0.13017498932991892, 'fraction_numerical': 0.00597524541186513, 'mean_word_length': 3.6051080550098233, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '907632', 'n_tokens_mistral': 772, 'n_tokens_neox': 724, 'n_words': 181}