Check marking before create user

This commit is contained in:
Too
2018-06-20 15:43:04 +08:00
parent b1843c0b9b
commit a2dad37758
3 changed files with 31 additions and 1 deletions
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Auth;
use App\User;
use App\Role;
use App\Marking;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
@@ -58,6 +59,11 @@ class RegisterController extends Controller
*/
protected function create(array $data)
{
$marking = Marking::Where('email',$data['email'])->first();
if($marking->marking = $data['marking']){
redirect('/');
}
$role = Role::where('name','=','member')->first();
$user = new User();
$user->name = $data['name'];
+10
View File
@@ -0,0 +1,10 @@
<?php
use Faker\Generator as Faker;
$factory->define(App\Marking::class, function (Faker $faker) {
return [
'email' => $faker->unique()->safeEmail,
'marking' => str_random(10)
];
});
+15 -1
View File
@@ -3,17 +3,31 @@
namespace Tests\Feature;
use Tests\TestCase;
use App\Marking;
use Artisan;
class RegisterTest extends TestCase
{
protected $marking;
public function setUp(){
parent::setUp();
Artisan::call('db:seed');
$this->marking = factory(Marking::class)->create();
}
/** @test */
public function can_register()
{
$response =
$this->postJson('/api/register', [
'name' => 'Test User',
'email' => 'test@test.app',
'email' => $this->marking->email,
'password' => 'secret',
'password_confirmation' => 'secret',
'marking' => $this->marking->marking
])
->assertSuccessful()
->assertJsonStructure(['id', 'name', 'email']);