mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-18 12:28:46 +00:00
Combination of initial files and some new code for login and user registration.
This commit is contained in:
40
app/lib/Firefly/Helper/Email/EmailHelper.php
Normal file
40
app/lib/Firefly/Helper/Email/EmailHelper.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace Firefly\Helper\Email;
|
||||
|
||||
class EmailHelper implements EmailHelperInterface
|
||||
{
|
||||
public function sendVerificationMail(\User $user)
|
||||
{
|
||||
|
||||
$verification = \Str::random(32);
|
||||
$user->verification = $verification;
|
||||
$user->save();
|
||||
$email = $user->email;
|
||||
$data = ['verification' => $verification];
|
||||
|
||||
\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.');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function sendPasswordMail(\User $user)
|
||||
{
|
||||
|
||||
$password = \Str::random(12);
|
||||
$user->password = \Hash::make($password);
|
||||
$user->verification = \Str::random(32); // new one.
|
||||
$user->save();
|
||||
$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!');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
10
app/lib/Firefly/Helper/Email/EmailHelperInterface.php
Normal file
10
app/lib/Firefly/Helper/Email/EmailHelperInterface.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Helper\Email;
|
||||
|
||||
interface EmailHelperInterface {
|
||||
|
||||
public function sendVerificationMail(\User $user);
|
||||
public function sendPasswordMail(\User $user);
|
||||
|
||||
}
|
||||
20
app/lib/Firefly/Helper/HelperServiceProvider.php
Normal file
20
app/lib/Firefly/Helper/HelperServiceProvider.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Firefly\Helper;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class HelperServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
|
||||
// Triggered automatically by Laravel
|
||||
public function register()
|
||||
{
|
||||
// mail:
|
||||
$this->app->bind(
|
||||
'Firefly\Helper\Email\EmailHelperInterface',
|
||||
'Firefly\Helper\Email\EmailHelper'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
20
app/lib/Firefly/Storage/StorageServiceProvider.php
Normal file
20
app/lib/Firefly/Storage/StorageServiceProvider.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Firefly\Storage;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class StorageServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
|
||||
// Triggered automatically by Laravel
|
||||
public function register()
|
||||
{
|
||||
// storage:
|
||||
$this->app->bind(
|
||||
'Firefly\Storage\User\UserRepositoryInterface',
|
||||
'Firefly\Storage\User\EloquentUserRepository'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
44
app/lib/Firefly/Storage/User/EloquentUserRepository.php
Normal file
44
app/lib/Firefly/Storage/User/EloquentUserRepository.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Firefly\Storage\User;
|
||||
|
||||
class EloquentUserRepository implements UserRepositoryInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
$user = new \User;
|
||||
$user->email = \Input::get('email');
|
||||
$user->migrated = 0;
|
||||
$user->verification = \Str::random(32);
|
||||
$user->password = \Hash::make(\Str::random(12));
|
||||
|
||||
if (!$user->isValid()) {
|
||||
\Log::error('Invalid user');
|
||||
\Session::flash('error', 'Input invalid, please try again.');
|
||||
return false;
|
||||
}
|
||||
$user->save();
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function auth()
|
||||
{
|
||||
$user = \User::where('email', \Input::get('email'))->first();
|
||||
if (!is_null($user)) {
|
||||
if (\Hash::check(\Input::get('password'), $user->password)) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function findByVerification($verification)
|
||||
{
|
||||
return \User::where('verification', $verification)->first();
|
||||
}
|
||||
|
||||
}
|
||||
15
app/lib/Firefly/Storage/User/UserRepositoryInterface.php
Normal file
15
app/lib/Firefly/Storage/User/UserRepositoryInterface.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Firefly\Storage\User;
|
||||
|
||||
|
||||
interface UserRepositoryInterface
|
||||
{
|
||||
public function register();
|
||||
public function auth();
|
||||
|
||||
public function findByVerification($verification);
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user