Sha256: bfad42b75cc1c84bba700707183e99df89bc00594a20c070a550dc778232d401

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

module Cms

  # Represents a CMS users that is managed through the CMS UI.
  class User < PersistentUser
    include Devise::Models::Validatable
    include Devise::Models::Recoverable

    class << self
      # Change a given user's password.
      #
      # @param [String] login
      # @param [String] new_password
      def change_password(login, new_password)
        find_by_login(login).change_password(new_password)
      end

      def permitted_params
        super + [:password, :password_confirmation]
      end
    end

    # Generate a new random password for this user.
    # @return [String] The newly generated and assigned password
    def new_password
      pwd = SecureRandom.hex(4)
      change_password(pwd)
      pwd
    end

    # Change this User's password to a new value.
    def change_password(new_password)
      update(:password => new_password, :password_confirmation => new_password)
      new_password
    end

    # By default, Users are coming from the the CMS database (cms_users). All Cms::User class have have the same source.
    #
    # @override #source The otherwise persistent attribute.
    def source
      "CMS Users"
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
browsercms-artirix-4.0.0.rc1.art4 app/models/cms/user.rb
browsercms-4.0.0.rc1 app/models/cms/user.rb
browsercms-4.0.0.beta app/models/cms/user.rb