firefly-iii/app/lib/FireflyIII/Database/User.php
2014-11-12 22:37:09 +01:00

73 lines
1.4 KiB
PHP

<?php
namespace FireflyIII\Database;
/**
* Class User
*
* @package FireflyIII\Database
*/
class User
{
/**
* @param $mail
*
* @return null|User
*/
public function findByEmail($mail)
{
return \User::where('email', $mail)->first();
}
/**
* @param $reset
*
* @return null|User
*/
public function findByReset($reset)
{
return \User::where('reset', $reset)->first();
}
/**
* @param array $data
*
* @return bool|\User
*/
public function register(array $data)
{
$user = new \User;
$user->email = isset($data['email']) ? $data['email'] : null;
$user->migrated = 0;
$user->reset = \Str::random(32);
$user->password = \Hash::make(\Str::random(12));
if (!$user->save()) {
\Log::error('Invalid user with data: ' . isset($data['email']) ? $data['email'] : '(no email!)');
\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)
{
$user->password = $password;
$user->forceSave();
return true;
}
}