public ActionResult LogOn(LogOnViewModel model)
        {
            model.Settings = this.Settings;
            var email = model.Email.ToLower();
            var playerCollection = this.Dbh.GetCollection<Player>("Players");
            var player = playerCollection.FindOne(Query.EQ("Email", email));

            if (player != null)
            {
                if (player.Password == Md5.CalculateMd5(model.Password))
                {
                    if (AutoLogin(player))
                    {
                        return Redirect(model.RefUrl);
                    }
                }
            }

            model.LogOnError = true;
            return View(model);
        }
        public ActionResult LogOn()
        {
            if (Session["IsLoggedIn"] == null || Session["IsLoggedIn"].ToString() == "false")
            {
                var authCookie = this.Request.Cookies.Get("RankTangleAuth");
                if (authCookie != null && authCookie["Token"] != null)
                {
                    var autoLoginCollection = this.Dbh.GetCollection<AutoLogin>("AutoLogin");
                    var autoLoginToken = autoLoginCollection.FindOne(Query.EQ("Token", authCookie["Token"]));

                    if (autoLoginToken != null)
                    {
                        var playerCollection = this.Dbh.GetCollection<Player>("Players");
                        var player = playerCollection.FindOne(Query.EQ("Email", autoLoginToken.Email.ToLower()));

                        if (AutoLogin(player))
                        {
                            // Go back to where we were before logging in
                            var referrer = this.Request.UrlReferrer;
                            if (referrer != null)
                            {
                                return this.Redirect(referrer.ToString());
                            }
                        }
                    }
                }
            }

            var urlReferrer = this.Request.UrlReferrer;

            if (urlReferrer != null)
            {
                var viewModel = new LogOnViewModel { RefUrl = urlReferrer.ToString(), Settings = this.Settings };

                return this.View(viewModel);
            }

            return RedirectToAction("Index", "Home");
        }