Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Vokuro\Controllers;
- use Phalcon\Mvc\Controller;
- use Vokuro\Models\EmailConfirmations;
- use Vokuro\Models\ResetPasswords;
- use Vokuro\Models\Users;
- /**
- * UserControlController
- * Provides help to users to confirm their passwords or reset them
- */
- class UserControlController extends ControllerBase
- {
- public function initialize()
- {
- if ($this->session->has('auth-identity')) {
- $this->view->setTemplateBefore('private');
- }
- }
- public function indexAction()
- {
- }
- /**
- * Confirms an e-mail, if the user must change thier password then changes it
- */
- public function confirmEmailAction()
- {
- $userid = $this->dispatcher->getParam('userid');
- $key = $this->dispatcher->getParam('key');
- $user = Users::findFirstById($userid);
- if(!$userid || !$key )
- die("error");
- if($user->activated)
- die("Ovaj account je vec aktiviran");
- if($user->activationKey == $key){
- $user->active = "Y";
- $user->activated = 1;
- $user->save();
- $this->flash->success('Uspješna aktivacija profila! Ulogirajte se na vaš profil.');
- return $this->dispatcher->forward(array(
- 'controller' => 'index',
- 'action' => 'index'
- ));
- }
- else{
- $this->flash->error('Aktivacijska sifra nije tocna. Molimo kontaktirajte administratora!');
- return $this->dispatcher->forward(array(
- 'controller' => 'index',
- 'action' => 'index'
- ));
- }
- }
- public function resetPasswordAction()
- {
- $code = $this->dispatcher->getParam('code');
- $resetPassword = ResetPasswords::findFirstByCode($code);
- if (!$resetPassword) {
- return $this->dispatcher->forward(array(
- 'controller' => 'index',
- 'action' => 'index'
- ));
- }
- if ($resetPassword->reset != 'N') {
- return $this->dispatcher->forward(array(
- 'controller' => 'session',
- 'action' => 'login'
- ));
- }
- $resetPassword->reset = 'Y';
- /**
- * Change the confirmation to 'reset'
- */
- if (!$resetPassword->save()) {
- foreach ($resetPassword->getMessages() as $message) {
- $this->flash->error($message);
- }
- return $this->dispatcher->forward(array(
- 'controller' => 'index',
- 'action' => 'index'
- ));
- }
- /**
- * Identify the user in the application
- */
- $this->auth->authUserById($resetPassword->usersId);
- $this->flash->success('Please reset your password');
- return $this->dispatcher->forward(array(
- 'controller' => 'users',
- 'action' => 'changePassword'
- ));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement