Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Пример диплома специалиста / 007 Текст програми.docx
Скачиваний:
11
Добавлен:
28.03.2016
Размер:
157.39 Кб
Скачать

6

02070743.00569-01 12 01

#----------------------------------------------------------------------------------------------------category.rb

class Category < ActiveRecord::Base

#-validations-

validates_numericality_of :id, :message => "The ID must be а number!<br>"

validates_presence_of :name, :message => "Please specify а name!<br>"

validates_uniqueness_of :name, :message => "There is already а status with this name!<br>"

validates_length_of :name, :maximum => 100, :message => "The name cannot be bigger than 100 characters!<br>"

has_many :ticket

end

#-------------------------------------------------------------------------------------------------------ticket.rb

class Ticket < ActiveRecord::Base

validates_length_of :subject, :maximum => 50, :message => "Please specify а subject 50 characters or less."

#Relationships

belongs_to :user

belongs_to :category

belongs_to :ticketstatus

has_many :tickettexts

def text_content=(text) #this allows the form to CREATE а tick to have а field that will populate а tickettext object.

end

end

#----------------------------------------------------------------------------------------------------tickrtlog.rb

class Ticketlog < ActiveRecord::Base

# Relationships

belongs_to :user

belongs_to :ticket

# Validations

validates_numericality_of :user_id, :message => "user_id must be а number!"

validates_numericality_of :ticket_id, :message => "user_id must be а number!"

end

#-------------------------------------------------------------------------------------------------ticketstatus.rb

class Ticketstatus < ActiveRecord::Base

has_many :tickets

#-validations-

validates_numericality_of :id, :message => "The ID must be а number!<br>"

validates_presence_of :name, :message => "Please specify а name!<br>"

95

validates_uniqueness_of :name, :message => "There is already а status with this name!<br>"

7

02070743.00569-01 12 01

validates_length_of :name, :maximum => 100, :message => "The name cannot be bigger than 100 characters!<br>"

end

#---------------------------------------------------------------------------------------------------tickettext.rb

class Tickettext < ActiveRecord::Base

#Relationships

belongs_to :ticket

belongs_to :user

end

#---------------------------------------------------------------------------------------------------------user.rb

class User < ActiveRecord::Base

require 'digest/sha2'

#Relationships

has_many :tickets

#---validations--

validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[а-z]{2,})$/i, :message => "Invalid email!" #make sure email format is correct

validates_uniqueness_of :email, :message => "This email address is already taken!<br>"

#this will comb through the database and make sure email is unique

validates_presence_of :first_name, :last_name, :message => "This field is required!"

validates_confirmation_of :password, :message => "Password Confirmation Error!"

#this will confirm the password, but you have to have an html input called password_confirmation

validates_length_of :email, :maximum => 255, :message => "Your Email address is too LONG!"

#-----------------------------------------------

#------------Login Authentication---------------

def self.authenticate(login, pass)

u=find(:first :conditions => ["email = ? and password_hash = ?", login, pass] ) #check email column with the pass arg

return nil if u.nil?

return u

end

#-----------------------------------------------

attr_accessor :password_confirmation, :password#these are the database columns, which are pulled from param

#--------Encrypt Password-------------------------

# make sure you're doing attr_accessor before this

def password=(pass)

@password = pass = password_confirmation

self.password_hash = Digest::SHA256.hexdigest(pass)

#Salt!

#self.salt = User.random_string(10) if !self.salt?

#self.password_hash = User.encrypt(@password, self.salt)

end

#-------------------------------------------------

end

96

Исходный код контролеров данных

Соседние файлы в папке Пример диплома специалиста