Esempio n. 1
0
 public function registerForm($request)
 {
     if (isset($_POST['XSRF'])) {
         if (\Kingboard\Lib\Form::getXSRFToken() == $_POST['XSRF']) {
             if (!isset($_POST['passwd']) || !isset($_POST['passwd2']) || !isset($_POST['login'])) {
                 $this->_context['registration_failed'] = 'Please fill in all fields';
             } elseif ($_POST['passwd'] != $_POST['passwd2']) {
                 $this->_context['registration_failed'] = 'both Password fields need to have the same value';
             } elseif (!is_null(\Kingboard\Model\User::findOne(array('username' => $_POST['login'])))) {
                 $this->_context['registration_failed'] = 'email/login allready in use';
             } elseif (!\Kingboard\Lib\Form::isEmail($_POST['login'])) {
                 $this->_context['registration_failed'] = 'not a valid email adresse';
             } else {
                 $validationCode = sha1(time() . $_POST['login']);
                 $user = new \Kingboard\Model\User();
                 $user->username = $_POST['login'];
                 $user->password = hash('sha256', $_POST['passwd']);
                 $user->status = \Kingboard\Model\User::STATUS_NEW;
                 $user->validationCode = $validationCode;
                 $user->save();
                 $body = file_get_contents(APP_PATH . '/templates/mails/verify_email.html');
                 $body = strtr($body, array("{{username}}" => $_POST['login'], "{{hostname}}" => \King23\Core\Registry::getInstance()->baseHost, "{{activationkey}}" => $validationCode));
                 $headers = "From: " . \King23\Core\Registry::getInstance()->sendFromEmail . "\r\n";
                 $headers .= "Reply-To: " . \King23\Core\Registry::getInstance()->sendFromEmail . "\r\n";
                 $headers .= "X-Mailer: PHP/" . phpversion();
                 mail($_POST['login'], "Kingboard Activation", $body, $headers);
                 $this->redirect('/');
             }
         } else {
             $this->_context['registration_failed'] = 'XSRF Token Invalid.';
         }
     }
     return $this->render('user/registration.html', $_POST);
 }
Esempio n. 2
0
 /**
  * Execute a Login for $username with $password
  * @static
  * @param string $username
  * @param string $password
  * @return \Kingboard\Model\User
  */
 public static function login($username, $password)
 {
     $user = \Kingboard\Model\User::findOneByUsernameAndPassword($username, $password);
     if ($user) {
         $_SESSION["Kingboard_Auth"] = array("User" => $user);
     }
     return $user;
 }
Esempio n. 3
0
 /**
  * execute the login
  * @static
  * @param array $config this providers config array from the registry
  * @return \Kingboard\Model\User
  */
 public static function login($config, $fake)
 {
     if (isset($_GET['error'])) {
         throw new \Exception("Could not login: "******"Error: could not access tokens");
     }
     $userinfo = json_decode(file_get_contents("https://graph.facebook.com/me?access_token=" . $tokens['access_token']));
     if (is_null($userinfo)) {
         throw new \Exception("Error: could not access userinfo");
     }
     $user = \Kingboard\Model\User::findOne(array("username" => $userinfo->email));
     if (is_null($user)) {
         $user = new \Kingboard\Model\User();
         $user->username = $userinfo->email;
         $user->save();
     }
     $_SESSION["Kingboard_Auth"] = array("User" => $user);
     return $user;
 }
Esempio n. 4
0
 /**
  * Login the current user
  * @static
  * @param string $username
  * @param string $password
  * @return bool|\Kingboard\Model\User
  */
 public static function login($username, $password)
 {
     try {
         $reg = \King23\Core\Registry::getInstance();
         $host = $reg->authJabberHost;
         $port = $reg->authJabberPort;
         $domain = !is_null($reg->authJabberDomain) ? $reg->authJabberDomain : $reg->authJabberHost;
         $xmpphp = \Wrapper\XMPPHP\XMPPHPWrapper::getXMPPHP($host, $port, $username, $password, "Kingboard", $domain);
         $xmpphp->connect();
         $xmpphp->processUntil('session_start');
         $xmpphp->disconnect();
         if (!($user = \Kingboard\Model\User::findOne(array('username' => $username)))) {
             $user = new \Kingboard\Model\User();
             $user->username = $username;
             $user->save();
         }
         $_SESSION["Kingboard_Auth"] = array("User" => $user);
         return $_SESSION["Kingboard_Auth"]["User"];
     } catch (\Exception $e) {
         // just skip the error, we'll return false
     }
     return false;
 }
Esempio n. 5
0
 /**
  * import mails from ccp's API.
  * @param array $options
  */
 public function api_import(array $options)
 {
     $log = Registry::getInstance()->getLogger();
     $log->info("api import running");
     foreach (User::findWithApiKeys() as $user) {
         /** @var User $user */
         foreach ($user['keys'] as $keyid => $key) {
             // skip inactive keys
             if (!$key['active']) {
                 continue;
             }
             try {
                 $stats = EveApi::fetch($key);
                 $log->info("processed key {$keyid} for user " . $user->name . " : " . $stats['old'] . ' known / ' . $stats['new'] . " new");
             } catch (\Exception $e) {
                 // we caught a pheal exception, we should implement proper handling of errors here
                 $log->warning("key {$keyid} caused pheal exception: " . $e->getMessage());
             }
         }
     }
 }