Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Samples / PestControl / Castle.Applications.PestControl.Web / Controllers / HomeController.cs
blob3680748e529a52ea97c88ac1f8d252b16c8c81f3
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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
17 using System;
18 using System.Web;
19 using System.Web.Security;
21 using Castle.Core;
23 using Castle.MonoRail.Framework;
25 using Castle.Applications.PestControl.Model;
27 [Layout("default")]
28 public class HomeController : SmartDispatcherController
30 private PestControlModel _model;
32 public HomeController(PestControlModel model)
34 _model = model;
37 // Actions
39 public void Index()
43 public void Authentication()
45 Context.Flash["ErrorMessage"] = "You must authenticate first";
46 RenderView("index");
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.";
54 RenderView("index");
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");
65 else
67 User user = _model.Users.FindByEmail(email);
69 Session["user"] = user;
71 if (HasFromUrl)
73 Redirect( ObtainAndRemoveFromUrl() );
75 else
77 Redirect("dashboard", "index");
82 public void SignUp()
84 Redirect("registration", "signup");
87 private String ObtainAndRemoveFromUrl()
89 String url = (String) Session["FromUrl"];
90 Session.Remove("FromUrl");
91 return url;
94 private bool HasFromUrl
96 get { return Session.Contains("FromUrl"); }