/** * (non-PHPdoc) * @see \Api\Model\Mapper\MapperModel::databaseName() */ public function databaseName() { CodeGuard::checkEmptyAndThrow($this->projectCode, 'projectCode'); $name = strtolower($this->projectCode); $name = str_replace(' ', '_', $name); return 'sf_' . $name; }
public static function updateReply($projectId, $userId, $website, $commentId, $params) { CodeGuard::checkTypeAndThrow($params, 'array'); CodeGuard::checkEmptyAndThrow($commentId, 'commentId in updateReply()'); $project = new LexiconProjectModel($projectId); $comment = new LexCommentModel($project, $commentId); $rightsHelper = new RightsHelper($userId, $project, $website); $replyId = $params['id']; if (array_key_exists('id', $params) && $replyId != '') { $reply = $comment->getReply($replyId); if ($reply->authorInfo->createdByUserRef->asString() != $userId && !$rightsHelper->userHasProjectRight(Domain::COMMENTS + Operation::EDIT)) { throw new \Exception("No permission to update other people's lex comment replies!"); } if ($reply->content != $params['content']) { $reply->authorInfo->modifiedDate = new \DateTime(); } $reply->content = $params['content']; $comment->setReply($replyId, $reply); } else { $reply = new LexCommentReply(); $reply->content = $params['content']; $reply->authorInfo->createdByUserRef->id = $userId; $reply->authorInfo->modifiedByUserRef->id = $userId; $reply->authorInfo->createdDate = new \DateTime(); $comment->replies->append($reply); $replyId = $reply->id; } $comment->write(); return $replyId; }
/** * Activate a user on the specified site and validate email if it was empty, otherwise login * @param string $username * @param string $password * @param string $email * @param Website $website * @param Application $app * @param DeliveryInterface $delivery * @return string|boolean $userId|false otherwise */ public static function activate($username, $password, $email, $website, $app, DeliveryInterface $delivery = null) { CodeGuard::checkEmptyAndThrow($username, 'username'); CodeGuard::checkEmptyAndThrow($password, 'password'); CodeGuard::checkEmptyAndThrow($email, 'email'); CodeGuard::checkNullAndThrow($website, 'website'); $identityCheck = self::checkIdentity($username, $email, $website); if ($website->allowSignupFromOtherSites && $identityCheck->usernameExists && !$identityCheck->usernameExistsOnThisSite && ($identityCheck->emailIsEmpty || $identityCheck->emailMatchesAccount)) { $user = new PasswordModel(); if ($user->readByProperty('username', $username)) { if ($user->verifyPassword($password)) { $user = new UserModel($user->id->asString()); $user->siteRole[$website->domain] = $website->userDefaultSiteRole; if ($identityCheck->emailIsEmpty) { $user->emailPending = $email; } $user->write(); // if website has a default project then add them to that project $project = ProjectModel::getDefaultProject($website); $url = '/app'; if ($project) { $project->addUser($user->id->asString(), ProjectRoles::CONTRIBUTOR); $user->addProject($project->id->asString()); $project->write(); $user->write(); $url = '/app/' . $project->appName . '/' . $project->id->asString(); } if ($identityCheck->emailIsEmpty) { Communicate::sendSignup($user, $website, $delivery); } if ($identityCheck->emailMatchesAccount) { Auth::login($app, $username, $password); return Auth::result(Auth::LOGIN_SUCCESS, $url, 'location'); } return Auth::result(Auth::LOGIN_FAIL_USER_UNAUTHORIZED, '', 'location'); } } } return false; }