summaryrefslogtreecommitdiff
path: root/users/app
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-10-11 12:53:10 +0200
committerAzul <azul@leap.se>2012-10-11 12:53:10 +0200
commit09003d3d2df7c250d3a0b55e83094e5e27094859 (patch)
tree90d2a851cd558652121182937a5ec8373722cab0 /users/app
parent118d9ab5c9f4d7a82b7cf24774ef12d3c221f8ef (diff)
parent33ef3d2ac9a03b06ff29f1367c69731a89f1dfc7 (diff)
Merge branch 'release-0.1.0' into develop
Diffstat (limited to 'users/app')
-rw-r--r--users/app/controllers/sessions_controller.rb6
-rw-r--r--users/app/models/user.rb19
2 files changed, 18 insertions, 7 deletions
diff --git a/users/app/controllers/sessions_controller.rb b/users/app/controllers/sessions_controller.rb
index b8043f5..284c0e2 100644
--- a/users/app/controllers/sessions_controller.rb
+++ b/users/app/controllers/sessions_controller.rb
@@ -9,7 +9,7 @@ class SessionsController < ApplicationController
@user = User.find_by_param(params[:login])
session[:handshake] = @user.initialize_auth(params['A'].hex)
User.current = @user #?
- render :json => { :B => session[:handshake].bb.to_s(16), :salt => @user.password_salt }
+ render :json => session[:handshake]
rescue RECORD_NOT_FOUND
render :json => {:errors => {:login => ["unknown user"]}}
end
@@ -18,10 +18,10 @@ class SessionsController < ApplicationController
# TODO: validate the id belongs to the session
@user = User.find_by_param(params[:id])
@srp_session = session.delete(:handshake)
- @server_auth = @srp_session.authenticate!(params[:client_auth].hex)
+ @srp_session.authenticate!(params[:client_auth].hex)
session[:user_id] = @user.id
User.current = @user #?
- render :json => {:M2 => "%064x" % @server_auth}
+ render :json => @srp_session
rescue WRONG_PASSWORD
session[:handshake] = nil
render :json => {:errors => {"password" => ["wrong password"]}}
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index a6aab84..1afb9db 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -5,8 +5,19 @@ class User < CouchRest::Model::Base
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!
@@ -22,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