public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Home");
            }

            ViewBag.LogOnError = null;
            if (ModelState.IsValid)
            {
                AccServ.Account acc = new AccServ.Account();
                AccServ.WebResultOfstringAccountDatalrs4Oh3P logon = acc.Login(model.UserName, model.Password);
                if (logon.ErrorCode == AccServ.WebResultErrorCodeList.SUCCESS)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, true);
                    HttpCookie auth = FormsAuthentication.GetAuthCookie(model.UserName, true);
                    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(auth.Value);
                    FormsAuthenticationTicket nticket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, logon.Value1);
                    auth.Value = FormsAuthentication.Encrypt(nticket);
                    Response.Cookies.Add(auth);

                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ViewBag.LogOnError = logon.ErrorCode.ToString();
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public ActionResult Register(RegisterModel model)
        {
            if (User.Identity.IsAuthenticated)
                return RedirectToAction("Index", "Home");

            ViewBag.RegisterError = null;
            if (ModelState.IsValid)
            {
                AccServ.Account acc = new AccServ.Account();
                AccServ.WebResult register = acc.Register(model.UserName, model.Email, model.Password);

                // Attempt to register the user
                if (register.ErrorCode.ToString() == "SUCCESS")
                {
                    AccServ.WebResultOfstringAccountDatalrs4Oh3P logon = acc.Login(model.UserName, model.Password);
                    if (logon.ErrorCode == AccServ.WebResultErrorCodeList.SUCCESS)
                    {
                        FormsAuthentication.SetAuthCookie(model.UserName, true);
                        HttpCookie auth = FormsAuthentication.GetAuthCookie(model.UserName, true);
                        FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(auth.Value);
                        FormsAuthenticationTicket nticket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, logon.Value1);
                        auth.Value = FormsAuthentication.Encrypt(nticket);
                        Response.Cookies.Add(auth);

                        return RedirectToAction("Index", "Home");
                    }
                    else
                        ViewBag.RegisterError = register.ErrorCode.ToString();
                }
                else
                    ViewBag.RegisterError = register.ErrorCode.ToString();
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }