mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-07 06:31:22 +00:00
Various changes to support the removed old code.
This commit is contained in:
57
app/lib/FireflyIII/Database/User.php
Normal file
57
app/lib/FireflyIII/Database/User.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database;
|
||||
|
||||
|
||||
/**
|
||||
* Class User
|
||||
* @package FireflyIII\Database
|
||||
*/
|
||||
class User
|
||||
{
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return bool|\User
|
||||
*/
|
||||
public function register(array $data)
|
||||
{
|
||||
$user = new \User;
|
||||
$user->email = isset($data['email']) ? $data['email'] : null;
|
||||
$user->migrated = 0;
|
||||
$user->reset = \Str::random(32);
|
||||
$user->password = \Hash::make(\Str::random(12));
|
||||
|
||||
if (!$user->save()) {
|
||||
\Log::error('Invalid user with data: ' . isset($data['email']) ? $data['email'] : '(no email!)');
|
||||
\Session::flash('error', 'Input invalid, please try again: ' . $user->errors()->first());
|
||||
|
||||
return false;
|
||||
}
|
||||
$user->save();
|
||||
|
||||
return $user;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $mail
|
||||
*
|
||||
* @return null|User
|
||||
*/
|
||||
public function findByEmail($mail)
|
||||
{
|
||||
return \User::where('email', $mail)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $reset
|
||||
*
|
||||
* @return null|User
|
||||
*/
|
||||
public function findByReset($reset)
|
||||
{
|
||||
return \User::where('reset', $reset)->first();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace FireflyIII;
|
||||
|
||||
use FireflyIII\Shared\Validation\FireflyValidator;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
/**
|
||||
@@ -11,6 +12,14 @@ use Illuminate\Support\ServiceProvider;
|
||||
class FF3ServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
public function boot()
|
||||
{
|
||||
$this->app->validator->resolver(
|
||||
function ($translator, $data, $rules, $messages) {
|
||||
return new FireflyValidator($translator, $data, $rules, $messages);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered automatically by Laravel
|
||||
@@ -23,6 +32,9 @@ class FF3ServiceProvider extends ServiceProvider
|
||||
// preferences:
|
||||
$this->app->bind('FireflyIII\Shared\Preferences\PreferencesInterface', 'FireflyIII\Shared\Preferences\Preferences');
|
||||
|
||||
// registration and user mail:
|
||||
$this->app->bind('FireflyIII\Shared\Mail\RegistrationInterface', 'FireflyIII\Shared\Mail\Registration');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
77
app/lib/FireflyIII/Shared/Mail/Registration.php
Normal file
77
app/lib/FireflyIII/Shared/Mail/Registration.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
namespace FireflyIII\Shared\Mail;
|
||||
|
||||
/**
|
||||
* Class Registration
|
||||
*
|
||||
* @package FireflyIII\Shared\Mail
|
||||
*/
|
||||
class Registration implements RegistrationInterface
|
||||
{
|
||||
/**
|
||||
* @param \User $user
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function sendVerificationMail(\User $user)
|
||||
{
|
||||
|
||||
$reset = \Str::random(32);
|
||||
$user->reset = $reset;
|
||||
$user->forceSave();
|
||||
$email = $user->email;
|
||||
$data = ['reset' => $reset];
|
||||
|
||||
\Mail::send(
|
||||
['emails.user.verify-html', 'emails.user.verify-text'], $data, function ($message) use ($email) {
|
||||
$message->to($email, $email)->subject('Verify your e-mail address.');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function sendPasswordMail(\User $user)
|
||||
{
|
||||
|
||||
$password = \Str::random(12);
|
||||
$user->password = $password;
|
||||
$user->reset = \Str::random(32); // new one.
|
||||
$user->forceSave();
|
||||
$email = $user->email;
|
||||
|
||||
|
||||
$data = ['password' => $password];
|
||||
\Mail::send(
|
||||
['emails.user.register-html', 'emails.user.register-text'], $data, function ($message) use ($email) {
|
||||
$message->to($email, $email)->subject('Welcome to Firefly!');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function sendResetVerification(\User $user)
|
||||
{
|
||||
$reset = \Str::random(32);
|
||||
$user->reset = $reset;
|
||||
$user->forceSave();
|
||||
$email = $user->email;
|
||||
|
||||
$data = ['reset' => $reset];
|
||||
\Mail::send(
|
||||
['emails.user.remindme-html', 'emails.user.remindme-text'], $data, function ($message) use ($email) {
|
||||
$message->to($email, $email)->subject('Forgot your password?');
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
34
app/lib/FireflyIII/Shared/Mail/RegistrationInterface.php
Normal file
34
app/lib/FireflyIII/Shared/Mail/RegistrationInterface.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Shared\Mail;
|
||||
|
||||
/**
|
||||
* Interface RegistrationInterface
|
||||
*
|
||||
* @package FireflyIII\Shared\Mail
|
||||
*/
|
||||
interface RegistrationInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function sendVerificationMail(\User $user);
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function sendPasswordMail(\User $user);
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function sendResetVerification(\User $user);
|
||||
|
||||
}
|
||||
@@ -29,8 +29,8 @@ class Filter
|
||||
if (!is_null(\Session::get('range'))) {
|
||||
$range = \Session::get('range');
|
||||
} else {
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
$preferences = \App::make('Firefly\Helper\Preferences\PreferencesHelperInterface');
|
||||
/** @var \FireflyIII\Shared\Preferences\PreferencesInterface $preferences */
|
||||
$preferences = \App::make('FireflyIII\Shared\Preferences\PreferencesInterface');
|
||||
$viewRange = $preferences->get('viewRange', '1M');
|
||||
|
||||
// default range:
|
||||
|
||||
22
app/lib/FireflyIII/Shared/Validation/FireflyValidator.php
Normal file
22
app/lib/FireflyIII/Shared/Validation/FireflyValidator.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace FireflyIII\Shared\Validation;
|
||||
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
/**
|
||||
* Class FireflyValidator
|
||||
*
|
||||
* @package FireflyIII\Shared\Validation
|
||||
*/
|
||||
class FireflyValidator extends Validator
|
||||
{
|
||||
public function validateAlphabasic($attribute, $value, $parameters)
|
||||
{
|
||||
$pattern = '/[^[:alnum:]_\-\.\& \(\)\'"]/iu';
|
||||
if (preg_match($pattern, $value)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace FireflyIII\Shared\Validation;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
/**
|
||||
* Class ValidationServiceProvider
|
||||
* @package FireflyIII\Shared\Validation
|
||||
*/
|
||||
class ValidationServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function boot()
|
||||
{
|
||||
$this->app->validator->resolver(
|
||||
function ($translator, $data, $rules, $messages) {
|
||||
return new FireflyValidator($translator, $data, $rules, $messages);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user