<commit_before><?php
/**
 * Laravel 4 Core - PasswordBroker replacement
 *
 * @author    <NAME> <<EMAIL>>
 * @license   http://opensource.org/licenses/MIT
 * @package   Laravel 4 Core
 */

namespace c\Auth\Reminders;

use Carbon\Carbon;
use Illuminate\Auth\Reminders\RemindableInterface;
use Illuminate\Support\Facades\Lang;
use Illuminate\Mail\Mailer;
use Illuminate\Auth\Reminders\ReminderRepositoryInterface;
use Illuminate\Auth\UserProviderInterface;

/**
 * Class responsible for handling password resets. Improved version of
 * Illuminate\Auth\Reminders\PasswordBroker - doesn't return redirect responses
 * with session data hard-coded in, but rather does things behind the scenes,
 * returns boolean flags or throws exceptions and lets the developer decide what
 * should be done with the results.
 */
class PasswordBroker
{
	protected $users;
	protected $reminders;
	protected $mailer;
	protected $emailView;
	protected $queue = false;

	public function __construct(
		UserProviderInterface $users,
		ReminderRepositoryInterface $reminders,
		Mailer $mailer,
		array $config
	) {
		$this->users = $users;
		$this->reminders = $reminders;
		$this->mailer = $mailer;
		$this->emailView = $config['email-view'];
		$this->queue = $config['queue-email'];
	}

	/**
	 * Register a request for a password reset. Create a reset token for a user
	 * and send him/her an email with instructions on how to reset password.
	 *
	 * @param  RemindableInterface $user
	 *
	 * @return bool
	 */
	public function requestReset(RemindableInterface $user)
	{
		$token = $this->reminders->create($user);
		return $this->mail($user, $token);
	}

	/**
	 * Send an email to a user with instructions on how to reset his/her password.
	 *
	 * @param  RemindableInterface $user
	 * @param  string $token
	 *
	 * @return bool
	 */
	public function mail(RemindableInterface $user, $token)
	{
		$email = $user->getReminderEmail();

		$method = $this->queue ? 'queue' : 'mail';

		$viewData = ['token' => $token];

		return $this->mailer->$method($this->emailView, $viewData, function($msg) use ($email) {
			$msg->to($email)
				->subject(Lang::get('auth.reminder.subject'));
		});
	}

	/**
	 * Reset a user's password.
	 *
	 * @param  RemindableInterface $user
	 * @param  string              $token
	 * @param  string              $newPassword
	 *
	 * @return boolean
	 */
	public function resetUser(RemindableInterface $user, $token, $newPassword)
	{
		if (!$this->reminders->exists($user, $token)) {
			return false;
		}

		$user->setPasswordAttribute($newPassword);
		$user->save();
		$this->reminders->delete($token);

		return true;
	}
}
<commit_msg>changed lang string<commit_after><?php
/**
 * Laravel 4 Core - PasswordBroker replacement
 *
 * @author    <NAME> <<EMAIL>>
 * @license   http://opensource.org/licenses/MIT
 * @package   Laravel 4 Core
 */

namespace c\Auth\Reminders;

use Carbon\Carbon;
use Illuminate\Auth\Reminders\RemindableInterface;
use Illuminate\Support\Facades\Lang;
use Illuminate\Mail\Mailer;
use Illuminate\Auth\Reminders\ReminderRepositoryInterface;
use Illuminate\Auth\UserProviderInterface;

/**
 * Class responsible for handling password resets. Improved version of
 * Illuminate\Auth\Reminders\PasswordBroker - doesn't return redirect responses
 * with session data hard-coded in, but rather does things behind the scenes,
 * returns boolean flags or throws exceptions and lets the developer decide what
 * should be done with the results.
 */
class PasswordBroker
{
	protected $users;
	protected $reminders;
	protected $mailer;
	protected $emailView;
	protected $queue = false;

	public function __construct(
		UserProviderInterface $users,
		ReminderRepositoryInterface $reminders,
		Mailer $mailer,
		array $config
	) {
		$this->users = $users;
		$this->reminders = $reminders;
		$this->mailer = $mailer;
		$this->emailView = $config['email-view'];
		$this->queue = $config['queue-email'];
	}

	/**
	 * Register a request for a password reset. Create a reset token for a user
	 * and send him/her an email with instructions on how to reset password.
	 *
	 * @param  RemindableInterface $user
	 *
	 * @return bool
	 */
	public function requestReset(RemindableInterface $user)
	{
		$token = $this->reminders->create($user);
		return $this->mail($user, $token);
	}

	/**
	 * Send an email to a user with instructions on how to reset his/her password.
	 *
	 * @param  RemindableInterface $user
	 * @param  string $token
	 *
	 * @return bool
	 */
	public function mail(RemindableInterface $user, $token)
	{
		$email = $user->getReminderEmail();

		$method = $this->queue ? 'queue' : 'mail';

		$viewData = ['token' => $token];

		return $this->mailer->$method($this->emailView, $viewData, function($msg) use ($email) {
			$msg->to($email)
				->subject(Lang::get('c::auth.resetpass-title'));
		});
	}

	/**
	 * Reset a user's password.
	 *
	 * @param  RemindableInterface $user
	 * @param  string              $token
	 * @param  string              $newPassword
	 *
	 * @return boolean
	 */
	public function resetUser(RemindableInterface $user, $token, $newPassword)
	{
		if (!$this->reminders->exists($user, $token)) {
			return false;
		}

		$user->setPasswordAttribute($newPassword);
		$user->save();
		$this->reminders->delete($token);

		return true;
	}
}

{'fraction_non_alphanumeric': 0.1314892004547177, 'fraction_numerical': 0.0007578628268283441, 'mean_word_length': 3.856485740570377, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 53, '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': '6801658', 'n_tokens_mistral': 1745, 'n_tokens_neox': 1637, 'n_words': 446}