I've installed the Sentinel laravel bundle into my project.
I've published the packages views and added several fields to the registration form. I wanted those fields to write to my users
database table.
I found the store()
method of the SentryUser
class in the SentryUser.php
file within the bundle's directories and saw the line:
$user = $this->sentry->register(array('email' => e($data['email']), 'password' => e($data['password'])));
I modified this mapping to include one of my additional fields:
$user = $this->sentry->register(array('email' => e($data['email']), 'password' => e($data['password']), 'first_name' => e($data['first_name']) ));
Which totally works.
So now that I know where the data needs to be passed in, I want to remove those changes, create a new extendedSentryUser.php
file in my app\model
directory, and extend the SentryUser
:
use Sentinel\Repo\User\SentryUser;
<?php namespace Apps\Models;
use Sentinel\Repo\User\SentryUser;
class extendedSentryUser extends SentryUser {
protected $sentry;
/**
* Construct a new SentryUser Object
*/
public function __construct(SentryUser $sentry)
{
$this->sentry = $sentry;
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store($data)
{
$result = array();
try {
//Attempt to register the user.
$user = $this->sentry->register(array('email' => e($data['email']), 'password' => e($data['password']), 'first_name' => e($data['first_name']) ));
// Add the new user to the specified default group(s).
$defaultUserGroups = Config::get('Sentinel::config.default_user_groups');
foreach ($defaultUserGroups as $groupName) {
$group = $this->sentry->getGroupProvider()->findByName($groupName);
$user->addGroup($group);
}
//success!
$result['success'] = true;
$result['message'] = trans('Sentinel::users.created');
$result['mailData']['activationCode'] = $user->GetActivationCode();
$result['mailData']['userId'] = $user->getId();
// $result['mailData']['first_name'] = e($data['first_name']);
$result['mailData']['email'] = e($data['email']);
}
catch (\Cartalyst\Sentry\Users\LoginRequiredException $e)
{
$result['success'] = false;
$result['message'] = trans('Sentinel::users.loginreq');
}
catch (\Cartalyst\Sentry\Users\UserExistsException $e)
{
$result['success'] = false;
$result['message'] = trans('Sentinel::users.exists');
}
return $result;
}
}
The thing I'm hung up on is how do I get my application to use this model instead of the existing one? Am I on the completely wrong path???