mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 10:47:00 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			80 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			80 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| 
 | |
| namespace Firefly\Storage\User;
 | |
| 
 | |
| /**
 | |
|  * Class EloquentUserRepository
 | |
|  *
 | |
|  * @package Firefly\Storage\User
 | |
|  */
 | |
| class EloquentUserRepository implements UserRepositoryInterface
 | |
| {
 | |
|     /**
 | |
|      *
 | |
|      */
 | |
|     public function __construct()
 | |
|     {
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @param $email
 | |
|      *
 | |
|      * @return mixed
 | |
|      */
 | |
|     public function findByEmail($email)
 | |
|     {
 | |
|         return \User::where('email', $email)->first();
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @param $reset
 | |
|      *
 | |
|      * @return mixed
 | |
|      */
 | |
|     public function findByReset($reset)
 | |
|     {
 | |
|         return \User::where('reset', $reset)->first();
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @param $array
 | |
|      *
 | |
|      * @return bool|\User
 | |
|      */
 | |
|     public function register($array)
 | |
|     {
 | |
|         $user           = new \User;
 | |
|         $user->email    = isset($array['email']) ? $array['email'] : null;
 | |
|         $user->migrated = 0;
 | |
|         $user->reset    = \Str::random(32);
 | |
|         $user->password = \Hash::make(\Str::random(12));
 | |
| 
 | |
|         if (!$user->save()) {
 | |
|             \Log::error('Invalid user');
 | |
|             \Session::flash('error', 'Input invalid, please try again: ' . $user->errors()->first());
 | |
| 
 | |
|             return false;
 | |
|         }
 | |
|         $user->save();
 | |
| 
 | |
|         return $user;
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @param \User $user
 | |
|      * @param       $password
 | |
|      *
 | |
|      * @return bool
 | |
|      */
 | |
|     public function updatePassword(\User $user, $password)
 | |
|     {
 | |
|         /** @noinspection PhpUndefinedFieldInspection */
 | |
|         $user->password = $password;
 | |
|         /** @noinspection PhpUndefinedMethodInspection */
 | |
|         $user->forceSave();
 | |
| 
 | |
|         return true;
 | |
|     }
 | |
| 
 | |
| } |