diff options
Diffstat (limited to 'users/app')
-rw-r--r-- | users/app/controllers/sessions_controller.rb | 6 | ||||
-rw-r--r-- | users/app/models/user.rb | 19 |
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 |