mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 03:43:07 +00:00
Some attempts at code coverage and coveralls support.
This commit is contained in:
@@ -20,15 +20,13 @@ class UserController extends BaseController
|
||||
|
||||
public function postLogin()
|
||||
{
|
||||
if (!$this->user->auth()) {
|
||||
$rememberMe = Input::get('remember_me') == '1';
|
||||
$data = [
|
||||
'email' => Input::get('email'),
|
||||
'password' => Input::get('password')
|
||||
];
|
||||
if (Auth::attempt($data, $rememberMe)) {
|
||||
return Redirect::route('index');
|
||||
}
|
||||
$rememberMe = Input::get('remember_me') == '1';
|
||||
$data = [
|
||||
'email' => Input::get('email'),
|
||||
'password' => Input::get('password')
|
||||
];
|
||||
if (Auth::attempt($data, $rememberMe)) {
|
||||
return Redirect::route('index');
|
||||
}
|
||||
Session::flash('error', 'No good!');
|
||||
return View::make('user.login');
|
||||
@@ -47,7 +45,7 @@ class UserController extends BaseController
|
||||
if (Config::get('auth.allow_register') !== true) {
|
||||
return App::abort(404);
|
||||
}
|
||||
$user = $this->user->register();
|
||||
$user = $this->user->register(Input::all());
|
||||
if ($user) {
|
||||
if (Config::get('auth.verify_mail') === true) {
|
||||
$this->email->sendVerificationMail($user);
|
||||
@@ -95,6 +93,7 @@ class UserController extends BaseController
|
||||
}
|
||||
return View::make('error')->with('message', 'Yo no hablo verification code!');
|
||||
}
|
||||
|
||||
public function reset($reset)
|
||||
{
|
||||
$user = $this->user->findByReset($reset);
|
||||
@@ -105,4 +104,4 @@ class UserController extends BaseController
|
||||
return View::make('error')->with('message', 'Yo no hablo reset code!');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -9,10 +9,10 @@ class EloquentUserRepository implements UserRepositoryInterface
|
||||
{
|
||||
}
|
||||
|
||||
public function register()
|
||||
public function register($array)
|
||||
{
|
||||
$user = new \User;
|
||||
$user->email = \Input::get('email');
|
||||
$user->email = $array['emai'];
|
||||
$user->migrated = 0;
|
||||
$user->verification = \Str::random(32);
|
||||
$user->password = \Hash::make(\Str::random(12));
|
||||
@@ -26,11 +26,11 @@ class EloquentUserRepository implements UserRepositoryInterface
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function auth()
|
||||
public function auth($array)
|
||||
{
|
||||
$user = \User::where('email', \Input::get('email'))->first();
|
||||
$user = \User::where('email', $array['email'])->first();
|
||||
if (!is_null($user)) {
|
||||
if (\Hash::check(\Input::get('password'), $user->password)) {
|
||||
if (\Hash::check($array['password'], $user->password)) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -45,6 +45,7 @@ class EloquentUserRepository implements UserRepositoryInterface
|
||||
{
|
||||
return \User::where('reset', $reset)->first();
|
||||
}
|
||||
|
||||
public function findByEmail($email)
|
||||
{
|
||||
return \User::where('email', $email)->first();
|
||||
|
@@ -6,9 +6,9 @@ namespace Firefly\Storage\User;
|
||||
|
||||
interface UserRepositoryInterface
|
||||
{
|
||||
public function register();
|
||||
public function register($array);
|
||||
|
||||
public function auth();
|
||||
public function auth($array);
|
||||
|
||||
public function findByVerification($verification);
|
||||
public function findByReset($reset);
|
||||
|
40
app/tests/controllers/UserControllerTest.php
Normal file
40
app/tests/controllers/UserControllerTest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
class UserControllerTest extends TestCase
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->mock = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
|
||||
}
|
||||
|
||||
public function mock($class)
|
||||
{
|
||||
$mock = Mockery::mock($class);
|
||||
|
||||
$this->app->instance($class, $mock);
|
||||
|
||||
return $mock;
|
||||
}
|
||||
|
||||
public function testLogin()
|
||||
{
|
||||
View::shouldReceive('make')->with('user.login');
|
||||
$this->call('GET', '/login');
|
||||
}
|
||||
|
||||
public function testPostLogin()
|
||||
{
|
||||
$data = ['email' => 'bla@bla.nl', 'password' => 'xxxx','remember_me' => '1'];
|
||||
Auth::shouldReceive('attempt')->once()->andReturn(true);
|
||||
$this->call('POST', '/login', $data);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user