Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sami 7 posts 27 karma points
    Jan 14, 2013 @ 13:03
    Sami
    0

    Members / Login

    Hi,

    I have a basic site and would like to password protect it.   I tried Razor login but didnt get anywhere with it sadly.

    I'm trying to use the http://www.mortenbock.dk/blog/2009/04/01/setting-up-membership-in-umbraco.aspx solution which seems to be working for a lot of people.

    So I followed the post and have created template/members and protected a page.   When I try to view the page I'm presented with the login page,  so far so good.     After I enter my username / password the login page simply reloads and does not display the protected content.

    Would appreciate any suggestions....

    Sami

     

  • Edwin van Koppen 156 posts 270 karma points
    Jan 16, 2013 @ 16:46
    Edwin van Koppen
    0

    I just make a child action like this:

    @{
        Layout = null;
    }
    <form method="post">
        @if (!String.IsNullOrEmpty(ViewBag.LoginError)) {
            <div style="color:red">@ViewBag.LoginError</div>
        }
        @if(String.IsNullOrEmpty(ViewBag.Username)){
            <div><label for="name">Username:</label>
            <input type="text" id="username" name="username"/></div>
            <div><label for="password">Password:</label>
            <input type="password" id="password" name="password"/></div>
            <div><input type="submit" id="submit" name="submit" value="login"/></div>
        } else {
            @ViewBag.Username
            <input type="submit" id="submit" name="submit" value="logout"/>
        }
    </form>

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Security;
    using Umbraco.Web.Mvc;

    namespace W3S.Controllers
    {
        public class LoginController : SurfaceController
        {
            //
            // GET: /Login/
            public ActionResult Login() {
                MembershipUser msUser = Membership.GetUser();
                if (msUser != null) {
                    ViewBag.Username = msUser.UserName;
                }
                return View();
            }
            [HttpPost]
            public ActionResult Login(String username, String password) {
                MembershipUser msUser = Membership.GetUser();
                if (msUser == null) {
                    if (Membership.ValidateUser(username, password)) {
                        FormsAuthentication.SetAuthCookie(username, true);
                        Response.Redirect("/");
                    } else {
                        ViewBag.LoginError = "no user found!";
                    }
                } else {
                    ViewBag.Username = msUser.UserName;

                    if (Request["submit"] == "logout") {
                        FormsAuthentication.SignOut();
                        Response.Redirect("/");
                    }
                }
                return View();
            }

        }
    }

     

     

     

  • Sami 7 posts 27 karma points
    Jan 17, 2013 @ 12:18
    Sami
    0

    Thank you very much for your reply.   How should I use this (sorry, im not a web developer) to allow access to the site ?

     

  • Edwin van Koppen 156 posts 270 karma points
    Jan 17, 2013 @ 14:28
    Edwin van Koppen
    0

    If you're no developer then it's not so easy to build.. sorry don't know any module for it because it's so easy to develop for me!

  • Sami 7 posts 27 karma points
    Jan 17, 2013 @ 15:09
    Sami
    0

    Perhaps you could point me in the right direction ?         Not a developer;  have plenty enthusiasm.

     

  • Edwin van Koppen 156 posts 270 karma points
    Jan 17, 2013 @ 17:14
    Edwin van Koppen
    0

    I write Umbraco code in a real developer way, it's not really possible to do it in a little post on a forum :)

Please Sign in or register to post replies

Write your reply to:

Draft