firefly-iii/app/lib/FireflyIII/Database/User.php

57 lines
1.1 KiB
PHP

<?php
namespace FireflyIII\Database;
/**
* Class User
* @package FireflyIII\Database
*/
class User
{
/**
* @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 $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();
}
}