Class: Marley::Joints::User::Resources::User

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/marley/joints/user.rb

Constant Summary collapse

LOGIN_FORM =
[:instance,{:name => 'login',:url => 'main_menu',:description => 'Existing users please log in here:',:new_rec => true,:schema => [[:text,'name',RESTRICT_REQ],[:password,'password',RESTRICT_REQ]]}]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#confirm_passwordObject

Returns the value of attribute confirm_password.



79
80
81
# File 'lib/marley/joints/user.rb', line 79

def confirm_password
  @confirm_password
end

#old_passwordObject

Returns the value of attribute old_password.



79
80
81
# File 'lib/marley/joints/user.rb', line 79

def old_password
  @old_password
end

#passwordObject

Returns the value of attribute password.



79
80
81
# File 'lib/marley/joints/user.rb', line 79

def password
  @password
end

Class Method Details

.authenticate(credentials) ⇒ Object



86
87
88
89
# File 'lib/marley/joints/user.rb', line 86

def self.authenticate(credentials)
  u=find(:name => credentials[0], :pw_hash => Digest::SHA1.hexdigest(credentials[1]))
  u.respond_to?(:user_type) ? Marley::Resources.const_get(u[:user_type].to_sym)[u[:id]] : u
end

.authorize_rest_postObject



83
84
85
# File 'lib/marley/joints/user.rb', line 83

def self.authorize_rest_post
  true
end

.join_to(klass, user_id_col_name = nil) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/marley/joints/user.rb', line 71

def self.join_to(klass, user_id_col_name=nil)
  user_id_col_name||=:user_id
  klass=MR.const_get(klass) if klass.class==String
  Marley.plugin(:current_user_methods).apply(klass)
  klass.owner_col!=user_id_col_name
  one_to_many klass.resource_name.pluralize.to_sym, :class => klass, :key => user_id_col_name
  klass.send(:many_to_one, :user, :class => MR::User, :key => user_id_col_name)
end

.requires_user?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/marley/joints/user.rb', line 80

def self.requires_user?
  ! ($request[:verb]=='rest_post' || ($request[:verb]=='rest_get' && $request[:path][1]=='new'))
end

Instance Method Details

#after_initializeObject



70
# File 'lib/marley/joints/user.rb', line 70

def after_initialize;end

#before_saveObject



100
101
102
103
104
# File 'lib/marley/joints/user.rb', line 100

def before_save
  if self.new? || self.old_password.to_s + self.password.to_s + self.confirm_password.to_s > ''
    self.pw_hash=Digest::SHA1.hexdigest(self.password)
  end
end

#create_msgObject



105
106
107
# File 'lib/marley/joints/user.rb', line 105

def create_msg
  [:msg,{:title => 'Success!'},"Your login, '#{self.name}', has been sucessfully created. You can now log in."]
end

#validateObject



90
91
92
93
94
95
96
97
98
99
# File 'lib/marley/joints/user.rb', line 90

def validate
  super
  validates_presence [:name]
  validates_unique [:name]
  if self.new? || self.old_password.to_s + self.password.to_s + self.confirm_password.to_s > ''
    errors[:password]=['Password must contain at least 8 characters'] if self.password.to_s.length < 8
    errors[:confirm_password]=['Passwords do not match'] unless self.password==self.confirm_password
    errors[:old_password]=['Old Password Incorrect'] if !self.new? && Digest::SHA1.hexdigest(self.old_password.to_s) != self.pw_hash
  end
end