本文整理汇总了PHP中Token::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Token::save方法的具体用法?PHP Token::save怎么用?PHP Token::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Token
的用法示例。
在下文中一共展示了Token::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postRegistro
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]);
}
示例2: factory
public static function factory($personId, $function, $expireDate = null)
{
$token = new Token();
$token->person_id = $personId;
$token->token = str_replace('.', '', uniqid('', true));
$token->function = $function;
$token->expire_date = $expireDate;
$token->save();
return $token;
}
示例3: getNewToken
/**
* 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;
}
示例4: addToken
/**
* 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;
}
示例5: postIndex
public function postIndex()
{
$input = Input::only('keyword');
$rules = array('keyword' => 'required|min:6');
$v = Validator::make($input, $rules);
if ($v->fails()) {
return Output::push(array('path' => 'token', 'errors' => $v, 'input' => TRUE));
}
$token = new Token();
$token->token = Hash::make($input['keyword']);
$token->user_id = Auth::user()->id;
$token->save();
return Output::push(array('path' => 'token', 'messages' => array('success' => _('Token was created'))));
}
示例6: obtainToken
/**
* 获得token
* @param $userId
* @param $orgId
* @param $eventId
* @return bool 返回false表示生成失败,否则返回sessionId
*/
protected static function obtainToken($userId, $orgId, $eventId)
{
session_start();
$sessionId = session_id();
$token = new Token();
$token->expire = time() + self::$expire;
$token->create_time = time();
$token->token = $sessionId;
$token->event_id = $eventId;
$token->user_id = $userId;
$token->org_id = $orgId;
if (!$token->save()) {
return false;
}
return $sessionId;
}
示例7: actionLogin
public function actionLogin()
{
$username = $_POST['username'];
$password = $_POST['password'];
$identity = new UserIdentity($username, $password);
if (!$identity->authenticate()) {
Helper::renderJSONErorr("Wrong username or password");
}
$token = new Token();
$token->user = $identity->getId();
$token->token = Yii::app()->getSecurityManager()->generateRandomString(64);
if ($token->save()) {
Helper::renderJSON(["access_token" => $token->token, "token_type" => "bearer"]);
}
Helper::renderJSONErorr("Internal error");
}
示例8: saveTokenForUser
/**
* Saves all tokens from session to database
*
* @param sfEvent $event
* @return void
*/
public static function saveTokenForUser(sfEvent $event)
{
foreach ($event->getSubject()->getAttributeHolder()->getNamespaces() as $namespace) {
if (substr($namespace, 0, 18) == 'sfCacophonyPlugin/') {
$t = Doctrine_Core::getTable('Token')->findOneByUserAndProvider($event->getSubject()->getGuardUser(), substr($namespace, 18));
if (!$t) {
$t = new Token();
}
$me = $event->getSubject()->getAttribute('me', null, $namespace);
$t->setProvidersUserId($me['providers_user_id']);
$t->setContent($event->getSubject()->getAttribute('accessToken', null, $namespace));
$t->setProvider(substr($namespace, 18));
$t->setUser($event->getSubject()->getGuardUser());
$t->save();
}
}
}
示例9: login_post
/**
* Account login
* @param POST username
* @param POST password
* @param POST client_secret_uuid
* @return object{status, token}
*/
public function login_post()
{
$response = new stdClass();
//Parameters check
$username = $this->post('username');
$password = $this->post('password');
$client_secret_uuid = $this->post('client_secret_uuid');
if (!empty($username) && !empty($password) && !empty($client_secret_uuid)) {
$user = new User();
$user->where('username', $this->post('username'))->where('password', sha1($this->post('password')))->get();
//Record found
if ($user->exists()) {
$token = uniqid(md5(rand()), true);
$token_entry = new Token();
$token_entry->token = $token;
$token_entry->user_id = $user->id;
//Token expire after 1 year
$token_entry->token_expire = time() + 60 * 60 * 24 * 365;
$token_entry->client_secret_uuid = $this->post('client_secret_uuid');
if ($token_entry->save()) {
$response->status = true;
$response->token = $token;
} else {
$response->status = false;
$response->error = "Something wrong in creating Auth Token";
}
} else {
$response->status = false;
$response->error = 'Username / Password wrong';
}
} else {
$response->status = false;
$response->error = 'You must provide username, password and client_secret_uuid';
}
$this->response($response);
}
示例10: executeSendPassword
public function executeSendPassword(sfWebRequest $request)
{
// try to find the user by the given E-Mail-Address
$user = Doctrine::getTable('User')->findOneByEmail($request->getParameter('email'));
if ($user) {
// delete all previous recovery tokens
Doctrine_Query::create()->delete('Token t')->where('t.user_id=? AND action=?', array($user->getId(), Token::$ACTION_RECOVER))->execute();
// generate recover token
$token = new Token();
$token->setUserId($user->getId());
$token->setAction(Token::$ACTION_RECOVER);
$token->save();
// sending user email
$html = $this->getPartial('recoverEmail', array('user' => $user, 'token' => $token));
$subject = sfContext::getInstance()->getI18N()->__('Your TimeHive password');
MailSender::createInstance()->send($user['email'], $subject, $html);
$this->getUser()->setFlash('send_pwd_failure', $this->getContext()->getI18N()->__('An email with instructions to choose a new password has been sent to you.'));
$this->redirect('login/index');
} else {
$this->getUser()->setFlash('send_pwd_failure', $this->getContext()->getI18N()->__('There is no such e-mail address in the our database!'));
$this->redirect('login/index');
}
}
示例11: User
function register_post()
{
$model = json_decode($this->post('models'));
$u = new User();
if ($this->_email_existed($model[0]->email)) {
$this->response(array('data' => array(), 'metadata' => array('msg' => 'email already used.', 'code' => 500)), 500);
} else {
$u->username = $model[0]->email;
$u->password = $this->_encrypt($model[0]->password);
$u->confirm_token = md5(uniqid(mt_rand(), true));
$u->status = 0;
if ($u->save()) {
$token = new Token();
$token->user_id = $u->id;
$token->token = md5(uniqid(mt_rand(), true));
$token->expired = date('Y-m-d', strtotime('+30 days'));
$token->save();
$data = array("id" => $u->id, "token" => $token->token, "username" => $u->username, "password" => "hidden", "status" => $u->status === 1 ? true : false, "confirmation" => $u->confirm_token, "companies" => array());
}
$this->response(array('user' => $data, 'metadata' => array('msg' => 'user created, waiting for validation.', 'code' => 201)), 201);
}
}
示例12: generatePhoneToken
public static function generatePhoneToken($key, $length)
{
$token = new Token();
$token->token_key = $key;
$token->token_value = rand(pow(10, $length - 1), pow(10, $length) - 1);
$token->expiry_date = \Carbon\Carbon::now()->addDay(1);
$token->created_at = \Carbon\Carbon::now();
$token->save();
return $token->token_value;
}
示例13: create
public static function create($customerId)
{
$customer = Customer::model()->findByPk($customerId);
if ($customer == null) {
throw new CHttpException(400, 'Invalid request. Customer id not available.');
}
$model = new Token();
$model->token = Yii::app()->hasher->hashPassword(time() . $customer->accountnr);
$model->created = time();
$model->customer_id = $customerId;
while (!$model->validate()) {
$model->token = Yii::app()->hasher->hashPassword(time() . $customer->accountnr);
}
if ($model->save()) {
return $model->token;
}
return false;
}
示例14: array
$selected_bar = Bar::find($_POST['select_bar']);
$shopping_cart = null;
$displayed_cart = null;
return $app['twig']->render("send_token.html.twig", array('user' => $user, 'friend' => $friend, 'friend_bars' => $friend_bars, 'selected_bar' => $selected_bar, 'shopping_cart' => $shopping_cart, 'displayed_cart' => $displayed_cart));
});
//Post Add Token {id}/{friend_id}/{bar_id}
$app->post("/add_token/{id}/{friend_id}/{bar_id}", function ($id, $friend_id, $bar_id) use($app) {
$user = Patron::find($id);
$friend = Patron::find($friend_id);
$friend_bars = $friend->getPreferredBars();
$selected_bar = Bar::find($bar_id);
$item_id = $_POST['item_id'];
$item = Item::find($item_id);
$menu_id = $selected_bar->getMenuId($item);
$new_token = new Token($friend_id, $menu_id, $id);
$new_token->save();
$mail = new PHPMailer();
// $mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'beerme.token@gmail.com';
$mail->Password = 'b33rm3123';
$mail->STMPSecure = 'ssl';
$mail->Port = 587;
$email_confirmation = $friend->getEmail();
$user_name = $friend->getName();
$mail->From = 'beerme.token@gmail.com';
$mail->FromName = 'Beer Me!';
$mail->addAddress($email_confirmation, $user_name);
$mail->addReplyTo('beerme.token@gmail.com', 'Beer Me!');
示例15: createToken
public function createToken()
{
$hash = sha1(microtime() . mt_rand() . "salty bastard");
$token = new Token();
$token->set('user_id', $this->id);
$token->set('hash', $hash);
$token->set('expire_date', date("Y-m-d H:i:s", strtotime("+1 year")));
$token->save();
return $token;
}