Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'authenticated_user'
- class User < WebFront
- include LoginEngine::AuthenticatedUser
- validates_captcha :on => :create
- has_many :comments
- has_many :forums
- has_many :prefrences
- has_one :user_pin
- has_many :portfolios
- end
- # authenticated_user.rb
- require 'digest/sha1'
- # this model expects a certain database layout and its based on the name/login pattern.
- # how does authenticate works here
- # you pass the password to the model and using username it picks the password and corresponding salt
- # for that user. Both are already encrypted and it used method self.hashed to hash the thing and
- # compare against the value stored in the database.
- module LoginEngine
- module AuthenticatedUser
- def self.included(base)
- base.class_eval do
- # use the table name given
- attr_accessor :new_password
- validates_presence_of :firstname
- validates_presence_of :lastname
- validates_presence_of :country
- validates_presence_of :city
- validates_presence_of :pincode
- validates_presence_of :state
- validates_length_of :login, :within => 3..40
- validates_length_of :addr_line1, :within => 4..40
- validates_uniqueness_of :login
- validates_uniqueness_of :email
- validates_format_of :email, :with => /^[^@]+@.+$/
- #validates_numericality_of :pincode
- validates_presence_of :password, :if => :validate_password?
- validates_confirmation_of :password, :if => :validate_password?
- validates_length_of :password, { :minimum => 5, :if => :validate_password? }
- validates_length_of :password, { :maximum => 40, :if => :validate_password? }
- protected
- attr_accessor :password, :password_confirmation
- after_save :falsify_new_password
- after_validation :crypt_password
- end
- base.extend(ClassMethods)
- end
- # COntroller code:
- def signup_user
- @user = User.new(params[:user])
- @user.new_password = true
- @user.verified = 1 unless $account_info[:use_email_notification]
- if @user.save
- key = @user.generate_security_token
- url = url_for(:action => 'verify_users', :user_id => @user.id, :key => key)
- flash[:success] = 'Signup successful!'
- if $account_info[:use_email_notification]
- UserNotify.deliver_signup(@user, params[:user][:password], url)
- flash[:success] << ' Please check your registered email account to verify your account registration and continue with login.'
- else
- flash[:success] << ' Please log in.'
- end
- redirect_to :action => 'login'
- else
- logger.info "Errors while submitting the page"
- flash[:invalid] = @user.errors.full_messages
- $stock.log_error flash[:invalid]
- render :partial => "signup_form",:status => 444
- end
- @user[:captcha_validation] = ""
- end
Add Comment
Please, Sign In to add comment