Kohana 3 auth username as number - authentication

I want to use numbers as username in Kohana Auth. For example, username 100001?
While adding new user Kohana returns me error: ORM_Validation_Exception [ 0 ]: Failed to validate array
Is is possible to user numbers as username in Kohana?

EDIT: This answer looks simpler and better than mine, but try to understand it at all.
You need to extend User Model, I'll help you using auth with the ORM driver.
Steps to extend User Model:
If you didn't yet, configure Auth module to use orm and create a database table with the fields you want. Here is a good example of how to doing it (It's an old tutorial using ko3.1 but you can still learn from it). PS.: you can have any columns at the 'users' table and you don't need to have the 'username' column if you do not want.
Open and read carefully this file: MODULES/orm/classes/model/auth/user.php (It's self documented and I hope you understand it. If not, stop reading this answer here and read the kohana docs. Some shortcuts: Auth - Kohana User Guide, Auth (orm) methods, addons:auth
Copy the file (don't edit the original) to APPPATH/classes/model/auth/user.php and edit it how you want. Some functions that you may like to edit are: rules, filters and unique_key (<- useful). Be creative, you also can add custom functions.
Test and change whatever else needed.
You can change the login method to works as you like. You can set login by e-mail, make a custom validation method or parse values before saving in the database (see public function filters()). This is helpful for whatever you try to do with auth module using ORM... But... if you really don't want to use ORM, you can build your own driver, learn how.
I made this some time ago in kohana 3.2 but I think you won't get problems with 3.3. If you still have questions, this question on kohana forum may help.

Related

I want to add a param (eg. locale, or session-id) to every link/submit rails generate, is that possible?

I try to avoid cookies where ever I can. Therefore I want to put locale or session as 'everytime params' to every 'link_to_tag' or submit button 'per default'. Is that possible with rails standards. If yes how.
wow, thats a short question
I try to explain further:
if a user does not accept cookies, i ask nicely, but he dosnt accept. Its ok, but I would like to 'store' this info in the links I (rails does) generate, something like:
http://mydomain.earth/.../...?id=2&...&cookie=dontask
So I just dont ask again if this param is set. And if this param is set, I want rails to put it into every link it generates.
(this is not a security question, so please avoid answers like 'dont put session info into URL')
There is a rails (version specific) way:
default_url_options
Basicaly
Overwrite to implement a number of default options that all
url_for-based methods will use. The default options should come in the
form of a hash, just like the one you would use for url_for directly

create query using webservice api for Rally

I am trying to write a query in Ruby to insert a user story in Rally using WSAPI. I read through https://rally1.rallydev.com/slm/doc/webservice/.I looked it up and found that wsapi has a create() method, but I am not aware of its signature. I know it uses PUT/Post method for creation, but I just need an example to understand how to write create queries. Does anyone know of any useful resource to know more about this? I have all my code ready, just need information about writing "create" queries using Rally's WSAPI.
Thanks
There is a full directory of Ruby REST examples in the Github Repository for RallyRestToolkitForRuby:
https://github.com/RallyTools/RallyRestToolkitForRuby/tree/master/examples
This create example may be of particular interest. It's for a Defect, but the same logic would apply to Stories:
04-create-defect.rb

Devise in mogoid for multi-users with different data

I am using rails 3.2.7, mongoid 3, and i am trying to use devise for users accounts.
Before i'll start: i was searching a lot for my problem, and i read many tutorials, byt none fit to my need.
I have similar problem like devise and multiple “user” models
but i am using mongodb so i think the problem is not exacly the same.
I have 3 types of users":
Manger which can have many places and can manage them(edit info).
User which can search for places(even no user can) and create their places lists. Also user can comment and note the places.
Administrator who can edit/delete anythig, so admin is a god.
So, all of them have different data(except of login info) and i don't know what solution is the best.
STI would be good if they would have the same data, and different actions, but data are different too(but i am using mongoid, so maybe it would be fine?)
Single user model with roles is another solution but i don't know how to store different data, maybe with polymorphic? I don't fully understand how it should be implemented with devise and maybe cancan.
Maybe there is third?
I know what is STI, polymorphic associations, also how to implement roles with CanCan, but the problem is that i dont't know how to connect them with devise?
If there would be few sign in forms or one, it doesn't matter. I don't have to use devise either.
I found few tutorials/examples how to use devise, monogid, roles for multi-users applications, but they are when users store the same data, so they don't fit for me.
Can you give me advice, or a maybe a link which could help me?
Thanks for help :)
I would recommend building different controllers for different use cases. Don't build dependencies of different views inside the data. This way you are free to use the data for other use cases or other user groups without changing it directly.
Simply create controllers for the different use cases. This way you can change them any time without changing your data model.

YII how to get data from another`s session?

I need a UI to manage all app sessions. How could I retrive data from foreign sessions? Im interested in getting data set bysetState` function during other users login.
I'm using CDbHttpSession for storing sessions in DB
So, i found answer, but it isnt good in my opinion. But maybe it will be helpfull for others. Yii stores data in session table using php built in session serialization method (it isnt regular serialize function). And only way that i found to work with it is suggested on the php session_decode manual page in the comments.

In Rails 3 app, how do I allow anonymous users to access a controller action only once?

For example, suppose I had a blog and anybody could read the articles, read the comments, and flag any comment as inappropriate. How do I prevent non-signed-in users from clicking the "Flag Comment" link more than once?
The "Flag Comment" link would be tied directly to a controller method for a Comment model.
I'm new to the idea of sessions and cookies (as well as Rails in general). I've read this on Sessions but I'm afraid I'm still a little confused.
I've considered creating a Base class called Guest, but I was wondering if I could avoid this and instead utilize session or cookies temp data.
Thanks in advance.
The basic idea could be the following (sorry, no code yet):
Define which information should be stored in a session and / or a cookie. I think it should be the id of the comment for each flagged comment. Store them in a hash like structure.
Make the link to flagging a comment depending on the content of the cookie. Something like that:
...
= link_to('flag comment', flag_comment_path(comment.id)) if ! cookies[:flagged_comments] || ! cookies[:flagged_comments][comment.id]
Set the cookies hash value when a comment is flagged (use here the local variable comment, this has to be set or known somewhere):
cookies[:flagged_comments] = Hash.new if ! cookies[:flagged_comments]
cookies[:flagged_comments][comment.id] = comment.id
I don't know if the code will work, but the idea should be clear. And yes, do that only to anonymous users (more dependent UI and controller functionality).
One more thing: I don't think you should use the session and the cookies for storing this information. And due to the fact that you have to notice when someone flags a comment in 2 different sessions, go with the cookies only.