_getAuth()->getUser(); $form = new UserSettingsForm($user); if ($this->request->isPost()) { $data = $this->request->getPost(); if ($form->isValid($data)) { $new_pw = $form->getValue('passwordNew'); if (strlen($new_pw) > 0) { $hash = password_hash($new_pw, PASSWORD_BCRYPT); // User had a password before. just update. if (strlen($user->getPassword()) > 0) { $user->setPassword($hash); } // Else we create a password link and email. else { $link = new PasswordLink(); $link->setUserId($user->getId()) ->setPassword($hash) ->save(); $tpl = $this->di->get('template'); $body = $tpl->render('mail/password_activation', [ 'link' => $link->getPublicId() ]); $mail = new SendGridMail(); $mail->setFrom('noreply@shufflingpixels.com'); $mail->setSubject('Httpcb password activation'); $mail->addTo($user->getEmail()); $mail->addContent('text/html', $body); $sendgrid = $this->di->get('sendgrid'); $sendgrid->send($mail); $msg = "For security reasons. Before a password can be created " . "a email has been sent to {$user->getEmail()} with " . "a activation link."; $this->flash->notice($msg); } } $user->save(); $form->initialize(); $this->flash->message('success', 'Settings saved!'); } else { $this->flash->message('error', 'Could not save settings'); } } $this->view->form = $form; } /** * Activate a password. * * @param $id */ public function activationLinkAction($id) { $link = PasswordLink::findFirst(['public_id = ?0', 'bind' => [ $id ]]); if ($link) { if ($link->isValid()) { // Save the password. $link->getUser() ->setPassword($link->getPassword()) ->save(); $this->flash->success('Your password has been activated.'); } else { $this->flash->error('This link has expired or has already been used.'); } // Make sure the link is deleted. $link->delete(); } else { $this->flash->error('This does not seem to be an active link'); } } public function activityAction($page = 1) { $user = $this->_getAuth()->getUser(); $paginator = ActivityLog::getPaginationList($user->getId(), $page); $this->view->page = $paginator->getPaginate(); $this->view->pagination_url = '/user/activity/'; } }