/** * @param User $user * * @return bool */ public function save(User $user) { $newUser = false; if (!$user->exists) { $newUser = true; } if (!$user->save()) { return false; } if ($newUser) { $this->emailsSignupSvc->sendSignupWelcome($user); return $user->id; } return $user->id; }
/** * @param Translator $translator * @param UserValidator $userValidator */ public function __construct(Translator $translator, UserValidator $userValidator) { parent::__construct('adminAccountForm'); $that = $this; $userValidator->addValidationRule('email', ['name' => 'Callback', 'break_chain_on_failure' => true, 'options' => ['callback' => function ($value) use($that) { $count = User::where('email', $value); if ($that->getObject()->id) { $count = $count->where('id', '!=', $that->getObject()->id); } $count = $count->count(); return !(bool) $count; }, 'message' => $translator->translate('The email already exists')]])->setUseAsBaseFieldset(true); $this->validationRules = ['csrf' => ['required', 'error_message' => $translator->translate('The form request has expired. You must resubmit the form in order to continue.')]]; return $this->addElements([$userValidator, new Csrf('csrf')]); }
/** * @param Builder $query * @param $filters * @param $currentUserId */ public function scopeFilterByAdminGrid(Builder $query, $filters, $currentUserId) { $query->select([User::getTableName() . '.*', 'up.*'])->join(Profile::getTableName() . ' AS up', 'up.user_id', '=', User::getTableName() . '.id', 'right'); foreach ($filters as $filterKey => $filterValue) { if (empty($filterValue)) { continue; } switch ($filterKey) { case 'fname': $query->where('fname', 'LIKE', '%' . $filterValue . '%'); break; case 'email': $query->where('email', 'LIKE', '%' . $filterValue . '%'); break; } } $query->where('id', '!=', $currentUserId); }
/** * @param $userId * * @return User|\Zend\Http\Response */ private function checkIfUserExists() { $userId = $this->params('id'); /** @var User $user */ $user = User::with('profile')->find($userId); if (!$user) { $this->flashMessenger()->addErrorMessage($this->translate('Account could not be found')); return $this->redirect()->toRoute('users-admin', ['controller' => 'manage', 'action' => 'index']); } return $user; }