diff --git a/app/config/database.php b/app/config/database.php index 000eceaa7b..3dc48bdd8e 100644 --- a/app/config/database.php +++ b/app/config/database.php @@ -4,13 +4,6 @@ return [ 'fetch' => PDO::FETCH_CLASS, 'default' => 'mysql', 'connections' => [ - - 'sqlite' => [ - 'driver' => 'sqlite', - 'database' => __DIR__ . '/../database/production.sqlite', - 'prefix' => '', - ], - 'mysql' => [ 'driver' => 'mysql', 'host' => 'localhost', @@ -21,6 +14,18 @@ return [ 'collation' => 'utf8_unicode_ci', 'prefix' => '', ], + // previous database, if present: + 'old-firefly' => [ + 'driver' => 'mysql', + 'host' => 'localhost', + 'database' => '(previous database)', + 'username' => '', + 'password' => '', + 'charset' => 'utf8', + 'collation' => 'utf8_unicode_ci', + 'prefix' => '', + ], + ], 'migrations' => 'migrations', 'redis' => [ diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.php index d6670a8145..5619bfd06e 100644 --- a/app/controllers/HomeController.php +++ b/app/controllers/HomeController.php @@ -1,11 +1,25 @@ accounts = $accounts; + } + public function index() { + $count = $this->accounts->count(); + if($count == 0) { + return Redirect::route('start'); + } return View::make('index'); } + public function start() { + return View::make('start'); + } + } diff --git a/app/controllers/MigrationController.php b/app/controllers/MigrationController.php new file mode 100644 index 0000000000..acc1d03bb2 --- /dev/null +++ b/app/controllers/MigrationController.php @@ -0,0 +1,29 @@ +select('SELECT * from `users`;'); + } catch(PDOException $e) { + return View::make('migrate.index'); + } + + return Redirect::route('migrate.select-user'); + + + } + + public function selectUser() { + // select a user to import data from. + } + + public function migrate($userID) { + // import the data. + } +} \ No newline at end of file diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index 46e01edefc..931c033400 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -22,13 +22,10 @@ class UserController extends BaseController { if (!$this->user->auth()) { $rememberMe = Input::get('remember_me') == '1'; - $result = []; $data = [ - 'email' => Input::get('email'), + 'email' => Input::get('email'), 'password' => Input::get('password') ]; - - if (Auth::attempt($data, $rememberMe)) { return Redirect::route('index'); } @@ -62,6 +59,33 @@ class UserController extends BaseController return View::make('user.register'); } + public function logout() + { + Auth::logout(); + return Redirect::route('index'); + } + + public function remindme() + { + return View::make('user.remindme'); + } + + public function postRemindme() + { + $user = $this->user->findByEmail(Input::get('email')); + if ($user) { + if (Config::get('auth.verify_reset') === true) { + $this->email->sendResetVerification($user); + } + if (Config::get('auth.verify_reset') === false) { + $this->email->sendPasswordMail($user); + } + } + Session::flash('error', 'No good!'); + return View::make('user.remindme'); + + } + public function verify($verification) { $user = $this->user->findByVerification($verification); @@ -71,5 +95,14 @@ class UserController extends BaseController } return View::make('error')->with('message', 'Yo no hablo verification code!'); } + public function reset($reset) + { + $user = $this->user->findByReset($reset); + if ($user) { + $this->email->sendPasswordMail($user); + return View::make('user.registered'); + } + return View::make('error')->with('message', 'Yo no hablo reset code!'); + } } \ No newline at end of file diff --git a/app/database/migrations/2014_06_27_163032_create_users_table.php b/app/database/migrations/2014_06_27_163032_create_users_table.php index 380223be20..29ea724880 100644 --- a/app/database/migrations/2014_06_27_163032_create_users_table.php +++ b/app/database/migrations/2014_06_27_163032_create_users_table.php @@ -18,7 +18,8 @@ class CreateUsersTable extends Migration { $table->timestamps(); $table->string('email',100); $table->string('password',60); - $table->string('verification',32); + $table->string('verification',32)->nullable(); + $table->string('reset',32)->nullable(); $table->string('remember_token',255)->nullable(); $table->boolean('migrated'); }); diff --git a/app/lib/Firefly/Helper/Email/EmailHelper.php b/app/lib/Firefly/Helper/Email/EmailHelper.php index 366f9fcf92..d1defb325c 100644 --- a/app/lib/Firefly/Helper/Email/EmailHelper.php +++ b/app/lib/Firefly/Helper/Email/EmailHelper.php @@ -37,4 +37,21 @@ class EmailHelper implements EmailHelperInterface ); } + public function sendResetVerification(\User $user) + { + $reset = \Str::random(32); + $user->reset = $reset; + $user->save(); + $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?'); + } + ); + + + } + } \ No newline at end of file diff --git a/app/lib/Firefly/Helper/Email/EmailHelperInterface.php b/app/lib/Firefly/Helper/Email/EmailHelperInterface.php index 4dba74bc30..9f671f205c 100644 --- a/app/lib/Firefly/Helper/Email/EmailHelperInterface.php +++ b/app/lib/Firefly/Helper/Email/EmailHelperInterface.php @@ -6,5 +6,6 @@ interface EmailHelperInterface { public function sendVerificationMail(\User $user); public function sendPasswordMail(\User $user); + public function sendResetVerification(\User $user); } \ No newline at end of file diff --git a/app/lib/Firefly/Storage/Account/AccountRepositoryInterface.php b/app/lib/Firefly/Storage/Account/AccountRepositoryInterface.php new file mode 100644 index 0000000000..39399bdbce --- /dev/null +++ b/app/lib/Firefly/Storage/Account/AccountRepositoryInterface.php @@ -0,0 +1,11 @@ +accounts()->count(); + + } + +} \ No newline at end of file diff --git a/app/lib/Firefly/Storage/StorageServiceProvider.php b/app/lib/Firefly/Storage/StorageServiceProvider.php index 5023f78eb8..58c6eb2868 100644 --- a/app/lib/Firefly/Storage/StorageServiceProvider.php +++ b/app/lib/Firefly/Storage/StorageServiceProvider.php @@ -15,6 +15,11 @@ class StorageServiceProvider extends ServiceProvider 'Firefly\Storage\User\UserRepositoryInterface', 'Firefly\Storage\User\EloquentUserRepository' ); + + $this->app->bind( + 'Firefly\Storage\Account\AccountRepositoryInterface', + 'Firefly\Storage\Account\EloquentAccountRepository' + ); } } \ No newline at end of file diff --git a/app/lib/Firefly/Storage/User/EloquentUserRepository.php b/app/lib/Firefly/Storage/User/EloquentUserRepository.php index d9693e5630..492d232416 100644 --- a/app/lib/Firefly/Storage/User/EloquentUserRepository.php +++ b/app/lib/Firefly/Storage/User/EloquentUserRepository.php @@ -41,4 +41,13 @@ class EloquentUserRepository implements UserRepositoryInterface return \User::where('verification', $verification)->first(); } + public function findByReset($reset) + { + return \User::where('reset', $reset)->first(); + } + public function findByEmail($email) + { + return \User::where('email', $email)->first(); + } + } \ No newline at end of file diff --git a/app/lib/Firefly/Storage/User/UserRepositoryInterface.php b/app/lib/Firefly/Storage/User/UserRepositoryInterface.php index 4a39c50489..b369e5f852 100644 --- a/app/lib/Firefly/Storage/User/UserRepositoryInterface.php +++ b/app/lib/Firefly/Storage/User/UserRepositoryInterface.php @@ -7,9 +7,13 @@ namespace Firefly\Storage\User; interface UserRepositoryInterface { public function register(); + public function auth(); public function findByVerification($verification); + public function findByReset($reset); + + public function findByEmail($email); } \ No newline at end of file diff --git a/app/models/User.php b/app/models/User.php index 16ddbeee20..aab02454ea 100644 --- a/app/models/User.php +++ b/app/models/User.php @@ -33,4 +33,8 @@ class User extends Elegant implements UserInterface, RemindableInterface */ protected $hidden = array('password', 'remember_token'); + public function accounts() { + return $this->hasMany('Account'); + } + } diff --git a/app/routes.php b/app/routes.php index ec948bd205..c04c861fdd 100644 --- a/app/routes.php +++ b/app/routes.php @@ -1,10 +1,21 @@ 'HomeController@index','as' => 'index','before' => 'auth']); +Route::get('/start', ['uses' => 'HomeController@start','as' => 'start','before' => 'auth']); + +// migration controller: +Route::get('/migrate/index', ['uses' => 'MigrationController@index','as' => 'migrate.index', 'before' => 'auth']); // login, register, logout: Route::get('/login',['uses' => 'UserController@login','as' => 'login','before' => 'guest']); Route::get('/register',['uses' => 'UserController@register','as' => 'register','before' => 'guest']); Route::get('/verify/{verification}',['uses' => 'UserController@verify','as' => 'verify','before' => 'guest']); +Route::get('/reset/{reset}',['uses' => 'UserController@reset','as' => 'reset','before' => 'guest']); +Route::get('/logout',['uses' => 'UserController@logout','as' => 'logout','before' => 'auth']); +Route::get('/remindme',['uses' => 'UserController@remindme','as' => 'remindme','before' => 'guest']); + Route::post('/login',['uses' => 'UserController@postLogin','before' => 'csrf|guest']); Route::post('/register',['uses' => 'UserController@postRegister','before' => 'csrf|guest']); +Route::post('/remindme',['uses' => 'UserController@postRemindme','before' => 'csrf|guest']); \ No newline at end of file diff --git a/app/views/emails/user/remindme-html.blade.php b/app/views/emails/user/remindme-html.blade.php new file mode 100644 index 0000000000..e16c85fafe --- /dev/null +++ b/app/views/emails/user/remindme-html.blade.php @@ -0,0 +1,19 @@ + + + + + +

+ Hi! +

+

+ To get a new password, please verify your e-mail address. +

+

+ Cya! +

+ + + \ No newline at end of file diff --git a/app/views/emails/user/remindme-text.php b/app/views/emails/user/remindme-text.php new file mode 100644 index 0000000000..8d1980a3e4 --- /dev/null +++ b/app/views/emails/user/remindme-text.php @@ -0,0 +1,5 @@ +Hi! + +To get a new password, please verify your e-mail address: {{route('reset',$reset)}} + +Cya! diff --git a/app/views/index.blade.php b/app/views/index.blade.php index ee6cb58b96..07fe446d52 100644 --- a/app/views/index.blade.php +++ b/app/views/index.blade.php @@ -7,5 +7,10 @@ @if(Auth::check()) logged in! @endif + +
+logout! + + \ No newline at end of file diff --git a/app/views/layouts/default.blade.php b/app/views/layouts/default.blade.php index d7a18ece51..d0187cfb9e 100644 --- a/app/views/layouts/default.blade.php +++ b/app/views/layouts/default.blade.php @@ -4,7 +4,7 @@ - + Firefly diff --git a/app/views/migrate/index.blade.php b/app/views/migrate/index.blade.php new file mode 100644 index 0000000000..2360e87d61 --- /dev/null +++ b/app/views/migrate/index.blade.php @@ -0,0 +1,50 @@ +@extends('layouts.default') +@section('content') +
+
+

Firefly
+ Migration instructions +

+
    +
  1. Open app/config/database.php
  2. +
  3. Fill in the old-firefly connection records.
  4. +
  5. Refresh this page.
  6. +
+

+ It should look something like this: +

+
+return [
+    'fetch'       => PDO::FETCH_CLASS,
+    'default'     => 'mysql',
+    'connections' => [
+        'mysql'  => [
+            'driver'    => 'mysql',
+            'host'      => 'localhost',
+            'database'  => '(current database)',
+            'username'  => '',
+            'password'  => '',
+            'charset'   => 'utf8',
+            'collation' => 'utf8_unicode_ci',
+            'prefix'    => '',
+        ],
+        
+        'old-firefly'  => [
+            'driver'    => 'mysql',
+            'host'      => 'localhost',
+            'database'  => '(previous database)',
+            'username'  => '',
+            'password'  => '',
+            'charset'   => 'utf8',
+            'collation' => 'utf8_unicode_ci',
+            'prefix'    => '',
+        ],
+    ],
+
+

+ Refresh this page; when the connection is valid this page will refresh. +

+
+
+ +@stop \ No newline at end of file diff --git a/app/views/start.blade.php b/app/views/start.blade.php new file mode 100644 index 0000000000..cfbb5ca9f7 --- /dev/null +++ b/app/views/start.blade.php @@ -0,0 +1,41 @@ +@extends('layouts.default') +@section('content') +
+
+

Firefly
+ Welcome! +

+
+
+ +
+
+

+ Welcome to Firefly! To get started, choose either of the two options below. +

+
+
+ +
+
+

Start anew

+

+ Click the link below to create your first account, and get started with Firefly. +

+

+ Start with a new account +

+
+ +
+

Migrate from another Firefly

+

+ If you've used Firefly before and have another database around, follow this link to import + your data from a previous version. +

+

+ Import your old data +

+
+
+@stop \ No newline at end of file diff --git a/app/views/user/login.blade.php b/app/views/user/login.blade.php index 13da867dbe..692912e6f5 100644 --- a/app/views/user/login.blade.php +++ b/app/views/user/login.blade.php @@ -44,7 +44,7 @@

@endif

- Reset password + Forgot your password?

diff --git a/app/views/user/register.blade.php b/app/views/user/register.blade.php index 28bab127ba..ac6764b98e 100644 --- a/app/views/user/register.blade.php +++ b/app/views/user/register.blade.php @@ -33,7 +33,7 @@ Back to login form

- Reset password + Reset password

diff --git a/app/views/user/remindme.blade.php b/app/views/user/remindme.blade.php new file mode 100644 index 0000000000..94e8d38e16 --- /dev/null +++ b/app/views/user/remindme.blade.php @@ -0,0 +1,42 @@ +@extends('layouts.guest') +@section('content') +
+
+

Firefly
+ Forgot your password? +

+
+
+ +
+
+
+
+ +
+
+ {{Form::open()}} +
+ + +
+ + {{Form::close()}} +
+
+
+
+

+   +

+

+ Back to login form +

+

+ Register a new account +

+ +
+
+ +@stop \ No newline at end of file