本文整理汇总了PHP中Token::generate方法的典型用法代码示例。如果您正苦于以下问题:PHP Token::generate方法的具体用法?PHP Token::generate怎么用?PHP Token::generate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Token
的用法示例。
在下文中一共展示了Token::generate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public function create()
{
new Protect();
$post = Input::post();
echo '<pre>';
if (!empty($post)) {
if (Token::check($post['token'])) {
Question::postQuestion($post);
echo 'Posted';
} else {
echo 'Security token missing.';
}
} else {
echo '
<form method="post" action="">
<input type="text" name="title" placeholder="Title">
<input type="hidden" name="token" value="' . Token::generate() . '">
<br>
<textarea placeholder="Description" type="text" name="content"></textarea>
<br>
<input type="submit">
</form>
';
}
}
示例2: RequesracallAction
public function RequesracallAction()
{
if (Input::exists() && Token::check(Input::get('token'))) {
$this->_DB->insert('phones', array('id' => 0, 'name' => Input::get('name'), 'number' => Input::get('number')));
$this->registerAction();
}
?>
<form action="" method="post">
<div class="field">
<LABEL for="name">Name: </LABEL>
<input
type="text"
name="name"
id="name" />
</div>
<div class="field">
<label for="number">Number: </label>
<input
type="tel"
name="number"
id="number" />
</div>
<input type="hidden" name="token" value="<?php
echo Token::generate();
?>
" />
<input type="submit" value="Save"/>
</form>
<?php
}
示例3: __construct
public function __construct()
{
$user_data = User::getUserData(['username', 'first_name', 'last_name', 'user_id', 'email', 'profile_pic'])[0];
$this->data['title'] = 'Questions - NCube School';
$this->data['first_name'] = ucwords($user_data['first_name']);
$this->data['last_name'] = ucwords($user_data['last_name']);
$this->data['token'] = Token::generate();
$this->data['username'] = $user_data['username'];
$this->data['side_active']['questions'] = ' active';
$this->data['profile_pic'] = User::getProfilePic($user_data['profile_pic']);
require_once 'include/header.php';
$questions = Question::getPublicQuestions();
foreach ($questions as $key => $value) {
$questions[$key]['up_count'] = Question::getVoteUpCount($value['q_id']);
$questions[$key]['down_count'] = Question::getVoteDownCount($value['q_id']);
$questions[$key]['level'] = Question::getDifficultyLevel($value['q_id']);
$questions[$key]['user_data'] = User::getPublicUserData($value['user_id'], ['profile_pic', 'first_name', 'last_name'])[0];
$questions[$key]['answers'] = Question::getAnswersCount($value['q_id']);
$questions[$key]['pic'] = User::getProfilePic($questions[$key]['user_data']['profile_pic']);
$vote = Question::getVote($value['q_id']);
if ($vote == 1) {
$questions[$key]['my_data']['vote_up_class'] = 'vote-up-active';
} else {
if ($vote == 0) {
$questions[$key]['my_data']['vote_down_class'] = 'vote-down-active';
}
}
}
$this->data['questions'] = $questions;
}
示例4: login
public function login($id = null)
{
$user = $this->user;
$this->data['user']['name'] = $user->data()->user;
Config::set('html.title', 'Авторизация');
Config::set('html.description.val', 'На этой странице можно залогиниться');
//$user = new User();
$salt = uniqid();
if (!Session::exists(Config::get('session.token_name'))) {
Token::generate();
}
if (Input::exists()) {
if (Token::check(Input::get('token'))) {
$validate = new VALIDATE();
$validation = $validate->check($_POST, array('user' => array('required' => true), 'password' => array('required' => true)));
if ($validate->passed()) {
$remember = Input::get('remember') === 'on' ? true : false;
$login = $user->login(Input::get('user'), Input::get('password'), null);
if ($login) {
Redirect::to('/');
} else {
echo '<p>Sorry, logging in failed</p>';
}
} else {
foreach ($validation->errors() as $error) {
//echo $error, '<br/>';
$this->data['validate_errors'][] = $error;
}
}
}
}
//$this->data['id']=$id;
//$this->data['name']=Input::get('name');
$this->view('user/login');
}
示例5: __construct
public function __construct($url)
{
$user_data = User::getUserData(['username', 'first_name', 'last_name', 'user_id', 'email', 'profile_pic'])[0];
$this->data['title'] = 'Question - NCube School';
$this->data['first_name'] = ucwords($user_data['first_name']);
$this->data['last_name'] = ucwords($user_data['last_name']);
$this->data['token'] = Token::generate();
$this->data['username'] = $user_data['username'];
$this->data['side_active']['questions'] = ' active';
$this->data['profile_pic'] = User::getProfilePic($user_data['profile_pic']);
$this->data['question'] = Question::getPublicQuestion($url[0])[0];
$this->data['q_user'] = User::getPublicUserData($this->data['question']['user_id'])[0];
$this->data['q_user']['profile_pic'] = User::getProfilePic($this->data['q_user']['profile_pic']);
$this->data['question']['up_count'] = Question::getVoteUpCount($this->data['question']['q_id']);
$this->data['question']['down_count'] = Question::getVoteDownCount($this->data['question']['q_id']);
$this->data['question']['level'] = Question::getDifficultyLevel($this->data['question']['q_id']);
$this->data['question']['answers_count'] = Question::getAnswersCount($this->data['question']['q_id']);
$answers = Question::getAnswers($this->data['question']['q_id']);
foreach ($answers as $key => $value) {
$answers[$key]['user'] = User::getPublicUserData($value['user_id'])[0];
$answers[$key]['user']['profile_pic'] = User::getProfilePic($answers[$key]['user']['profile_pic']);
}
$this->data['answers'] = $answers;
require_once 'include/header.php';
}
示例6: sendMail
/**
* Looks up user supplied email address / alias and sends a mail
*
* @param $email email address or username
*/
function sendMail($in)
{
$in = trim($in);
if (is_email($in)) {
$user_id = UserFinder::byEmail($in);
} else {
$user_id = UserFinder::byUsername($in);
}
$error = ErrorHandler::getInstance();
if (!$user_id) {
$error->add('Invalid email address or username');
return false;
}
$email = UserSetting::getEmail($user_id);
if (!$email) {
throw new \Exception('entered email not found');
}
$code = Token::generate($user_id, 'activation_code');
$pattern = array('/@USERNAME@/', '/@IP@/', '/@URL@/', '/@EXPIRETIME@/');
$user = User::get($user_id);
$page = XmlDocumentHandler::getInstance();
$url = $page->getUrl() . 'u/reset_pwd/' . $code;
$replacement = array($user->getName(), client_ip(), $url, shortTimePeriod($this->expire_time_email));
$msg = preg_replace($pattern, $replacement, $this->password_msg);
//d($msg);
$mail = SendMail::getInstance();
$mail->addRecipient($email);
$mail->setSubject('Forgot password');
$mail->send($msg);
return true;
}
示例7: test1
public function test1()
{
// TODO make proper test
$tok = new Token();
$val = $tok->generate(1000, 'bajs');
echo $val . "\n";
}
示例8: __construct
public function __construct()
{
$user_data = User::getUserData(['username', 'first_name', 'last_name', 'user_id', 'email', 'profile_pic'])[0];
$this->data['title'] = 'Home - NCube School';
$this->data['first_name'] = ucwords($user_data['first_name']);
$this->data['last_name'] = ucwords($user_data['last_name']);
$this->data['token'] = Token::generate();
$this->data['username'] = $user_data['username'];
$this->data['side_active']['home'] = ' active';
$this->data['profile_pic'] = User::getProfilePic($user_data['profile_pic']);
require_once 'include/header.php';
}
示例9: __construct
public function __construct()
{
$this->data['title'] = 'Login - NCube School';
$this->data['loginAction'] = '/login';
$this->data['registerAction'] = '/register';
$this->data['token'] = Token::generate();
$errors = Session::errors('errors');
if (gettype($errors) === 'string') {
$errors = array($errors);
}
$this->data['errors'] = $errors;
}
示例10: create
public function create($Model)
{
$this->Model = $Model;
echo '<p style="color:#FF0F13;">' . $this->errors() . '</p>';
echo '<form action="" method="post">
<input type="text" placeholder="username" name="Username" value="' . escape(\Input::get("username")) . '">
<input type="password" placeholder="password" name="Password">
<br>
<span>Remember me:</span><input type="checkbox" name="remember">
<br>
<input type="hidden" name="token" value="' . \Token::generate() . '">
<input type="submit">
</form>';
}
示例11: create
public function create($Model)
{
$this->Model = $Model;
if ($this->Model->hasErrors()) {
echo '<p style="color:#FF0F13;">' . $this->errors($this->Model->getErrors()) . '</p>';
}
echo '<form action="" method="post">
<input type="text" placeholder="Username" name="Username" value="' . escape(\Input::get("username")) . '"><br>
<input type="password" placeholder="Password" name="Password"><br>
<input type="password" placeholder="Repeat Password" name="Password2"><br>
<br>
<input type="hidden" name="token" value="' . \Token::generate() . '">
<input type="submit">
</form>';
}
示例12: __construct
public function __construct($url)
{
$user_data = User::getUserData(['username', 'first_name', 'last_name', 'user_id', 'email', 'profile_pic'])[0];
$this->data['title'] = 'Requests - NCube School';
$this->data['first_name'] = ucwords($user_data['first_name']);
$this->data['last_name'] = ucwords($user_data['last_name']);
$this->data['email'] = $user_data['email'];
$this->data['token'] = Token::generate();
$this->data['username'] = $user_data['username'];
$this->data['url'] = $url;
require_once 'include/header.php';
$this->data['side_active']['requests'] = ' active';
$this->data['profile_pic'] = User::getProfilePic($user_data['profile_pic']);
$user_id = Session::get('user_id');
$requests = User::getRequests();
foreach ($requests as $key => $value) {
$requests[$key]['user_data'] = User::getPublicUserData($value['user_id'])[0];
if (empty($value['user_data']['profile_pic'])) {
$requests[$key]['user_data']['profile_pic'] = '/public/images/profile-pic.png';
} else {
$requests[$key]['user_data']['profile_pic'] = '/data/images/profile/' . $value['user_data']['profile_pic'] . '.jpg';
}
switch ($value['type']) {
case 'C':
$requests[$key]['type'] = 'Classmate';
break;
case 'T':
$requests[$key]['type'] = 'Teacher';
break;
case 'S':
$requests[$key]['type'] = 'Student';
break;
case 'F':
$requests[$key]['type'] = 'Friend';
break;
case 'P':
$requests[$key]['type'] = 'Parent or Guardian';
break;
default:
$requests[$key]['type'] = '';
break;
}
}
$this->data['requests'] = $requests;
}
示例13: __construct
public function __construct($url)
{
$user_data = User::getUserData(['username', 'first_name', 'last_name', 'user_id', 'email', 'profile_pic'])[0];
$this->data['title'] = 'Settings - NCube School';
$this->data['first_name'] = ucwords($user_data['first_name']);
$this->data['last_name'] = ucwords($user_data['last_name']);
$this->data['email'] = $user_data['email'];
$this->data['token'] = Token::generate();
$this->data['username'] = $user_data['username'];
$this->data['url'] = $url;
require_once 'include/header.php';
$this->data['side_active']['settings'] = ' active';
$this->data['active'] = NULL;
if (!empty($url[0])) {
$this->data['active'][$url[0]] = ' stngs-menu-item-active';
}
$this->data['profile_pic'] = User::getProfilePic($user_data['profile_pic']);
}
示例14: __construct
public function __construct($username)
{
$user_id = Session::get('user_id');
$user_data = User::getPublicUserData($user_id)[0];
$this->data['title'] = ucwords($username);
$this->data['username'] = $user_data['username'];
$this->data['token'] = Token::generate();
$this->data['side_active']['profile'] = ' active';
require_once 'include/header.php';
$this->data['first_name'] = ucwords($user_data['first_name']);
$this->data['last_name'] = ucwords($user_data['last_name']);
$this->data['email'] = $user_data['email'];
$this->data['profile_pic'] = User::getProfilePic($user_data['profile_pic']);
$profile_id = User::getPublicUserId($username);
$profile_data = User::getPublicUserData($profile_id)[0];
$this->data['profile_data']['username'] = $username;
$this->data['profile_data']['first_name'] = ucwords($profile_data['first_name']);
$this->data['profile_data']['last_name'] = ucwords($profile_data['last_name']);
$this->data['profile_data']['email'] = $profile_data['email'];
$this->data['profile_data']['profile_pic'] = User::getProfilePic($profile_data['profile_pic']);
$this->data['profile_data']['follow'] = User::checkFollow($username);
$this->data['profile_data']['dob'] = $profile_data['dob'];
//date in mm/dd/yyyy format; or it can be in other formats as well
$birthDate = $profile_data['dob'];
//explode the date to get month, day and year
$birthDate = explode("-", $birthDate);
//get age from date or birthdate
$this->data['profile_data']['age'] = date("md", date("U", mktime(0, 0, 0, $birthDate[2], $birthDate[1], $birthDate[0]))) > date("md") ? date("Y") - $birthDate[0] - 1 : date("Y") - $birthDate[0];
$this->data['profile_data']['country'] = $profile_data['country'];
switch ($profile_data['gender']) {
case 'M':
$this->data['profile_data']['gender'] = 'Male';
break;
case 'F':
$this->data['profile_data']['gender'] = 'Female';
break;
case 'O':
$this->data['profile_data']['gender'] = 'Others';
break;
default:
break;
}
}
示例15: create
public static function create()
{
// TODO: Remplacer 'root' par '' en prod absolument !!
$public_key = $_SERVER['HTTP_X_PUBLIC_KEY'] ?? 'root';
// TODO: Remplacer 'hash_hmac(...)' par '' en prod absolument !!
$received_hash = $_SERVER['HTTP_X_HASH'] ?? hash_hmac('sha256', 'root', 'root');
if (Client::exists('public_key', $public_key)) {
$client = Client::getBy('public_key', $public_key);
$expected_hash = hash_hmac('sha256', $client->name, $client->private_key);
if ($received_hash == $expected_hash) {
$token = Token::generate();
$ttl = 600;
Token::insertIntoDb([$token, Utils::time(), $ttl, $client->id]);
Data::get()->add('token', $token);
return null;
}
}
Data::get()->add('error', 'Wrong keypair');
}