-
Notifications
You must be signed in to change notification settings - Fork 992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a new dropdown 'token type' for numeric tokens. #1104
Conversation
This commit adds a new selection to let you choose between the normal tokens and numeric-only tokens.
Such feature mus be in plugin |
Such feature must be in plugin
Can this be done in a plugin?
|
Except with some hack, i don't think currently. |
Hey, thanks a lot. |
Great to hear that! Please just ping me when you are considering merging this, then I'll rebase it and make sure it still works. One caveat: The random generator for the numbers is just |
This is a great feature. |
I would like to have a "startFrom' value there. Typically I like having similar tokens with the same length so I would like to start tokens eg from 10000, |
@TonisOrmisson it's exacly why i ask it to be in plugin … Create an event + a core plugin to set it as number allow creating another plugin to have
|
I'm willing to port the patch to the current dev branch, but could you
please first discuss whether it will be accepted or not? [not as a
plugin, but as a part of core, as it is still impossible to write as a
plugin at this point, I think].
|
I confirm, personnaly i ask for a new event in core to allow adding this. |
@@ -472,6 +473,7 @@ public function rules() | |||
array('format', 'in', 'range'=>array('G', 'S', 'A'), 'allowEmpty'=>true), | |||
array('googleanalyticsstyle', 'numerical', 'integerOnly'=>true, 'min'=>'0', 'max'=>'2', 'allowEmpty'=>true), | |||
array('autonumber_start', 'numerical', 'integerOnly'=>true, 'allowEmpty'=>true), | |||
array('tokentype', 'in', 'range'=>array('default','numeric'), 'allowEmpty'=>true), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest using constants for the types. Much easier to refer to later and refactor if needed
return str_replace(array('~', '_'), array('a', 'z'), Yii::app()->securityManager->generateRandomString($iTokenLength)); | ||
if($tokenType == 'numeric') { | ||
return randomChars($iTokenLength, '123456789'); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no else
is needed here if true above will return
<div class="form-group"> | ||
<label class=" control-label" for='tokentype'><?php eT("Select token type:"); ?></label> | ||
<div class=""> | ||
<select name='tokentype' id='tokentype' class="form-control"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use CHtml::dropDownList here. That's why we have a framework for
I like this feature. While using a plugin is nice to separate code, I consider this a core feature which should go into LS 4 directly. |
@maziminke : The reason why i think it's best by event is allowing forcing to anythging else … One user can want number only, one another uppercase only etc … |
@pefeigl: Please port this PR to the current develop branch. |
@dominikvitt : then need another Pull request for Omit ambiguous characters from token Again and agin : best solution : add an event for plugin to do anything with token … |
@Shnoulle Why would this be put in a plugin instead of core? |
@@ -691,6 +691,7 @@ public function addnew($iSurveyId) | |||
|
|||
$aData['thissurvey'] = getSurveyInfo($iSurveyId); | |||
$aData['surveyid'] = $iSurveyId; | |||
$aData['tokenType'] = !empty(Token::model($iSurveyId)->survey->tokentype) ? Token::model($iSurveyId)->survey->tokentype : 'default'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When ported to LS4, you can use the ??
operator here, since LS4 will require PHP 7+.
@olleharstedt : because see #1104 (comment)
Or Omit ambiguous characters from token (most valuable in my opinion than only number) I ever have user with specificcode{number} only token code. And why not only alpha (not numeric), only uppercase (great to have too) This pull request do ONE system when we can need a lot more … Adding a event + a plugin for numeric only care all of options … |
@tammoterhark is a solution for all too, but : more and more system to care by core dev in LimeSurvey … need a test here for combination. |
We can do both. Add new core features and event to allow more customization. |
Also note that Travis fails because the newly installed database column is different from the upgraded one:
|
? Why do both , in my opinion, needed
|
How about a change like this for adding a new event
The idea is that a plugin that subscribes to the event I tested this with a plugin that used this function to generate the token:
The token is now generated as numeric, just like the purpose of this PR: |
I now have these functions:
See the functions in the source code of our TFRcustomToken plugin |
@Jan-E 👍 for With
Then :
|
Comment moved to #1307 (comment) |
Let us continue the discussions in the new PR without any code changes yet: |
Ah right … no surveyId because it's a static function, Think it's best to have $this totally when generate token, then 2 solution:
Looking at usage in develop, not a lot of place for usage
But 1 seemls the really BEST solution. Maybe move generateRandomToken to |
To all participants in and subscribers to this PR: please review Add a new event to generate custom tokens at #1307 |
@Jan-E , i merge it in develop (and take responsability of fixing if needed). |
@Shnoulle Do you mean adding a dropdown 'token type' for numeric tokens? There are several people here that want to see it in core, not in a plugin. I know you are a fan of plugins, but having this in core as well might be equally inportant. |
New PR for afterGenerateToken plus customToken plugin is here now: #1308 If this PR is merged every LimeSurvey admin can activate the plugin and choose for the 3 token types in the plugin:
Please review the PR. |
This commit adds a new selection to let you choose between the normal tokens and numeric-only tokens.
New feature # :
Dev:
Dev: