diff options
author | Azul <azul@leap.se> | 2012-10-11 12:52:40 +0200 |
---|---|---|
committer | Azul <azul@leap.se> | 2012-10-11 12:52:40 +0200 |
commit | 10441deba145f53604ca3b981374f1ee6619c400 (patch) | |
tree | 90d2a851cd558652121182937a5ec8373722cab0 /users/app/models | |
parent | 61d73ac517ccbcc7ca8892010ef89e861052807f (diff) | |
parent | 33ef3d2ac9a03b06ff29f1367c69731a89f1dfc7 (diff) |
Merge branch 'release-0.1.0'
Diffstat (limited to 'users/app/models')
-rw-r--r-- | users/app/models/user.rb | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/users/app/models/user.rb b/users/app/models/user.rb index fa64f42..1afb9db 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -1,14 +1,23 @@ class User < CouchRest::Model::Base - include SRP::Authentication - property :login, String, :accessible => true property :email, String, :accessible => true property :password_verifier, String, :accessible => true property :password_salt, String, :accessible => true - validates :login, :password_salt, :password_verifier, :presence => true - validates :login, :uniqueness => true + validates :login, :password_salt, :password_verifier, + :presence => true + + validates :login, + :uniqueness => true + + validates :login, + :format => { :with => /\A[A-Za-z\d_]+\z/, + :message => "Only letters, digits and _ allowed" } + + validates :password_salt, :password_verifier, + :format => { :with => /\A[\dA-Fa-f]+\z/, + :message => "Only hex numbers allowed" } timestamps! @@ -24,8 +33,8 @@ class User < CouchRest::Model::Base # valid set of attributes for testing def valid_attributes_hash { :login => "me", - :password_verifier => "1234", - :password_salt => "4321" } + :password_verifier => "1234ABC", + :password_salt => "4321AB" } end end @@ -38,6 +47,10 @@ class User < CouchRest::Model::Base super(options.merge(:only => ['login', 'password_salt'])) end + def initialize_auth(aa) + return SRP::Session.new(self, aa) + end + def salt password_salt.hex end @@ -46,4 +59,15 @@ class User < CouchRest::Model::Base password_verifier.hex end + def username + login + end + + def self.current + Thread.current[:user] + end + def self.current=(user) + Thread.current[:user] = user + end + end |