Skip to content

Commit

Permalink
Check if customer is activated before login
Browse files Browse the repository at this point in the history
  • Loading branch information
sampoyigi committed Dec 28, 2018
1 parent 81e18d3 commit 934b4b0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 14 additions & 0 deletions app/admin/models/Customers_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Carbon\Carbon;
use DB;
use Exception;
use Igniter\Flame\ActivityLog\Traits\LogsActivity;
use Igniter\Flame\Auth\Models\User as AuthUserModel;
use Igniter\Flame\Database\Traits\Purgeable;
Expand Down Expand Up @@ -98,6 +99,19 @@ public function scopeIsEnabled($query)
// Events
//

public function beforeLogin()
{
if (!$this->group OR !$this->group->requiresApproval())
return;

if ($this->is_activated OR $this->status)
return;

throw new Exception(sprintf(
'Cannot login user "%s" until activated.', $this->email
));
}

public function afterCreate()
{
$this->saveCustomerGuestOrder();
Expand Down
7 changes: 6 additions & 1 deletion app/main/classes/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,20 @@ public function getGroupId()
*
* @param array $credentials
*
* @param bool $activate
* @return \Admin\Models\Customers_model
* @throws \Exception
*/
public function register(array $credentials)
public function register(array $credentials, $activate = FALSE)
{
$model = $this->createModel();
$model->fill($credentials);
$model->save();

if ($activate) {
$model->completeActivation($model->getActivationCode());
}

// Prevents subsequent saves to this model object
$model->password = null;

Expand Down

0 comments on commit 934b4b0

Please sign in to comment.