Skip to content

Commit

Permalink
Users, return user after sign up
Browse files Browse the repository at this point in the history
  • Loading branch information
mruz committed Jul 3, 2014
1 parent 8f6f1a1 commit 9e8c774
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 33 deletions.
4 changes: 2 additions & 2 deletions app/common/models/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@ public function signup()

if ($email->Send() === true) {
unset($_POST);
return true;
return $this;
} else {
\Baseapp\Bootstrap::log($email->ErrorInfo);
return false;
}
} else {
\Baseapp\Bootstrap::log($this->getMessages());
return $this->getMessages();
return false;
}
}
}
Expand Down
42 changes: 11 additions & 31 deletions app/frontend/controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Baseapp\Frontend\Controllers;

use Baseapp\Library\Auth;
use Baseapp\Models\Users;

/**
Expand All @@ -23,18 +22,14 @@ class UserController extends IndexController
*/
public function indexAction()
{
//$this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_NO_RENDER);
if ($this->auth->logged_in()) {

} else {
$this->view->pick('msg');
$this->tag->setTitle(__('No access'));
$this->view->setVar('title', __('No access'));
$this->view->setVar('redirect', 'user/signin');
$this->flashSession->error(
$this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) .
'<strong>' . __('Error') . '!</strong> ' .
__("Please log in to access."));
$this->flashSession->error($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Error') . '!</strong> ' . __("Please log in to access."));
}
}

Expand All @@ -48,19 +43,18 @@ public function signinAction()
{
if ($this->request->hasPost('submit_signin') && $this->request->hasPost('username') && $this->request->hasPost('password')) {
$login = $this->auth->login($this->request->getPost('username'), $this->request->getPost('password'), $this->request->getPost('rememberMe') ? TRUE : FALSE);

if (!$login) {
$errors = new \Phalcon\Validation\Message\Group();

if ($login === NULL) {
$errors->appendMessage(new \Phalcon\Validation\Message(__('Field :field is incorrect', array(':field' => __('Username'))), 'username', 'Incorrect'));
} else {
$errors->appendMessage(new \Phalcon\Validation\Message(__('Field :field is incorrect', array(':field' => __('Password'))), 'password', 'Incorrect'));
}

$this->view->setVar('errors', $errors);
$this->flashSession->warning(
$this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) .
'<strong>' . __('Warning') . '!</strong> ' .
__("Please correct the errors."));
$this->flashSession->warning($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Warning') . '!</strong> ' . __("Please correct the errors."));
} else {
$referer = $this->request->getHTTPReferer();
$needBackRedirect = !empty($referer) && strpos(parse_url($referer, PHP_URL_PATH), '/user/signin') !== 0 && parse_url($referer, PHP_URL_HOST) == $this->request->getHttpHost();
Expand All @@ -86,17 +80,11 @@ public function signupAction()
$user = new Users();
$signup = $user->signup();

if ($signup === TRUE) {
$this->flashSession->notice(
$this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) .
'<strong>' . __('Success') . '!</strong> ' .
__("Check Email to activate your account."));
if ($signup instanceof Users) {
$this->flashSession->notice($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Success') . '!</strong> ' . __("Check Email to activate your account."));
} else {
$this->view->setVar('errors', $signup);
$this->flashSession->warning(
$this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) .
'<strong>' . __('Warning') . '!</strong> ' .
__("Please correct the errors."));
$this->flashSession->warning($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Warning') . '!</strong> ' . __("Please correct the errors."));
}
}
}
Expand Down Expand Up @@ -132,23 +120,15 @@ public function activationAction()
$activation = $user->activation();

if ($activation === NULL) {
$this->flashSession->notice(
$this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) .
'<strong>' . __('Notice') . '!</strong> ' .
__("Activation has already been completed."));
$this->flashSession->notice($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Notice') . '!</strong> ' . __("Activation has already been completed."));
} elseif ($activation === TRUE) {
$this->flashSession->success(
$this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) .
'<strong>' . __('Success') . '!</strong> ' .
__("Activation completed. Please log in."));
$this->flashSession->success($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Success') . '!</strong> ' . __("Activation completed. Please log in."));

// Redirect to sign in
$this->view->setVar('redirect', 'user/signin');
}
} else {
$this->flashSession->error(
$this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) .
'<strong>' . __('Error') . '!</strong> ' .
__("Activation cannot be completed. Invalid username or hash."));
$this->flashSession->error($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Error') . '!</strong> ' . __("Activation cannot be completed. Invalid username or hash."));
}
}

Expand Down

0 comments on commit 9e8c774

Please sign in to comment.