I am trying to add login functionality to a page in Umbraco 7. However, when using the controller (Html.BeginUmbracoForm<UmbLoginController>) I ALWAYS get redirected to the homepage. Which I do not want. I need the user remain on the page he was at when he logged in. How do I do this?
Do you get redirected when visiting the Login page or after the member has logged in?
How does your controller look like?
Normally I would save the url from which the user was redirected to login in a hidden field of my form and after sucessfull login redirect to the url of that page.
Sorry, other projects drew my attention for a bit.
Anyway, the moment I hit the login button, I get logged in and redirected to the homepage. As for the controIer I am using, it's one supplied by Umbraco. This is the entire view (it's the default code you get when selecting login template when creating a partial view in the settings section):
The UmbLoginController just redirects your member to the homepage.
Seems there is no way to change this behavior. So if you want more controller over this you have to implement the login on your own. Would recommend to have a look at Warren Buckleys package which is also available from nuget.
Sorry for the double post, but I wanted to add an additional question.
I have the following model:
public class BmMemberModel { [Required] public string Username { get; set; }
[Required] public string Password { get; set; }
public string loginRedirectUrl { get; set; }
public string logoutRedirectUrl { get; set; } }
And the following Controller:
public class BmMemberSurfaceController : SurfaceController { [HttpPost] public ActionResult MemberLogin([Bind(Prefix = "BmMemberModel")]BmMemberModel model) { if (ModelState.IsValid) { var m = Member.GetMemberFromLoginNameAndPassword(model.Username, model.Password); if (m != null) Member.AddMemberToCache(m); }
return CurrentUmbracoPage(); } }
And finally, my view:
{ var memberModel = new BmMemberModel(); } @using (Html.BeginUmbracoForm<BmMemberSurfaceController>("MemberLogin")) { memberModel.loginRedirectUrl = "";
Now, I am still somewhat new to the whole MVC thing, so maybe I am missing something obvious. But, whenever I hit submit, the model I get back is NULL and gives null reference exceptions in my controller. But, I kinda just changed the names of the version that is in Umbraco.
Okay, I figured out my problem! With the examples I read, it said that
[Bind(Prefix="BmMemberModel")]
would give all the elements in the form the prefix "BmMemberModel". This was wrong as I now found it. It means that it will only react to fields prefixed with "BmMemberModel". To get the fields prefixed, I just need to name the Model on the page "BmMemberModel".
Sorry if this is obvious or anything, but like I said, I am pretty new to the whole MVC thing and it threw me for quite a loop!
I'm sorry, this was a post from a little over 2 years ago. I do not have access to the code. Perhaps if you could post your view/model/controller we could help you figure it out?
Login surface controller
Hi all,
I am trying to add login functionality to a page in Umbraco 7. However, when using the controller (Html.BeginUmbracoForm<UmbLoginController>) I ALWAYS get redirected to the homepage. Which I do not want. I need the user remain on the page he was at when he logged in. How do I do this?
-Ferdy
Do you get redirected when visiting the Login page or after the member has logged in?
How does your controller look like?
Normally I would save the url from which the user was redirected to login in a hidden field of my form and after sucessfull login redirect to the url of that page.
Sorry, other projects drew my attention for a bit.
Anyway, the moment I hit the login button, I get logged in and redirected to the homepage. As for the controIer I am using, it's one supplied by Umbraco. This is the entire view (it's the default code you get when selecting login template when creating a partial view in the settings section):
So yeah, the controller "UmbLoginController" is the controller I am using, but I do not know what the code looks like.
Ok had a small look at the Umbraco source.
The UmbLoginController just redirects your member to the homepage.
Seems there is no way to change this behavior. So if you want more controller over this you have to implement the login on your own. Would recommend to have a look at Warren Buckleys package which is also available from nuget.
My colleague and I just came to the same conclusion and decided to go implement our own controller. Thanks for the suggestion though.
-Ferdy
Sorry for the double post, but I wanted to add an additional question.
I have the following model:
And the following Controller:
And finally, my view:
Now, I am still somewhat new to the whole MVC thing, so maybe I am missing something obvious. But, whenever I hit submit, the model I get back is NULL and gives null reference exceptions in my controller. But, I kinda just changed the names of the version that is in Umbraco.
What am I doing wrong/missing?
-Ferdy
Okay, I figured out my problem! With the examples I read, it said that
would give all the elements in the form the prefix "BmMemberModel". This was wrong as I now found it. It means that it will only react to fields prefixed with "BmMemberModel". To get the fields prefixed, I just need to name the Model on the page "BmMemberModel".
Sorry if this is obvious or anything, but like I said, I am pretty new to the whole MVC thing and it threw me for quite a loop!
-Ferdy
Hi Fredy
How does your complete solution look like. I am going through this right now and will need all heads up.
Have you used Partial view or just view ? and i didn't understand the last thing with model, can you show it ?
Hi Tajamal,
I'm sorry, this was a post from a little over 2 years ago. I do not have access to the code. Perhaps if you could post your view/model/controller we could help you figure it out?
-Ferdy
Hi Ferdy
Thanks
I am migrating my code to umbraco at the time and soon as i reach there i may post something.
/Tajamal
Glad you solved your problem.
Haven't used the [Bind]-thing before. New to me and don't know why you should use it. Will have a read on it.
is working on a reply...