checkbox to allow autosign in

Topics: Core, General, Writing modules
Feb 19, 2012 at 12:40 AM

Hi:

I am currently developing a website for world-wide use amongst the education community. One of the clients requirements is to have a remember me checkbox on the signin page.

I have a few questions:

Firstly, has anybody already got such a system working?

secondly I'm quite happy to write this and then submit a patch, where is the IAuthenticationService implemented? if I can find this, I shouldn't have a problem. Also do I have access to the response object directly or do I have to go through something that is orchard specific to gain access?

Help apreciated as always.

Regards

Sean.

Coordinator
Feb 19, 2012 at 1:29 AM

That should be easily done as a module.

Feb 19, 2012 at 11:57 AM

Hi:

Ok, how do I add to the signin page? And replace the login method of the account controller. Given that this si a one line change and most sites have this shouldn’t this be a cure feature?

Cheers

Sean.

From: bertrandleroy [email removed]
Sent: 19 February 2012 02:30
To: Sean Farrow
Subject: Re: checkbox to allow autosign in [orchard:325827]

From: bertrandleroy

That should be easily done as a module.

Coordinator
Feb 20, 2012 at 12:27 AM
You can probably override the template for it in your theme.

Everybody has a different idea about what should be a core feature. That's why we limit ourselves to building a core that people can build around. If something can be built as a module, chances are we won't include it in core.

In this specific instance, it must not be that important to most people as there isn't a module yet implementing it ;)

Thanks,
Bertrand

From: SeanFarrow [notifications@codeplex.com]
Sent: Sunday, February 19, 2012 4:57 AM
To: Bertrand Le Roy
Subject: Re: checkbox to allow autosign in [orchard:325827]

From: SeanFarrow

Hi:

Ok, how do I add to the signin page? And replace the login method of the account controller. Given that this si a one line change and most sites have this shouldn’t this be a cure feature?

Cheers

Sean.

From: bertrandleroy [email removed]
Sent: 19 February 2012 02:30
To: Sean Farrow
Subject: Re: checkbox to allow autosign in [orchard:325827]

From: bertrandleroy

That should be easily done as a module.

Feb 20, 2012 at 7:29 AM

Hi:

Very true!

Ok, I think I know how I’m going to do this, one final question though.

I have an html snippet representing my checkbox, is it possible with clay to inject between two of the list items In the current logon shape, or should I just write a new page?

Cheers

Sean.

From: BertrandLeRoy [email removed]
Sent: 20 February 2012 01:27
To: Sean Farrow
Subject: Re: checkbox to allow autosign in [orchard:325827]

From: BertrandLeRoy

You can probably override the template for it in your theme.

Everybody has a different idea about what should be a core feature. That's why we limit ourselves to building a core that people can build around. If something can be built as a module, chances are we won't include it in core.

In this specific instance, it must not be that important to most people as there isn't a module yet implementing it ;)

Thanks,

Bertrand


From: SeanFarrow [notifications@codeplex.com]
Sent: Sunday, February 19, 2012 4:57 AM
To: Bertrand Le Roy
Subject: Re: checkbox to allow autosign in [orchard:325827]

From: SeanFarrow

Hi:

Ok, how do I add to the signin page? And replace the login method of the account controller. Given that this si a one line change and most sites have this shouldn’t this be a cure feature?

Cheers

Sean.

From: bertrandleroy [email removed]
Sent: 19 February 2012 02:30
To: Sean Farrow
Subject: Re: checkbox to allow autosign in [orchard:325827]

From: bertrandleroy

That should be easily done as a module.

Coordinator
Feb 20, 2012 at 7:31 AM
I think it's possible but I'm not 100% sure.

From: SeanFarrow [notifications@codeplex.com]
Sent: Monday, February 20, 2012 12:29 AM
To: Bertrand Le Roy
Subject: Re: checkbox to allow autosign in [orchard:325827]

From: SeanFarrow

Hi:

Very true!

Ok, I think I know how I’m going to do this, one final question though.

I have an html snippet representing my checkbox, is it possible with clay to inject between two of the list items In the current logon shape, or should I just write a new page?

Cheers

Sean.

From: BertrandLeRoy [email removed]
Sent: 20 February 2012 01:27
To: Sean Farrow
Subject: Re: checkbox to allow autosign in [orchard:325827]

From: BertrandLeRoy

You can probably override the template for it in your theme.

Everybody has a different idea about what should be a core feature. That's why we limit ourselves to building a core that people can build around. If something can be built as a module, chances are we won't include it in core.

In this specific instance, it must not be that important to most people as there isn't a module yet implementing it ;)

Thanks,

Bertrand


From: SeanFarrow [notifications@codeplex.com]
Sent: Sunday, February 19, 2012 4:57 AM
To: Bertrand Le Roy
Subject: Re: checkbox to allow autosign in [orchard:325827]

From: SeanFarrow

Hi:

Ok, how do I add to the signin page? And replace the login method of the account controller. Given that this si a one line change and most sites have this shouldn’t this be a cure feature?

Cheers

Sean.

From: bertrandleroy [email removed]
Sent: 19 February 2012 02:30
To: Sean Farrow
Subject: Re: checkbox to allow autosign in [orchard:325827]

From: bertrandleroy

That should be easily done as a module.

Feb 20, 2012 at 10:08 AM

No it's not possible; and in any case, you'll need your own controller to handle the posted value.

Feb 20, 2012 at 10:09 AM

Hi:

Thanks pete.

Sean.

From: randompete [email removed]
Sent: 20 February 2012 11:08
To: Sean Farrow
Subject: Re: checkbox to allow autosign in [orchard:325827]

From: randompete

No it's not possible; and in any case, you'll need your own controller to handle the posted value.

Feb 20, 2012 at 12:49 PM

Hi:

Just looking at this again, it seems that this is made ahrder than it needs to be. Ideally I would inherit from the account controller—unfortunately it’s not virtual.

Any chance of making controllers virtual? I only need to change one method, but am forced currently to rewrite a whole controller. Also, how is the signlink displayed, it is constructed in a migration—I’m using the 1.4 development branch, so this might make a difference as to how the sign in link is produced on the homepage.

Cheers

Sean.

From: randompete [email removed]
Sent: 20 February 2012 11:08
To: Sean Farrow
Subject: Re: checkbox to allow autosign in [orchard:325827]

From: randompete

No it's not possible; and in any case, you'll need your own controller to handle the posted value.

Coordinator
Feb 21, 2012 at 2:24 AM

You should never inherit from a controller, so no. What you can do instead is override the route to point it to your own controller. Just create a new one in your own route provider, with a higher priority.

Feb 21, 2012 at 12:30 PM

The sign in link comes from the User shape  I think, this gets manually added into a zone in your Layout.cshtml.

Feb 21, 2012 at 1:17 PM

By the way - my personal opinion is that this should be in core, it's something that literally all websites just have. Admittedly I didn't particularly notice it wasn't there until pointed out - but yeah it'd be useful, and I'm sure sooner or later a client will ask why it's not there.

Feb 21, 2012 at 2:59 PM

I agree too that it should be in core. I haven't needed it myself yet, but I'm sure that very soon my business analysts will ask for this checkbox. Every site I've worked on has had this, and most that i use have it as well. 

Feb 21, 2012 at 3:01 PM

SeanFarrow, anything you can do with inheritance can also be achieved with composition, so you might be able to make your own controller that has an instance of the one you wanted to inherit. Just make the actions call the "base" Controller's, and add your own functionality to the method you want to inherit. 

Coordinator
Feb 21, 2012 at 5:45 PM

This feature was implemented but removed at the last moment because we didn't have time to test it completely. If you want to file a bug and provide a patch, here is the patch ;)

 

diff -r 4b5c42b7c871 src/Orchard.Web/Modules/Orchard.Users/Controllers/AccountController.cs
--- a/src/Orchard.Web/Modules/Orchard.Users/Controllers/AccountController.cs	Mon Feb 20 13:58:43 2012 -0800
+++ b/src/Orchard.Web/Modules/Orchard.Users/Controllers/AccountController.cs	Tue Feb 21 10:45:02 2012 -0800
@@ -79,14 +79,14 @@
         [HttpPost]
         [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
             Justification = "Needs to take same parameter type as Controller.Redirect()")]
-        public ActionResult LogOn(string userNameOrEmail, string password, string returnUrl) {
+        public ActionResult LogOn(string userNameOrEmail, string password, string returnUrl, bool rememberMe) {
             var user = ValidateLogOn(userNameOrEmail, password);
             if (!ModelState.IsValid) {
                 var shape = _orchardServices.New.LogOn().Title(T("Log On").Text);
                 return new ShapeResult(this, shape); 
             }
 
-            _authenticationService.SignIn(user, false);
+            _authenticationService.SignIn(user, rememberMe);
             foreach (var userEventHandler in _userEventHandlers) {
                 userEventHandler.LoggedIn(user);
             }
diff -r 4b5c42b7c871 src/Orchard.Web/Modules/Orchard.Users/Views/LogOn.cshtml
--- a/src/Orchard.Web/Modules/Orchard.Users/Views/LogOn.cshtml	Mon Feb 20 13:58:43 2012 -0800
+++ b/src/Orchard.Web/Modules/Orchard.Users/Views/LogOn.cshtml	Tue Feb 21 10:45:02 2012 -0800
@@ -27,6 +27,9 @@
         @Html.Password("password")
         @Html.ValidationMessage("password")
     </li>
+    <li>
+        @Html.CheckBox("rememberMe", new { id = "remember-me" })<label class="forcheckbox" for="remember-me">@T("Remember me?")</label>
+    </li>
     <button class="primaryAction" type="submit">@T("Sign In")</button>
     </ol>
 </fieldset>


 

Feb 29, 2012 at 1:28 PM

Hi:

I now have a patch for this. Should I be using the default codeplex branch or the 1.x branch (which I’m using for current sites given 1.4 isn’t to far away.)

Cheers

Sean.

From: sebastienros [email removed]
Sent: 21 February 2012 18:46
To: Sean Farrow
Subject: Re: checkbox to allow autosign in [orchard:325827]

From: sebastienros

This feature was implemented but removed at the last moment because we didn't have time to test it completely. If you want to file a bug and provide a patch, here is the patch ;)

diff -r 4b5c42b7c871 src/Orchard.Web/Modules/Orchard.Users/Controllers/AccountController.cs
--- a/src/Orchard.Web/Modules/Orchard.Users/Controllers/AccountController.cs       Mon Feb 20 13:58:43 2012 -0800
+++ b/src/Orchard.Web/Modules/Orchard.Users/Controllers/AccountController.cs       Tue Feb 21 10:45:02 2012 -0800
@@ -79,14 +79,14 @@
         [HttpPost]
         [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
             Justification = "Needs to take same parameter type as Controller.Redirect()")]
-        public ActionResult LogOn(string userNameOrEmail, string password, string returnUrl) {
+        public ActionResult LogOn(string userNameOrEmail, string password, string returnUrl, bool rememberMe) {
             var user = ValidateLogOn(userNameOrEmail, password);
             if (!ModelState.IsValid) {
                 var shape = _orchardServices.New.LogOn().Title(T("Log On").Text);
                 return new ShapeResult(this, shape); 
             }
 
-            _authenticationService.SignIn(user, false);
+            _authenticationService.SignIn(user, rememberMe);
             foreach (var userEventHandler in _userEventHandlers) {
                 userEventHandler.LoggedIn(user);
             }
diff -r 4b5c42b7c871 src/Orchard.Web/Modules/Orchard.Users/Views/LogOn.cshtml
--- a/src/Orchard.Web/Modules/Orchard.Users/Views/LogOn.cshtml      Mon Feb 20 13:58:43 2012 -0800
+++ b/src/Orchard.Web/Modules/Orchard.Users/Views/LogOn.cshtml      Tue Feb 21 10:45:02 2012 -0800
@@ -27,6 +27,9 @@
         @Html.Password("password")
         @Html.ValidationMessage("password")
     </li>
+    <li>
+        @Html.CheckBox("rememberMe", new { id = "remember-me" })<label class="forcheckbox" for="remember-me">@T("Remember me?")</label>
+    </li>
     <button class="primaryAction" type="submit">@T("Sign In")</button>
     </ol>
 </fieldset>
 
 

Coordinator
Feb 29, 2012 at 2:56 PM

Please use the 1.x as. Even though it should be merge to default in a few hours

Feb 29, 2012 at 5:28 PM

Hi:

Ok, given that codeplex mercurial were down when I wrote this, what is the easiest way of getting the patch to the orchard team?

Also where is orchards default IAuthenticationService implemented, I carn’t seem to find this anywhere.

Cheers

Sean.

From: sebastienros [email removed]
Sent: 29 February 2012 15:56
To: Sean Farrow
Subject: Re: checkbox to allow autosign in [orchard:325827]

From: sebastienros

Please use the 1.x as. Even though it should be merge to default in a few hours

Coordinator
Feb 29, 2012 at 5:31 PM

you can wait for the source control to be back, we won't take it right now, because we are working on the 1.4 release, and it won't make it to 1.4 as it is too risky now. But yeah, nice addition !!

Feb 29, 2012 at 7:03 PM
SeanFarrow wrote:

Also where is orchards default IAuthenticationService implemented, I carn’t seem to find this anywhere.

 

http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-part-8

Developer
Feb 29, 2012 at 7:08 PM
infofromca wrote:
SeanFarrow wrote:

Also where is orchards default IAuthenticationService implemented, I carn’t seem to find this anywhere.

 

http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-part-8


 

The default implementation of IAuthenticationService can be found in Orchard.Framework, in the folder Security\Providers, and is called FormsAuthenticationService.

The full typename is:

Orchard.Security.Providers.FormsAuthenticationService