コード例 #1
0
 function index(Request $request, Application $app)
 {
     $form = $app['form.factory']->create(new NewSiteForm());
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         $data = $form->getData();
         $siteRepository = new SiteRepository();
         $site = $siteRepository->loadBySlug($data['slug']);
         if ($site) {
             $form->addError(new FormError('That address is already taken'));
         }
         if ($form->isValid()) {
             $userRepo = new UserAccountRepository();
             $user = $userRepo->loadByEmail($data['email']);
             if ($user) {
                 $data = $form->getData();
                 $site = new SiteModel();
                 $site->setSlug($data['slug']);
                 $site->setTitle($data['title']);
                 if ($data['read'] == 'public') {
                     $site->setIsListedInIndex(true);
                     $site->setIsWebRobotsAllowed(true);
                 } else {
                     $site->setIsListedInIndex(false);
                     $site->setIsWebRobotsAllowed(false);
                 }
                 if ($data['write'] == 'public') {
                     $site->setIsAllUsersEditors(true);
                     $site->setIsRequestAccessAllowed(false);
                 } else {
                     $site->setIsAllUsersEditors(false);
                     $site->setIsRequestAccessAllowed(true);
                 }
                 $site->setIsFeatureCuratedList($app['config']->newSiteHasFeatureCuratedList);
                 $site->setIsFeatureImporter($app['config']->newSiteHasFeatureImporter);
                 $site->setIsFeatureMap($app['config']->newSiteHasFeatureMap);
                 $site->setIsFeatureVirtualEvents($app['config']->newSiteHasFeatureVirtualEvents);
                 $site->setIsFeaturePhysicalEvents($app['config']->newSiteHasFeaturePhysicalEvents);
                 $site->setIsFeatureGroup($app['config']->newSiteHasFeatureGroup);
                 $site->setPromptEmailsDaysInAdvance($app['config']->newSitePromptEmailsDaysInAdvance);
                 $site->setIsFeatureTag($app['config']->newSiteHasFeatureTag);
                 $countryRepository = new CountryRepository();
                 $siteQuotaRepository = new SiteQuotaRepository();
                 $siteRepository->create($site, $user, array($countryRepository->loadByTwoCharCode("GB")), $siteQuotaRepository->loadByCode($app['config']->newSiteHasQuotaCode));
                 return $app->redirect("/sysadmin/site/" . $site->getId());
             } else {
                 $app['flashmessages']->addError('Existing user not found!');
             }
         }
     }
     return $app['twig']->render('sysadmin/sitenew/index.html.twig', array('form' => $form->createView()));
 }
コード例 #2
0
 function test1()
 {
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $this->checkUserInTest1($userRepo->loadByID($user->getId()));
     $this->checkUserInTest1($userRepo->loadByUserName("test"));
     $this->checkUserInTest1($userRepo->loadByEmail("*****@*****.**"));
     $this->checkUserInTest1($userRepo->loadByUserNameOrEmail("test"));
     $this->checkUserInTest1($userRepo->loadByUserNameOrEmail("*****@*****.**"));
 }
コード例 #3
0
 function index(Request $request, Application $app)
 {
     $form = $app['form.factory']->create(new NewAPI2ApplicationForm());
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         if ($form->isValid()) {
             $data = $form->getData();
             $userRepo = new UserAccountRepository();
             $user = $userRepo->loadByEmail($data['email']);
             if ($user) {
                 $appRepo = new API2ApplicationRepository();
                 $apiapp = $appRepo->create($user, $data['title']);
                 return $app->redirect("/sysadmin/api2app/" . $apiapp->getId());
             } else {
                 $app['flashmessages']->addError('Existing user not found!');
             }
         }
     }
     $rb = new API2ApplicationRepositoryBuilder();
     $apps = $rb->fetchAll();
     return $app['twig']->render('sysadmin/api2applist/index.html.twig', array('api2apps' => $apps, 'form' => $form->createView()));
 }
コード例 #4
0
 public function setFromJSON($json)
 {
     if (isset($json->event)) {
         if (isset($json->event->summary)) {
             $this->summary = $json->event->summary;
         }
         if (isset($json->event->description)) {
             $this->description = $json->event->description;
         }
         if (isset($json->event->url)) {
             $this->url = $json->event->url;
         }
         $timezone = new \DateTimeZone($this->timezone);
         if (isset($json->event->start->str)) {
             $this->start_at = new \DateTime($json->event->start->str, $timezone);
         }
         if (isset($json->event->end->str)) {
             $this->end_at = new \DateTime($json->event->end->str, $timezone);
         }
         if (isset($json->event->country) && isset($json->event->country->code) && $json->event->country->code) {
             $countryRepo = new CountryRepository();
             // Delibrately setting NULL on failure so user gets an error message.
             $this->country = $countryRepo->loadByTwoCharCode($json->event->country->code);
             // TODO check allowed in this site
         }
         if (isset($json->event->timezone)) {
             // Delibrately setting NULL on failure so user gets an error message.
             $this->timezone = $this->country && in_array($json->event->timezone, $this->country->getTimezonesAsList()) ? $json->event->timezone : null;
         }
     }
     if (isset($json->site)) {
         $siteRepo = new SiteRepository();
         if (isset($json->site->id)) {
             $this->site = $siteRepo->loadById($json->site->id);
         }
         if (isset($json->site->slug)) {
             $this->site = $siteRepo->loadBySlug($json->site->slug);
         }
     }
     if (isset($json->user)) {
         $userRepo = new UserAccountRepository();
         if (isset($json->user->email)) {
             $this->user = $userRepo->loadByEmail($json->user->email);
         } else {
             if (isset($json->user->username)) {
                 $this->user = $userRepo->loadByUserName($json->user->username);
             }
         }
     }
     if (isset($json->group)) {
         $groupRepo = new GroupRepository();
         if (isset($json->group->slug) && $this->site) {
             $this->group = $groupRepo->loadBySlug($this->site, $json->group->slug);
         } else {
             if (isset($json->group->id)) {
                 $this->group = $groupRepo->loadById($json->group->id);
             }
         }
     }
 }
コード例 #5
0
$makeSysAdmin = in_array("sysadmin", $extraFlags);
if (!$username || !$email || !$password) {
    die("Username and Email and Password?\n\n");
}
print "Username: "******"\n";
print "Email: " . $email . "\n";
print "Password: "******"\n";
print "Sys Admin: " . ($makeSysAdmin ? "yes" : "no") . "\n";
sleep(10);
print "Starting ...\n";
$userRepository = new UserAccountRepository();
if (is_array($CONFIG->userNameReserved) && in_array($username, $CONFIG->userNameReserved)) {
    die("That user name is reserved\n");
}
$userExistingUserName = $userRepository->loadByUserName($username);
if ($userExistingUserName) {
    die("That user name is already taken\n");
}
$userExistingEmail = $userRepository->loadByEmail($email);
if ($userExistingEmail) {
    die("That email address already has an account\n");
}
$user = new UserAccountModel();
$user->setEmail($email);
$user->setUsername($username);
$user->setPassword($password);
$userRepository->create($user);
if ($makeSysAdmin) {
    $userRepository->makeSysAdmin($user, null);
}
print "Done!\n";
コード例 #6
0
 function forgot(Request $request, Application $app)
 {
     $form = $app['form.factory']->create(new ForgotUserForm());
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         if ($form->isValid()) {
             $data = $form->getData();
             $userRepository = new UserAccountRepository();
             if ($data['email']) {
                 $user = $userRepository->loadByEmail($data['email']);
             } else {
                 if ($data['username']) {
                     $user = $userRepository->loadByUserName($data['username']);
                 }
             }
             if ($user) {
                 if ($user->getIsClosedBySysAdmin()) {
                     $form->addError(new FormError('There was a problem with this account and it has been closed: ' . $user->getClosedBySysAdminReason()));
                 } else {
                     $aurr = new UserAccountResetRepository();
                     $uarLast = $aurr->loadRecentlyUnusedSentForUserAccountId($user->getId(), $app['config']->resetEmailsGapBetweenInSeconds);
                     if ($uarLast) {
                         $form->addError(new FormError('An email was sent recently; please try again soon'));
                     } else {
                         $uar = $aurr->create($user);
                         $uar->sendEmail($app, $user);
                         return $app['twig']->render('index/user/forgotDone.html.twig', array());
                     }
                 }
             } else {
                 $form->addError(new FormError('User not known'));
             }
         }
     }
     return $app['twig']->render('index/user/forgot.html.twig', array('form' => $form->createView()));
 }
コード例 #7
0
 function login(Request $request, Application $app)
 {
     if (!$app['apiApp']) {
         return $app['twig']->render('indexapi2/index/login.app.problem.html.twig', array());
     }
     $appRequestTokenRepo = new API2ApplicationRequestTokenRepository();
     $userAuthorisationTokenRepo = new API2ApplicationUserAuthorisationTokenRepository();
     $userInApp2Repo = new UserInAPI2ApplicationRepository();
     ######################################## Check Data In
     // Load and check request token!
     $data = array();
     if ($app['websession']->has('api2requestToken')) {
         $data['request_token'] = $app['websession']->get('api2requestToken');
     }
     $data = array_merge($data, $_GET, $_POST);
     $requestToken = $data['request_token'] ? $appRequestTokenRepo->loadByAppAndRequestToken($app['apiApp'], $data['request_token']) : null;
     if (!$requestToken || $requestToken->getIsUsed()) {
         return $app['twig']->render('indexapi2/index/login.requestToken.problem.html.twig', array());
     }
     $userAuthorisationToken = null;
     $permissionsGranted = new API2ApplicationUserPermissionsModel();
     $app['websession']->set('api2appToken', $app['apiApp']->getAppToken());
     $app['websession']->set('api2requestToken', $requestToken->getRequestToken());
     ######################################## User Workflow
     $formObj = new LogInUserForm($app['currentUser'], $app['apiApp'], $requestToken);
     $form = $app['form.factory']->create($formObj);
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         if ($form->isValid()) {
             $formData = $form->getData();
             $userRepository = new UserAccountRepository();
             if ($formData['email']) {
                 $user = $userRepository->loadByEmail($formData['email']);
             } else {
                 if ($formData['username']) {
                     $user = $userRepository->loadByUserName($formData['username']);
                 }
             }
             if ($user) {
                 if ($user->checkPassword($formData['password'])) {
                     if ($app['apiApp']->getIsAutoApprove()) {
                         $permissionsGranted->setFromApp($app['apiApp']);
                     } else {
                         $permissionsGranted->setFromData($formData);
                     }
                     $userInApp2Repo->setPermissionsForUserInApp($permissionsGranted, $user, $app['apiApp']);
                     $userAuthorisationToken = $userAuthorisationTokenRepo->createForAppAndUserFromRequestToken($app['apiApp'], $user, $requestToken);
                 } else {
                     $app['monolog']->addError("Login attempt on API2 - account " . $user->getId() . ' - password wrong.');
                     $form->addError(new FormError('User and password not recognised'));
                 }
             } else {
                 $app['monolog']->addError("Login attempt on API2 - unknown account");
                 $form->addError(new FormError('User and password not recognised'));
             }
         }
     }
     if (!$userAuthorisationToken) {
         return $app['twig']->render('indexapi2/index/login.html.twig', array('form' => $form->createView(), 'api2app' => $app['apiApp'], 'askForPermissionEditor' => $formObj->getIsEditor()));
     }
     ###################################### Return
     if ($requestToken->getCallbackUrl()) {
         if ($userAuthorisationToken) {
             return $app->redirect($requestToken->getCallbackUrlWithParams(array('authorisation_token' => $userAuthorisationToken->getAuthorisationToken(), 'state' => $requestToken->getStateFromUser())));
         } else {
             return $app->redirect($requestToken->getCallbackUrlWithParams(array('status' => 'failure')));
         }
     } else {
         if ($requestToken->getIsCallbackJavascript()) {
             if ($userAuthorisationToken) {
                 return $app['twig']->render('indexapi2/index/login.callback.javascript.success.html.twig', array('authorisationToken' => $userAuthorisationToken->getAuthorisationToken(), 'state' => $requestToken->getStateFromUser()));
             } else {
                 return $app['twig']->render('indexapi2/index/login.callback.javascript.failure.html.twig', array());
             }
         } else {
             if ($requestToken->getIsCallbackDisplay()) {
                 if ($userAuthorisationToken) {
                     return $app['twig']->render('indexapi2/index/login.callback.display.success.html.twig', array('authorisationToken' => $userAuthorisationToken->getAuthorisationToken()));
                 } else {
                     return $app['twig']->render('indexapi2/index/login.callback.display.failure.html.twig', array());
                 }
             } else {
                 return "No Callback was given!";
             }
         }
     }
     return "???";
 }