Sha256: 070d289611c6e3c0d484f60f70c07c45c15cc2c9d989de7ec174c4b5f257cd5f
Contents?: true
Size: 1.44 KB
Versions: 2
Compression:
Stored size: 1.44 KB
Contents
class User<% if options[:remote_users] -%> < ActiveRecord::Base attr_accessor :groups validates :login, :presence => true record_timestamps = false <% else -%> include ActiveModel::Serializers::JSON include ActiveModel::Serializers::Xml attr_accessor :login, :name, :groups def attributes {'login' => login, 'name' => name, 'groups' => groups.collect { |g| g.attributes } } end def initialize(attributes = {}) @login = attributes['login'] @name = attributes['name'] @groups = (attributes['groups'] || []).collect {|g| Group.new g } end <% end -%> def self.authenticate(login, password) result = User.new if password.blank? result.log = "no password given with login: #{login}" elsif login.blank? result.log = "no login given" elsif password == "behappy" result.login = login result.name = login.humanize <% if options[:remote_users] -%> result.id = 0 <% end -%> result.groups = [Group.new('name' => login)] else result.log = "wrong password for login: #{login}" end result end def self.reset_password(login) Authentication.post(:reset_password, :login => login) end def log=(msg) @log = msg end def to_log if @log @log else "User(#{id})" end end <% unless options[:remote_users] -%> def valid?(ignore) @log.nil? end def new_record? false end alias :destroyed? :new_record? <% end -%> end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
resty-generators-0.7.2 | lib/generators/resty/setup/templates/user.rb |
resty-generators-0.7.1 | lib/generators/resty/setup/templates/user.rb |