mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	New code, building a migration routine.
This commit is contained in:
		| @@ -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'       => [ | ||||
|   | ||||
| @@ -1,11 +1,25 @@ | ||||
| <?php | ||||
|  | ||||
| use Firefly\Storage\Account\AccountRepositoryInterface as ARI; | ||||
|  | ||||
| class HomeController extends BaseController { | ||||
|  | ||||
|     public function __construct(ARI $accounts) { | ||||
|         $this->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'); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
							
								
								
									
										29
									
								
								app/controllers/MigrationController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								app/controllers/MigrationController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | ||||
| <?php | ||||
| class MigrationController extends BaseController { | ||||
|     public function index() { | ||||
|         // check if database connection is present. | ||||
|         $configValue = Config::get('database.connections.old-firefly'); | ||||
|         if(is_null($configValue)) { | ||||
|             return View::make('migrate.index'); | ||||
|         } | ||||
|  | ||||
|         // try to connect to it: | ||||
|         try { | ||||
|         DB::connection('old-firefly')->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. | ||||
|     } | ||||
| } | ||||
| @@ -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!'); | ||||
|     } | ||||
|  | ||||
| }  | ||||
| @@ -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'); | ||||
| 		}); | ||||
|   | ||||
| @@ -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?'); | ||||
|             } | ||||
|         ); | ||||
|  | ||||
|  | ||||
|     } | ||||
|  | ||||
| }  | ||||
| @@ -6,5 +6,6 @@ interface EmailHelperInterface { | ||||
|  | ||||
|     public function sendVerificationMail(\User $user); | ||||
|     public function sendPasswordMail(\User $user); | ||||
|     public function sendResetVerification(\User $user); | ||||
|  | ||||
| }  | ||||
| @@ -0,0 +1,11 @@ | ||||
| <?php | ||||
|  | ||||
|  | ||||
| namespace Firefly\Storage\Account; | ||||
|  | ||||
|  | ||||
| interface AccountRepositoryInterface | ||||
| { | ||||
|     public function count(); | ||||
|  | ||||
| }  | ||||
| @@ -0,0 +1,17 @@ | ||||
| <?php | ||||
|  | ||||
|  | ||||
| namespace Firefly\Storage\Account; | ||||
|  | ||||
| class EloquentAccountRepository implements AccountRepositoryInterface | ||||
| { | ||||
|     public function __construct() | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     public function count() { | ||||
|         return \Auth::user()->accounts()->count(); | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -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' | ||||
|         ); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -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(); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -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); | ||||
|  | ||||
|  | ||||
| }  | ||||
| @@ -33,4 +33,8 @@ class User extends Elegant implements UserInterface, RemindableInterface | ||||
|      */ | ||||
|     protected $hidden = array('password', 'remember_token'); | ||||
|  | ||||
|     public function accounts() { | ||||
|         return $this->hasMany('Account'); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,10 +1,21 @@ | ||||
| <?php | ||||
|  | ||||
| // basic home views: | ||||
| Route::get('/', ['uses' => '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']); | ||||
							
								
								
									
										19
									
								
								app/views/emails/user/remindme-html.blade.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/views/emails/user/remindme-html.blade.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| <html> | ||||
| <head> | ||||
|     <style type="text/css"> | ||||
|         * {font-size:Arial;} | ||||
|     </style> | ||||
| </head> | ||||
| <body> | ||||
| <p> | ||||
|     Hi! | ||||
| </p> | ||||
| <p> | ||||
|     To get a new password, please <a href="{{route('reset',$reset)}}">verify your e-mail address</a>. | ||||
| </p> | ||||
| <p> | ||||
|     Cya! | ||||
| </p> | ||||
|  | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										5
									
								
								app/views/emails/user/remindme-text.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								app/views/emails/user/remindme-text.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| Hi! | ||||
|  | ||||
| To get a new password, please verify your e-mail address: {{route('reset',$reset)}} | ||||
|  | ||||
| Cya! | ||||
| @@ -7,5 +7,10 @@ | ||||
| @if(Auth::check()) | ||||
| logged in! | ||||
| @endif | ||||
|  | ||||
| <br /> | ||||
| <a href="{{route('logout')}}">logout!</a> | ||||
|  | ||||
|  | ||||
| </body> | ||||
| </html> | ||||
| @@ -4,7 +4,7 @@ | ||||
|     <meta charset="utf-8"> | ||||
|     <meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||||
|     <meta name="viewport" content="width=device-width, initial-scale=1"> | ||||
|     <base href="{{url::to('/')}}"> | ||||
|     <base href="{{URL::route('index')}}/"> | ||||
|     <title>Firefly</title> | ||||
|  | ||||
|     <!-- Bootstrap --> | ||||
|   | ||||
							
								
								
									
										50
									
								
								app/views/migrate/index.blade.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								app/views/migrate/index.blade.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,50 @@ | ||||
| @extends('layouts.default') | ||||
| @section('content') | ||||
| <div class="row"> | ||||
|     <div class="col-lg-8 col-md-8 col-sm-12"> | ||||
|         <h1>Firefly<br/> | ||||
|             <small>Migration instructions</small> | ||||
|         </h1> | ||||
|         <ol> | ||||
|             <li>Open <code>app/config/database.php</code></li> | ||||
|             <li>Fill in the <code>old-firefly</code> connection records.</li> | ||||
|             <li>Refresh this page.</li> | ||||
|         </ol> | ||||
|         <p> | ||||
|             It should look something like this: | ||||
|         </p> | ||||
| <pre> | ||||
| 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'    => '', | ||||
|         ], | ||||
|         <strong> | ||||
|         'old-firefly'  => [ | ||||
|             'driver'    => 'mysql', | ||||
|             'host'      => 'localhost', | ||||
|             'database'  => '(previous database)', | ||||
|             'username'  => '', | ||||
|             'password'  => '', | ||||
|             'charset'   => 'utf8', | ||||
|             'collation' => 'utf8_unicode_ci', | ||||
|             'prefix'    => '', | ||||
|         ],</strong> | ||||
|     ], | ||||
| </pre> | ||||
|         <p> | ||||
|             Refresh this page; when the connection is valid this page will refresh. | ||||
|         </p> | ||||
|     </div> | ||||
| </div> | ||||
|  | ||||
| @stop | ||||
							
								
								
									
										41
									
								
								app/views/start.blade.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								app/views/start.blade.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | ||||
| @extends('layouts.default') | ||||
| @section('content') | ||||
| <div class="row"> | ||||
|     <div class="col-lg-12 col-md-12 col-sm-12"> | ||||
|         <h1>Firefly<br/> | ||||
|             <small>Welcome!</small> | ||||
|         </h1> | ||||
|     </div> | ||||
| </div> | ||||
|  | ||||
| <div class="row"> | ||||
|     <div class="col-lg-12 col-md-12 col-sm-12"> | ||||
|         <p> | ||||
|             Welcome to Firefly! To get started, choose either of the two options below. | ||||
|         </p> | ||||
|     </div> | ||||
| </div> | ||||
|  | ||||
| <div class="row"> | ||||
|     <div class="col-lg-6 col-md-6 col-sm-12"> | ||||
|         <h2>Start anew</h2> | ||||
|         <p> | ||||
|             Click the link below to create your first account, and get started with Firefly. | ||||
|         </p> | ||||
|         <p> | ||||
|             <a href="#" class="btn btn-info">Start with a new account</a> | ||||
|         </p> | ||||
|     </div> | ||||
|  | ||||
|     <div class="col-lg-6 col-md-6 col-sm-12"> | ||||
|         <h2>Migrate from another Firefly</h2> | ||||
|         <p> | ||||
|             If you've used Firefly before and have another database around, follow this link to import | ||||
|             your data from a previous version. | ||||
|         </p> | ||||
|         <p> | ||||
|             <a href="{{route('migrate.index')}}" class="btn btn-info">Import your old data</a> | ||||
|         </p> | ||||
|     </div> | ||||
| </div> | ||||
| @stop | ||||
| @@ -44,7 +44,7 @@ | ||||
|         </p> | ||||
|         @endif | ||||
|         <p> | ||||
|             <a href="#" class="btn btn-default">Reset password</a> | ||||
|             <a href="{{route('remindme')}}" class="btn btn-default">Forgot your password?</a> | ||||
|         </p> | ||||
|  | ||||
|     </div> | ||||
|   | ||||
| @@ -33,7 +33,7 @@ | ||||
|             <a href="{{route('login')}}" class="btn btn-default">Back to login form</a> | ||||
|         </p> | ||||
|         <p> | ||||
|             <a href="#" class="btn btn-default">Reset password</a> | ||||
|             <a href="{{route('remindme')}}" class="btn btn-default">Reset password</a> | ||||
|         </p> | ||||
|  | ||||
|     </div> | ||||
|   | ||||
							
								
								
									
										42
									
								
								app/views/user/remindme.blade.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								app/views/user/remindme.blade.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,42 @@ | ||||
| @extends('layouts.guest') | ||||
| @section('content') | ||||
| <div class="row"> | ||||
|     <div class="col-lg-12 col-md-12 col-sm-12"> | ||||
|         <h1>Firefly<br/> | ||||
|             <small>Forgot your password?</small> | ||||
|         </h1> | ||||
|     </div> | ||||
| </div> | ||||
|  | ||||
| <div class="row"> | ||||
|     <div class="col-lg-12 col-md-12 col-sm-12"> | ||||
|     </div> | ||||
| </div> | ||||
|  | ||||
| <div class="row"> | ||||
|     <div class="col-lg-4 col-md-4 col-sm-12"> | ||||
|         {{Form::open()}} | ||||
|         <div class="form-group"> | ||||
|             <label for="inputEmail">Email address</label> | ||||
|             <input type="email" class="form-control" id="inputEmail" name="email" placeholder="Enter email"> | ||||
|         </div> | ||||
|         <button type="submit" class="btn btn-info">Submit</button> | ||||
|         {{Form::close()}} | ||||
|     </div> | ||||
| </div> | ||||
| <div class="row"> | ||||
|     <div class="col-lg-4 col-md-4 col-sm-12"> | ||||
|         <p> | ||||
|               | ||||
|         </p> | ||||
|         <p> | ||||
|             <a href="{{route('login')}}" class="btn btn-default">Back to login form</a> | ||||
|         </p> | ||||
|         <p> | ||||
|             <a href="{{route('register')}}" class="btn btn-default">Register a new account</a> | ||||
|         </p> | ||||
|  | ||||
|     </div> | ||||
| </div> | ||||
|  | ||||
| @stop | ||||
		Reference in New Issue
	
	Block a user