I'm currently doing something similar, although I am using a completely 
different user system to what radiant uses as default (it's basically a 
modified version of acts_as_authenticated and authorization plugins).

All I've done so far is create some custom tags that allow me to show 
content based on a users roles...

--------------------
### USER TAGS ###
    current_user ||= request.session[:user] ? 
User.find(request.session[:user]) : nil

    # This creates the <r:current_user/> namespace.
    tag "current_user", :for => current_user, :expose => ['username',
                                                          'email',
                                                          'fullname',
                                                          'displayname',
                                                          'fistname',
                                                          'lastname']

    tag "if_current_user" do |tag|
      if current_user
        tag.expand
      end
    end

    tag "unless_current_user" do |tag|
      unless current_user
        tag.expand
      end
    end

    tag "if_user_has_role" do |tag|
      if current_user && (eval "current_user.is_#{tag.attr['role']}?")
        tag.expand
      end
    end
--------------------

and implement a basic login box that can be shown on all pages:

--------------------
class AccountBehavior < Behavior::Base

  register 'Account System'

  description %{
    The Account System behaviour allows users to sign-up, login and 
modify their account details
  }

  def find_page_by_url(url, live = true, clean = false)
    @action = url.sub(@page.url, '').sub(/\/$/, '')
    return @page
  end

  def render_page
    case @action
      when 'login'
        if request.post?
          process_login
        else
          render_standard_page
        end
      when 'logout'
        process_logout
      when 'register'
      else
        render_standard_page
    end
  end

  def render_standard_page
    lazy_initialize_parser_and_context
    if layout = @page.layout
      parse_object(layout)
    else
      render_page_part(:body)
    end
  end

  def process_login
    user = User.authenticate( request.parameters[:username], 
request.parameters[:password] )
    if user.nil?
      #flash.now[:error] = 'Supplied username or password is incorrect'
    else
      request.session[:user] = user.id
      render_standard_page
    end
  end

  def process_logout
    request.session[:user] = nil
    render_standard_page
  end

  def process_register
  end

  define_tags do

    url = request.request_uri unless request.nil?

    # This is just for creating the <r:account/> namespace.
    tag "account" do |tag|
      tag.expand
    end

  end

end
--------------------

my loginbox snippet then has the following:

--------------------
<div id="loginbox">

<r:if_current_user>
    <h2>Welcome back <r:current_user:fullname /></h2>
    <p class="info">Not <r:current_user:fullname />? Then please <a 
href="/account/logout">logout</a></p>
</r:if_current_user>

<r:unless_current_user>
    <h2>Existing User Login</h2>
    <form action="/account/login" method="POST">
        <p><label for="username">Username</label>
            <input type="text" name="username" class="textbox" 
maxlength="40" /></p>
        <p><label for="password">Password</label>
            <input type="password" name="password" class="textbox" 
maxlength="40" /></p>
        <div class="register">
          <a href="/account/login">Why register?</a>
        </div>
        <div class="buttons">
          <input type="submit" value="login >>" class="button" />
        </div>
    </form>
</r:unless_current_user>

</div>
--------------------

I have yet to code the registration form or the ability for users to 
modify their details. However, this does allow me to let admin users 
login directly from any page and once logged in have a direct link to 
the admin area.

Much of the above may be buggy and full of bad practices as I'm fairly 
new to Ruby, Rails and especially some of the more advanced stuff that 
is going on throughout radiant. I hope it provides some ideas though.

Kev

-- 
Posted via http://www.ruby-forum.com/.
_______________________________________________
Radiant mailing list
Radiant@lists.radiantcms.org
http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to