2014-06-29 15:12:33 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace Firefly\Storage\User;
|
|
|
|
|
2014-07-25 06:02:01 -05:00
|
|
|
/**
|
|
|
|
* Class EloquentUserRepository
|
|
|
|
*
|
|
|
|
* @package Firefly\Storage\User
|
|
|
|
*/
|
2014-06-29 15:12:33 -05:00
|
|
|
class EloquentUserRepository implements UserRepositoryInterface
|
|
|
|
{
|
2014-07-25 06:02:01 -05:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2014-06-29 15:12:33 -05:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-25 06:02:01 -05:00
|
|
|
/**
|
|
|
|
* @param $array
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-07-02 16:12:31 -05:00
|
|
|
public function auth($array)
|
2014-06-29 15:12:33 -05:00
|
|
|
{
|
2014-07-02 16:12:31 -05:00
|
|
|
$user = \User::where('email', $array['email'])->first();
|
2014-06-29 15:12:33 -05:00
|
|
|
if (!is_null($user)) {
|
2014-07-02 16:12:31 -05:00
|
|
|
if (\Hash::check($array['password'], $user->password)) {
|
2014-06-29 15:12:33 -05:00
|
|
|
}
|
|
|
|
}
|
2014-07-29 12:37:52 -05:00
|
|
|
|
2014-06-29 15:12:33 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-06 00:06:45 -05:00
|
|
|
/**
|
|
|
|
* @param $email
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function findByEmail($email)
|
|
|
|
{
|
|
|
|
return \User::where('email', $email)->first();
|
|
|
|
}
|
|
|
|
|
2014-07-25 06:02:01 -05:00
|
|
|
/**
|
|
|
|
* @param $reset
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2014-06-30 00:26:38 -05:00
|
|
|
public function findByReset($reset)
|
|
|
|
{
|
|
|
|
return \User::where('reset', $reset)->first();
|
|
|
|
}
|
2014-07-02 16:12:31 -05:00
|
|
|
|
2014-07-25 06:02:01 -05:00
|
|
|
/**
|
2014-08-06 00:06:45 -05:00
|
|
|
* @param $array
|
2014-07-25 06:02:01 -05:00
|
|
|
*
|
2014-08-06 00:06:45 -05:00
|
|
|
* @return bool|\User
|
2014-07-25 06:02:01 -05:00
|
|
|
*/
|
2014-08-06 00:06:45 -05:00
|
|
|
public function register($array)
|
2014-06-30 00:26:38 -05:00
|
|
|
{
|
2014-09-02 10:27:28 -05:00
|
|
|
$user = new \User;
|
|
|
|
$user->email = isset($array['email']) ? $array['email'] : null;
|
2014-08-06 00:06:45 -05:00
|
|
|
$user->migrated = 0;
|
2014-09-02 10:27:28 -05:00
|
|
|
$user->reset = \Str::random(32);
|
2014-08-06 00:06:45 -05:00
|
|
|
$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());
|
2014-08-10 04:30:14 -05:00
|
|
|
|
2014-08-06 00:06:45 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
return $user;
|
2014-06-30 00:26:38 -05:00
|
|
|
}
|
|
|
|
|
2014-07-25 06:02:01 -05:00
|
|
|
/**
|
|
|
|
* @param \User $user
|
|
|
|
* @param $password
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-07-03 02:16:17 -05:00
|
|
|
public function updatePassword(\User $user, $password)
|
|
|
|
{
|
|
|
|
/** @noinspection PhpUndefinedFieldInspection */
|
|
|
|
$user->password = $password;
|
|
|
|
/** @noinspection PhpUndefinedMethodInspection */
|
2014-08-06 00:06:45 -05:00
|
|
|
$user->forceSave();
|
2014-07-29 12:37:52 -05:00
|
|
|
|
2014-07-03 02:16:17 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-29 15:12:33 -05:00
|
|
|
}
|