/** * Create an activation * * @param $user */ public function createActivation($user) { $this->user = $user; $token = $this->generateToken(); Activation::create(['user_id' => $this->user->id, 'token' => $token, 'created_at' => new Carbon()]); $this->sendEmail($token, 'send'); }
/** @test */ public function aRegisteredUserCanRequestNewToken() { $this->visit('register')->type('sam', 'name')->type('*****@*****.**', 'email')->type('password', 'password')->type('password', 'password_confirmation')->press('Register'); // user is registered but not active $this->see("Almost done. Please, activate your account. I've sent an activation code to your email. It will expire in 24 hours.")->seeInDatabase('users', ['name' => 'sam', 'active' => 0]); $this->visit('activation/resend')->type('*****@*****.**', 'email')->type('password', 'password')->press('Send')->see('Please, activate your account'); // get the user from DB $user = $this->getUser(); // get the activation from DB $activation = Activation::where('user_id', $user->id)->first(); // user must have a 64 char token $this->assertTrue(strlen($activation->token) === 64); // activate the user $this->visit("activate/{$activation->token}")->see('Welcome')->seeInDatabase('users', ['name' => 'sam', 'active' => 1]); // activation record does not exist anymore $activation = Activation::where('user_id', $user->id)->first(); $this->assertTrue($activation === null); }