public function registerAction() { try { $form = new \RegisterForm(); if ($this->request->isPost()) { $email = $this->request->getPost('email', 'email'); $password = $this->request->getPost('password'); $repeatPassword = $this->request->getPost('repeatPassword'); $user = new Users(); $user->setPassword($password, $repeatPassword); $user->email = $email; $user->created_at = new \Phalcon\Db\RawValue('now()'); $user->user_name = $this->request->getPost('name', ['string', 'striptags']); $user->nickname = $this->request->getPost('nickname', 'string'); if ($user->save() == false) { foreach ($user->getMessages() as $message) { $this->flash->error((string) $message); } } else { $this->tag->setDefault('email', ''); $this->tag->setDefault('password', ''); $this->auth->login($user->toArray()); $user->sendEmailAfterReg(); return $this->goToMain(); } } } catch (\Exception $e) { $this->flash->error($e->getMessage()); } $this->view->form = $form; }
/** * Action to register a new user */ public function indexAction() { $form = new RegisterForm(); if ($this->request->isPost()) { $name = $this->request->getPost('name', array('string', 'striptags')); $username = $this->request->getPost('username', 'alphanum'); $email = $this->request->getPost('email', 'email'); $password = $this->request->getPost('password'); $repeatPassword = $this->request->getPost('repeatPassword'); if ($password != $repeatPassword) { $this->flash->error('Passwords are different'); return false; } $user = new Users(); $user->username = $username; $user->password = sha1($password); $user->name = $name; $user->email = $email; $user->created_at = new \Phalcon\Db\RawValue('now()'); $user->active = 'Y'; if ($user->save() == false) { foreach ($user->getMessages() as $message) { $this->flash->error((string) $message); } } else { $this->tag->setDefault('email', ''); $this->tag->setDefault('password', ''); $this->flash->success('Thanks for sign-up, please log-in to start generating invoices'); return $this->forward('session/index'); } } $this->view->form = $form; }