I want when i use $users->save($this->request->getPost(), $form), to store the token that come from the form to be stored into the another model Sessions
So, how can achieved that?
Here is what i'm doing in the controller:
public function signUpAction()
{
if (!empty($this->isAuth())) {
$this->redirect(IndexEnom::HOME_URL);
}
$form = new SignUpForm();
if ($this->request->isPost()) {
$users = new Users();
if ($users->save($this->request->getPost(), $form)) {
$this->saveUserData($this->request->getPost('email'), $this->request->getPost('password'));
$this->authAction();
}
foreach ($users->getMessages() as $message) {
$this->flashSession->error($message->getMessage());
}
}
$this->view->pick("index/signup");
$this->view->form = $form;
}
User model:
namespace Modules\Engine\Models;
use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Validator\Email as EmailValidator;
use Phalcon\Mvc\Model\Validator\Uniqueness;
use Modules\Engine\Models\Validators\PasswordValidator;
class Users extends Model
{
public $id;
public $email;
public $password;
public $username;
public $type;
public $token;
public function validation()
{
$this->validate(new PasswordValidator(
array(
"field" => "password"
)
));
$this->validate(new EmailValidator(
array(
"field" => "email",
"message" => "Email is not valid!"
)
));
$this->validate(new Uniqueness(
array(
"field" => "email",
"message" => "Type another email!"
)
));
return true !== $this->validationHasFailed();
}
public function getId()
{
return $this->id;
}
public function getEmail()
{
return $this->email;
}
public function getPassword()
{
return $this->password;
}
public function getUsername()
{
return $this->username;
}
public function getType()
{
return $this->type;
}
public function setId($id)
{
$this->id = $id;
}
public function setEmail($email)
{
$this->email = $email;
}
public function setPassword($password)
{
$this->password = $this->getDi()->getSecurity()->hash($password);
}
public function setUsername($username)
{
$this->username = $username;
}
public function setType($type)
{
$this->type = $type;
}
public function getToken()
{
return $this->token;
}
public function setToken($token)
{
$this->token = $this->getDi()->getSecurity()->hash($token);
}
}
Sessions model:
namespace Modules\Engine\Models;
use Phalcon\Mvc\Model;
class Sessions extends Model
{
public $id;
public $auth_token;
public $activity;
public function getId()
{
return $this->id;
}
public function getAuth_token()
{
return $this->auth_token;
}
public function getActivity()
{
return $this->activity;
}
public function setId($id)
{
$this->id = $id;
}
public function setAuthToken($auth_token)
{
$this->auth_token = $this->getDi()->getSecurity()->hash($auth_token);
}
public function setActivity()
{
$this->activity = time();
}
}