Exemple #1
0
 /**
  * @covers Xoops\Form\Token::__construct
  * @covers Xoops\Form\Token::render
  */
 public function test__construct()
 {
     // '<input hidden type="hidden" name="XOOPS_TOKEN_REQUEST" value="'
     $oldWay = new Token();
     $newWay = new Token([]);
     $this->assertEquals(substr($oldWay->render(), 0, 62), substr($newWay->render(), 0, 62));
 }
Exemple #2
0
 /**
  * Verificação da Precedência
  * @param Token $tokenA Token para Verificação
  * @param Token $tokenB Token para Verificação
  * @throws Exception Token de Tipo Não Operador
  * @return int Comparação de Precedências dos Tokens
  */
 public function precedence($tokenA, $tokenB)
 {
     /* @todo Checar Precedência */
     $precedenceA = $this->_mapper[$tokenA->getContent()];
     $precedenceB = $this->_mapper[$tokenB->getContent()];
     return $precedenceA - $precedenceB;
 }
 /**
  * @param int $userId
  * @param string $token
  * @return Token
  */
 public static function createToken($userId, $token)
 {
     $newToken = new Token();
     $newToken->setUserId($userId);
     $newToken->setToken($token);
     return $newToken;
 }
 public function postRegistro()
 {
     $input = Input::all();
     $reglas = array('nombre' => 'required', 'apellido' => 'required', 'celular' => 'required|numeric|unique:users', 'cedula' => 'required|numeric|unique:users', 'email' => 'required|email|unique:users', 'pin' => 'required|numeric|digits_between:0,4', 'password' => 'required|numbers|case_diff|letters|min:6|confirmed', 'password_confirmation' => 'required|min:6');
     $validation = Validator::make($input, $reglas);
     if ($validation->fails()) {
         return Response::json(['success' => false, 'errors' => $validation->errors()->toArray()]);
     }
     try {
         // se guarda los datos del usuario
         $user = Sentry::register(array('first_name' => Input::get('nombre'), 'last_name' => Input::get('apellido'), 'email' => Input::get('email'), 'habilitar_pin' => 1, 'celular' => Input::get('celular'), 'cedula' => Input::get('cedula'), 'password' => Input::get('password'), 'pin' => Input::get('pin'), 'porcentaje' => 0.05, 'activated' => true));
         $userId = $user->getId();
         $token = new Token();
         $token->user_id = $userId;
         $token->api_token = hash('sha256', Str::random(10), false);
         $token->client = BrowserDetect::toString();
         $token->expires_on = Carbon::now()->addMonth()->toDateTimeString();
         $token->save();
         // Se autentica de una
         $user_login = Sentry::findUserById($userId);
         Sentry::login($user_login, false);
         return Response::json(['success' => true, 'user' => $user_login, 'token' => $token->api_token]);
     } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) {
         $error = array('usuario' => 'Email es requerido');
     } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) {
         $error = array('usuario' => 'Password es requerido');
     } catch (Cartalyst\Sentry\Users\UserExistsException $e) {
         $error = array('usuario' => 'El Email ya está registrado');
     }
     return Response::json(['success' => false, 'errors' => $error]);
 }
Exemple #5
0
 public static function conjure($token, TokenSet $tokenSet, TokenOutput $tokenOutput = null)
 {
     if (is_array($token)) {
         switch ($token[0]) {
             case T_INTERFACE:
                 $t = new InterfaceToken($token, $tokenSet);
                 break;
             case T_CLASS:
                 $t = new ClassToken($token, $tokenSet);
                 break;
             case T_FUNCTION:
                 $t = new FunctionToken($token, $tokenSet);
                 break;
             default:
                 // fall through to regular Token
                 $t = new Token($token, $tokenSet);
         }
     } else {
         // fall through to regular Token
         $t = new Token($token, $tokenSet);
     }
     if ($tokenOutput == null) {
         $tokenOutput = new TextTokenOutput();
     }
     $t->setOutput($tokenOutput);
     return $t;
 }
Exemple #6
0
 public function test1()
 {
     // TODO make proper test
     $tok = new Token();
     $val = $tok->generate(1000, 'bajs');
     echo $val . "\n";
 }
 /**
  * @param integer $steps
  * @param Token $token
  *
  * @return $this
  */
 protected function occupy($steps, Token $token)
 {
     if ($token->owner()->equals($this->homeSquares->owner())) {
         return $this->homeSquares->occupy(--$steps, $token);
     }
     return parent::occupy($steps, $token);
 }
 public function testIsExpired()
 {
     $token = new Token(array('access_token' => '', 'refresh_token' => '', 'expires_in' => 5));
     $this->assertFalse($token->isExpired());
     $token = new Token(array('access_token' => '', 'refresh_token' => '', 'expires_in' => -5));
     $this->assertTrue($token->isExpired());
 }
 /**
  * Simply attempts to attract place names or names.
  */
 private function extract_potential_named_entities()
 {
     for ($i = 0, $n = count($this->tokens); $i < $n; $i++) {
         $entity = NULL;
         $token = new Token($this->tokens[$i]);
         // If the token is uppercase, maybe it is a name or a place.
         if ($token->isUpperCase() && !$token->isStopWord() && !$token->isInitWord()) {
             $entity = array($token->getText());
             // Look two words ahead.
             if (isset($this->tokens[$i + 2])) {
                 $next = new Token($this->tokens[$i + 2]);
                 while ($next->isUpperCase() || $next->isPrefixOrInfix()) {
                     // Jump two words.
                     $i += 2;
                     $entity[] = $next->getText();
                     if (isset($this->tokens[$i + 2])) {
                         $next = new Token($this->tokens[$i + 2]);
                     } else {
                         break;
                     }
                 }
             }
             $this->named_entities[] = $entity;
         }
     }
 }
Exemple #10
0
 /**
  * Reads the next token from the INI file
  *
  * @throws  IOException     On error
  * @return Token
  */
 function readToken()
 {
     if ($this->file === null) {
         throw new BuildException("No File set for IniFileTokenReader");
     }
     static $tokens = null;
     if ($tokens === null) {
         $tokens = array();
         $arr = parse_ini_file($this->file->getAbsolutePath(), true);
         if ($this->section === null) {
             foreach ($arr as $sec_name => $values) {
                 foreach ($arr[$sec_name] as $key => $value) {
                     $tok = new Token();
                     $tok->setKey($key);
                     $tok->setValue($value);
                     $tokens[] = $tok;
                 }
             }
         } else {
             if (isset($arr[$this->section])) {
                 foreach ($arr[$this->section] as $key => $value) {
                     $tok = new Token();
                     $tok->setKey($key);
                     $tok->setValue($value);
                     $tokens[] = $tok;
                 }
             }
         }
     }
     if (count($tokens) > 0) {
         return array_pop($tokens);
     } else {
         return null;
     }
 }
Exemple #11
0
 /**
  * @param integer $user_id
  * @return Token
  */
 public function createAutologinToken($user_id)
 {
     $token = new Token();
     $token->setUserId($user_id);
     $token->setAction(Token::$ACTION_AUTOLOGIN);
     return $token;
 }
Exemple #12
0
 /**
  * @covers Xoops\Form\Token::render
  */
 public function testRender()
 {
     $value = $this->object->render();
     $this->assertTrue(is_string($value));
     $this->assertTrue(false !== strpos($value, '<input'));
     $this->assertTrue(false !== strpos($value, 'type="hidden"'));
     $this->assertTrue(false !== strpos($value, 'name="XOOPS_TOKEN_REQUEST"'));
 }
Exemple #13
0
 /**
  * Sign the Request with a Token
  *
  * @param Token  $token
  * @param string $prefix
  * @return array
  */
 public function sign(Token $token, $prefix = self::PREFIX)
 {
     $auth = [$prefix . 'version' => self::VERSION, $prefix . 'key' => $token->key(), $prefix . 'timestamp' => $this->timestamp];
     $payload = $this->payload($auth, $this->params);
     $signature = $this->signature($payload, $this->method, $this->uri, $token->secret());
     $auth[$prefix . 'signature'] = $signature;
     return $auth;
 }
Exemple #14
0
 protected function _getParseTokenFromToken(Token $token)
 {
     $code = $token->getCode();
     if ($code === "WHILE_START") {
         $code = "WHILE";
     }
     return new ParseToken($code, $token->getContent(), $token->getChar(), $token->getLine());
 }
 /**
  * @param array $params Parameters for creating an account
  *                      username, password, email are required
  *                      language, first_name, last_name are optional
  * @return array
  */
 public function create($params)
 {
     $params = $this->filter_parameters($params, array('username', 'password', 'first_name', 'last_name', 'email', 'language'));
     $v = new \Valitron\Validator($params);
     $v->rules(['required' => [['username'], ['password'], ['email'], ['language']]]);
     $used_values = null;
     $return_errors = null;
     if ($v->validate()) {
         if ($this->get_user_id($params['username']) !== false) {
             $used_values[] = 'username';
         }
         if ($this->email_used($params['email'])) {
             $used_values[] = 'email';
         }
         if ($used_values === null) {
             $v->rule('email', 'email');
             if ($v->validate()) {
                 $v->rules(['lengthMax' => [['username', 20]]]);
                 if ($v->validate()) {
                     $params['password'] = create_hash($params['password']);
                     $sql = "INSERT INTO user (";
                     foreach ($params as $key => $value) {
                         $sql .= $key . ",";
                     }
                     $sql = substr($sql, 0, -1);
                     $sql .= ") VALUES (";
                     foreach ($params as $key => $value) {
                         $sql .= " :" . $key . ",";
                         $params[':' . $key] = $value;
                     }
                     $sql = substr($sql, 0, -1);
                     $sql .= ")";
                     $query = $this->db->prepare($sql);
                     $query->execute($params);
                     $user_id = $this->get_user_id($params['username']);
                     $auth = new Token($this->db);
                     require_once 'core/Mail.php';
                     $mail = new Mail();
                     $mail->addAddress($params['email'], $params['username']);
                     $mail->isHTML(true);
                     $mail->Subject = "Welcome to buckbrowser";
                     $mail->Body = str_replace(['%username%', '%bb-link%'], [$params['username'], 'http://buckbrowser.langstra.nl'], file_get_contents(TEMPLATE_PATH . 'mail/signup.html'));
                     $mail->send();
                     return array('token' => $auth->create_token($user_id));
                 } else {
                     $return_errors['incorrect_fields'] = 'username';
                 }
             } else {
                 $return_errors['incorrect_fields'] = 'email';
             }
         } else {
             $return_errors['already_exists'] = $used_values;
         }
     } else {
         $return_errors['empty_fields'] = array_keys($v->errors());
     }
     return $this->create_error($return_errors);
 }
 private function getRandomToken($studentId)
 {
     $t = new Token($this->tokenAlphabet, $this->tokenLength);
     // check for existing tokens
     while ($this->checkToken($studentId, $t->getString())) {
         $t = Token($this->tokenAlphabet, $this->tokenLength);
     }
     return $t->getString();
 }
Exemple #17
0
 public function getSalt()
 {
     $password = $this->password;
     $token = new Token();
     $hash = $token->generatePassword(15);
     $this->hash = $hash;
     $salt = md5($password . $hash);
     return $salt;
 }
Exemple #18
0
 function apply(TokenStream $ts, Token $t, BlueContext $blueContext)
 {
     if (isset($this->raytraceLiteral[(string) $t]) || isset($this->raytraceNonliteral[$t->type()])) {
         foreach ($this->directives as $directives) {
             foreach ($directives as $directive) {
                 $directive->apply($ts, $this, $blueContext);
             }
         }
     }
 }
Exemple #19
0
 /**
  * Check if the token is operator
  *
  * @param Token $token
  * @return boolean
  */
 public function isOperator(Token $token)
 {
     if (T_STRING == $token->getType()) {
         if (isset($this->byPass[$token->getValue()])) {
             return false;
         }
         return isset($this->operatorsStrings[$token->getValue()]);
     }
     return isset($this->operators[$token->getType()]);
 }
Exemple #20
0
 /**
  * Adds a new token to the admin, and returns with the id of the newly created Doctrine model.
  *
  * @param object $admin an Admin model object
  * @param string $tokenType
  * @param string $token default null if null then one will be generated
  * @param string $rid default null if null then one will be generated
  * @return object the new Token model object
  */
 public static function addToken($admin, $tokenType, $token = null, $rid = null)
 {
     $model = new Token();
     $model->username = $admin['username'];
     $model->type = $tokenType;
     $model->token = $token === null ? self::createRandomString() : $token;
     $model->rid = $rid === null ? self::createRandomString(32) : $rid;
     $model->save();
     return $model;
 }
Exemple #21
0
 /**
  * Créer un nouveau jeton d'accès
  * @return Token
  */
 public function getNewToken()
 {
     $id = (string) Uuid::uuid4();
     $token = new Token();
     $token->id = $id;
     $token->user_id = $this->id;
     $token->save();
     $token->id = $id;
     return $token;
 }
Exemple #22
0
 public function getCookie(Slim\Slim &$app)
 {
     if (empty($app->getCookie('username'))) {
         //setting cokkie if the user doesn't have it
         $generateToken = new Token();
         $cookieKey = md5($generateToken->generatePassword(8));
         $app->setCookie('username', $cookieKey, time() + 86400 * 4);
     }
     $cookie = $app->getCookie('username');
     return $cookie;
 }
Exemple #23
0
 private static function readInt(Token $current_token, $string, &$i)
 {
     while (++$i < strlen($string)) {
         if (in_array($string[$i], array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-'), true)) {
             $current_token->addData($string[$i]);
         } else {
             $i--;
             break;
         }
     }
 }
 public function getTokenUserCloud($user, $cloud)
 {
     $token = new Token();
     $token->setUserId($user);
     $token->setCloudspaceName($cloud);
     try {
         $toReturn = current($this->dao->search($token));
     } catch (EyeResultNotFoundException $e) {
     }
     return $toReturn;
 }
 /**
  * Detect type of block.
  *
  * @param Token $token token
  *
  * @return null|array array with 'type' and 'isStart' keys or null if not found
  */
 public static function detectBlockType(Token $token)
 {
     foreach (self::getBlockEdgeDefinitions() as $type => $definition) {
         if ($token->equals($definition['start'])) {
             return array('type' => $type, 'isStart' => true);
         }
         if ($token->equals($definition['end'])) {
             return array('type' => $type, 'isStart' => false);
         }
     }
     return null;
 }
Exemple #26
0
 function testContains()
 {
     $token = new Token('$');
     $this->assertTrue($token->contains('$'));
     $this->assertFalse($token->contains('!'));
     $token = new Token(T_STRING);
     $this->assertTrue($token->contains(null));
     $this->assertFalse($token->contains(''));
     $token = new Token(T_STRING, '"yep"', null);
     $this->assertTrue($token->contains(null));
     $this->assertFalse($token->contains('"nope"'));
     $this->assertTrue($token->contains('"yep"'));
 }
Exemple #27
0
 public function testWithersReturnNewModifiedInstance()
 {
     $value = 'bob';
     $newValue = 'alice';
     $type = new TokenType(TokenType::DYNAMIC_ARRAY_TYPE);
     $token = new Token($value, $type);
     $newToken = $token->withValue($newValue);
     $this->assertEquals($value, $token->getValue());
     $this->assertEquals($type->getValue(), $token->getType());
     $this->assertInstanceOf(Token::class, $newToken);
     $this->assertEquals($newValue, $newToken->getValue());
     $this->assertEquals($type->getValue(), $newToken->getType());
 }
 public function token()
 {
     if ($this->token === null) {
         $this->reloadToken();
     }
     if ($this->token === null) {
         $this->initializeToken();
     }
     if ($this->token->isTokenExpired()) {
         $this->refreshToken();
     }
     return $this->token;
 }
Exemple #29
0
 public function emit($token = null)
 {
     if ($token != null) {
         $this->token = $token;
     } else {
         $t = new Token($this->input, $this->type, $this->tokenStartCharIndex, $this->getCharIndex() - 1);
         $t->line = $this->tokenStartLine;
         $t->setText($this->text);
         $t->charPositionInLine = $this->tokenStartCharPositionInLine;
         $this->token = $t;
         return $t;
     }
 }
Exemple #30
0
 /**
  * Creates individual Entry objects of the appropriate type and
  * stores them as members of this entry based upon DOM data.
  *
  * @param DOMNode $child The DOMNode to process
  */
 protected function takeChildFromDOM($child)
 {
     $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
     switch ($absoluteNodeName) {
         case $this->lookupNamespace('yt') . ':' . 'token':
             $token = new Token();
             $token->transferFromDOM($child);
             $this->_token = $token;
             break;
         default:
             parent::takeChildFromDOM($child);
             break;
     }
 }