/home/techb158/immovalet.com/platform/core/acl/src/Repositories/Eloquent
Edit: /home/techb158/immovalet.com/platform/core/acl/src/Repositories/Eloquent/ActivationRepository.php (3601B)
model;
$code = $this->generateActivationCode();
$activation->fill(compact('code'));
$activation->user_id = $user->getKey();
$activation->save();
$this->resetModel();
return $activation;
}
/**
* {@inheritDoc}
*/
public function exists(User $user, $code = null)
{
$expires = $this->expires();
/**
* @var Builder $activation
*/
$activation = $this
->model
->newQuery()
->where('user_id', $user->getKey())
->where('completed', false)
->where('created_at', '>', $expires);
if ($code) {
$activation->where('code', $code);
}
$this->resetModel();
return $activation->first() ?: false;
}
/**
* {@inheritDoc}
*/
public function complete(User $user, $code)
{
$expires = $this->expires();
/**
* @var Activation $activation
*/
$activation = $this
->model
->newQuery()
->where('user_id', $user->getKey())
->where('code', $code)
->where('completed', false)
->where('created_at', '>', $expires)
->first();
if ($activation === null) {
return false;
}
$activation->fill([
'completed' => true,
'completed_at' => now(),
]);
$activation->save();
$this->resetModel();
return true;
}
/**
* {@inheritDoc}
*/
public function completed(User $user)
{
$activation = $this
->model
->newQuery()
->where('user_id', $user->getKey())
->where('completed', true)
->first();
$this->resetModel();
return $activation ?: false;
}
/**
* {@inheritDoc}
* @throws Exception
*/
public function remove(User $user)
{
/**
* @var Activation $activation
*/
$activation = $this->completed($user);
if ($activation === false) {
return false;
}
$this->resetModel();
return $activation->delete();
}
/**
* {@inheritDoc}
*/
public function removeExpired()
{
$expires = $this->expires();
return $this
->model
->newQuery()
->where('completed', false)
->where('created_at', '<', $expires)
->delete();
}
/**
* Returns the expiration date.
*
* @return Carbon
*/
protected function expires()
{
return now()->subSeconds($this->expires);
}
/**
* Return a random string for an activation code.
*
* @return string
*/
protected function generateActivationCode()
{
return Str::random(32);
}
}