Sha256: bd4719020ffdf869e233e3d491cf58222d4d6e6b3bc47ead5011a4d497131397

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

# -*- encoding : utf-8 -*-
class BaseUser < ActiveRecord::Base
	self.table_name = "users"

	attr_accessor :password, :password_repeat, :email

	has_many :user_roles, :foreign_key => :user_id

	# Validate name
	validates_length_of :name, :within => 3..30, :if => Proc.new {|u| not u.name.nil?}
	validates_format_of :name, :with => /\A[a-z\d_ -.öäüÖÄÜ]+\z/i, :if => Proc.new {|u| not u.name.nil?}

	def token
		return OAuth2::AccessToken.new(OnlinegamesInfoConnect::OgiOauth.instance.get_client, self.oauth_token)
	end

	attr_accessor :cached_user_roles
	def has_right(right)
		if self.cached_user_roles.nil?
			self.cached_user_roles = []
			self.user_roles.all.each do |role|
				self.cached_user_roles << role.role
			end
		end

		return true if self.cached_user_roles.include?(right)
		return true if self.cached_user_roles.include?('superadmin')
		return false
	end

	# Checks if Online in the last 15 minutes
	def get_last_action
		return (self.last_request_at + 15.minutes) > Time.now
	end

	def user_login(remote_ip)
		self.last_request_at = Time.now
		self.last_login_ip = self.current_login_ip
		self.last_login_at = self.current_login_at
		self.current_login_at = Time.now
		self.current_login_ip = remote_ip
		self.login_count += 1
		self.save!
	end

	before_create do
		self.current_login_at = Time.now
		self.last_login_at = Time.now
		self.premium_time = Time.now
		self.user_status = 'active'

		return true
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
onlinegames_info_connect-0.0.1 app/models/base_user.rb