Commit 103eb270 by liyijie

Fix register bug

parent 0bdede66
...@@ -101,11 +101,11 @@ module RailsApiAuthentication ...@@ -101,11 +101,11 @@ module RailsApiAuthentication
user.nil? ? raise(UserError.new(401, '-1', 'Unauthorized')) : user user.nil? ? raise(UserError.new(401, '-1', 'Unauthorized')) : user
end end
def register(name, password, params={}) def register(name, password, attrs={})
raise(UserError.new(401, '-1', 'password is blank')) if password.blank? raise(UserError.new(401, '-1', 'password is blank')) if password.blank?
valid! name, attrs.delete(@valid_key) valid! name, attrs.delete(@valid_key)
user = self.create!({@auth_key => name, @auth_password => generate_password(password)}) user = self.create!({@auth_key => name, @auth_password => generate_password(password)})
user.token = AuthToken.create(self, oauth_params(params).merge({ oid: user.id }) ).token user.token = AuthToken.create(self, oauth_params(attrs).merge({ oid: user.id }) ).token
user user
rescue ActiveRecord::RecordInvalid => e rescue ActiveRecord::RecordInvalid => e
raise UserError.new(401, '-1', e.message) raise UserError.new(401, '-1', e.message)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment