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
.Applications
.PestControl
.Web
.Controllers
19 using System
.Web
.Security
;
23 using Castle
.MonoRail
.Framework
;
25 using Castle
.Applications
.PestControl
.Model
;
28 public class HomeController
: SmartDispatcherController
30 private PestControlModel _model
;
32 public HomeController(PestControlModel model
)
43 public void Authentication()
45 Context
.Flash
["ErrorMessage"] = "You must authenticate first";
49 // This is a hack to avoid the infinite cycle with
50 // Asp.Net page processing
51 public void NotFound()
53 Context
.Flash
["ErrorMessage"] = "User not found or wrong password.";
57 public void Login(String email
, String passwd
)
59 if (!_model
.Users
.Authenticate(email
, passwd
))
61 // This is a hack to avoid the infinite cycle with
62 // Asp.Net page processing
63 Redirect("home", "NotFound");
67 User user
= _model
.Users
.FindByEmail(email
);
69 Session
["user"] = user
;
73 Redirect( ObtainAndRemoveFromUrl() );
77 Redirect("dashboard", "index");
84 Redirect("registration", "signup");
87 private String
ObtainAndRemoveFromUrl()
89 String url
= (String
) Session
["FromUrl"];
90 Session
.Remove("FromUrl");
94 private bool HasFromUrl
96 get { return Session.Contains("FromUrl"); }