hi guys
I have a landing page in angular where I have 3 forms : Login, Signup and forgot password. Now all the three forms POST via $http service on a single controller but 3 different actions.
Each action does a certain common tasks like regenrating the CSRF tokens, cleansing the form data. I want to follow DRY approach and abstract away these certain task at a single place. I am pretty new to phalcon so don't know how to achieve it and where to achieve it in phalcon.
public function signUpAction() {
if ($this->request->isPost()) {
try{
$rawPost = $this->request->getJsonRawBody();
$csrfKey = $this->session->get('$PHALCON/CSRF/KEY$');
@$csrfToken = $rawPost->{$csrfKey};
if ($this->security->checkToken($csrfKey, $csrfToken)) {
/* Common Tasks START */
$result['newCsrfKey'] = $this->security->getTokenKey();
$result['newCsrfVal'] = $this->security->getToken();
$cleanPost = Security::clean_external_data($rawPost);
/* Common Tasks END */
$cleanPost['password'] = Security::get_salted_hash($cleanPost['password']);
$newUserEntity = new MoneyManagerUsers();
$saved = $newUserEntity->save($cleanPost, ['name', 'email', 'password']);
}
else
throw new Exception("CSRF ATTACK");
}
catch(Exception $e) {
echo $e->getMessage(); die;
}
}
}