/** * Create user * * @param array $data */ private function createUser($data) { if (!isset($data['email'])) { RestoLogUtil::httpError(400, 'Email is not set'); } if ($this->context->dbDriver->check(RestoDatabaseDriver::USER, array('email' => $data['email']))) { RestoLogUtil::httpError(3000); } $redirect = isset($data['activateUrl']) ? '&redirect=' . rawurlencode($data['activateUrl']) : ''; $userInfo = $this->context->dbDriver->store(RestoDatabaseDriver::USER_PROFILE, array('profile' => array('email' => $data['email'], 'password' => isset($data['password']) ? $data['password'] : null, 'username' => isset($data['username']) ? $data['username'] : null, 'givenname' => isset($data['givenname']) ? $data['givenname'] : null, 'lastname' => isset($data['lastname']) ? $data['lastname'] : null, 'country' => isset($data['country']) ? $data['country'] : null, 'organization' => isset($data['organization']) ? $data['organization'] : null, 'flags' => isset($data['flags']) ? $data['flags'] : null, 'topics' => isset($data['topics']) ? $data['topics'] : null, 'activated' => 0))); if (isset($userInfo)) { $activationLink = $this->context->baseUrl . '/api/user/activate?email=' . rawurlencode($data['email']) . '&act=' . $userInfo['activationcode'] . $redirect; $fallbackLanguage = isset($this->context->mail['accountActivation'][$this->context->dictionary->language]) ? $this->context->dictionary->language : 'en'; if (!RestoUtil::sendMail(array('to' => $data['email'], 'senderName' => $this->context->mail['senderName'], 'senderEmail' => $this->context->mail['senderEmail'], 'subject' => $this->context->dictionary->translate($this->context->mail['accountActivation'][$fallbackLanguage]['subject'], $this->context->title), 'message' => $this->context->dictionary->translate($this->context->mail['accountActivation'][$fallbackLanguage]['message'], $this->context->title, $activationLink)))) { RestoLogUtil::httpError(3001); } } else { RestoLogUtil::httpError(500, 'Database connection error'); } return RestoLogUtil::success('User ' . $data['email'] . ' created'); }
/** * Send reset password link to user email adress * */ public function sendResetPasswordLink() { /* * Only existing local user can change there password */ if (!$this->context->dbDriver->check(RestoDatabaseDriver::USER, array('email' => $this->profile['email'])) || $this->context->dbDriver->get(RestoDatabaseDriver::USER_PASSWORD, array('email' => $this->profile['email'])) === str_repeat('*', 40)) { RestoLogUtil::httpError(3005); } /* * Send email with reset link */ $shared = $this->context->dbDriver->get(RestoDatabaseDriver::SHARED_LINK, array('email' => $this->profile['email'], 'resourceUrl' => $this->context->resetPasswordUrl . '/' . base64_encode($this->profile['email']), 'duration' => isset($this->context->sharedLinkDuration) ? $this->context->sharedLinkDuration : null)); $fallbackLanguage = isset($this->context->mail['resetPassword'][$this->context->dictionary->language]) ? $this->context->dictionary->language : 'en'; if (!RestoUtil::sendMail(array('to' => $this->profile['email'], 'senderName' => $this->context->mail['senderName'], 'senderEmail' => $this->context->mail['senderEmail'], 'subject' => $this->context->dictionary->translate($this->context->mail['resetPassword'][$fallbackLanguage]['subject'], $this->context->title), 'message' => $this->context->dictionary->translate($this->context->mail['resetPassword'][$fallbackLanguage]['message'], $this->context->title, $shared['resourceUrl'] . '?_tk=' . $shared['token'])))) { RestoLogUtil::httpError(3003); } return RestoLogUtil::success('Reset link sent to ' . $this->profile['email']); }