Issue
users field, activation_key string, status int = 0 default,
activated profile will have status = 1 but it will always login even if the user is not yet activated,
If its already activated then users can login but if not yet activated put a message "please activate first'
assuming my activate method already done,
<?php
public function login()
{
if ($this->request->is('post')) {
if (Validation::email($this->request->data['username'])) {
$this->Auth->config('authenticate', [
'Form' => [
'fields' => ['username' => 'email']
]
]);
$this->Auth->constructAuthenticate();
$this->request->data['email'] = $this->request->data['username'];
unset($this->request->data['username']);
}
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__('Invalid username or password, try again'));
}
}
?>
Solution
You can check status after authentication and before setUser()
.
Example
$user = $this->Auth->identify();
if($user) {
if($user['status'] == 0) {
$this->Flash->error(__('Your account is not activated yet.please check your email.'),array('class' => 'alert alert-danger'));
} else {
$this->Auth->setUser($user);
//rest code here
}
}
Answered By - shubham715
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.