1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Framework
.ViewComponents
17 using System
.Security
.Principal
;
20 /// This component renders different inner
21 /// sections based on the current principal state (authenticated or not)
23 /// #blockcomponent(AuthenticatedContent)
25 /// Welcome back $context.CurrentUser.Identity.Name
28 /// Create your account by clicking here.
33 public class AuthenticatedContent
: ViewComponent
35 private const string LoggedSection
= "logged";
36 private const string NotLoggedSection
= "notlogged";
39 /// Called by the framework so the component can
40 /// render its content
42 public override void Render()
44 if (IsAuthenticated())
46 Context
.RenderSection(LoggedSection
);
50 Context
.RenderSection(NotLoggedSection
);
55 /// Implementor should return true only if the
56 /// <c>name</c> is a known section the view component
59 /// <param name="name">section being added</param>
61 /// <see langword="true"/> if section is supported
63 public override bool SupportsSection(string name
)
65 return name
== LoggedSection
|| name
== NotLoggedSection
;
68 private bool IsAuthenticated()
70 IPrincipal user
= EngineContext
.CurrentUser
;
72 return user
!= null && user
.Identity
!= null && user
.Identity
.IsAuthenticated
;