コード例 #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    EmailAddressAttribute emailCheck = new EmailAddressAttribute();

                    if (emailCheck.IsValid(model.Email))
                    {
                        UserDataContext db = new UserDataContext();

                        CustSecurityController Secure = new CustSecurityController();
                        WebSecurity.CreateUserAndAccount(model.UserName, model.Password);

                        UserData dataProfile = new UserData(model.UserName, model.Email, model.Street, model.HouseNumber, model.City, model.PostalCode, null);

                        db.DBUserData.Add(dataProfile);
                        db.SaveChanges();

                        Secure.Create(new IPProfile(model.UserName, Request.UserHostAddress));
                        WebSecurity.Login(model.UserName, model.Password);
                        return RedirectToAction("Overview", "Page");
                    }
                    else
                    {
                        ModelState.AddModelError("", "The email address entered is not valid");
                    }
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #2
0
        public ActionResult Login(LoginModel model)
        {
            CustSecurityController Secure = new CustSecurityController();
            WebSecurity.Logout();

            //IP Check
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                if (Roles.IsUserInRole(model.UserName, "Admin"))
                {
                    if (CustSecurity.IPCheck(Secure.Details(model.UserName), Request.UserHostAddress))
                    {
                        return RedirectToAction("Index", "Dashboard");
                    }
                    else
                    {
                        WebSecurity.Logout();
                        Secure.createIPVerification(new IPProfile(model.UserName, Request.UserHostAddress));
                        ModelState.AddModelError("", "IP is not certified, an email has been sent to your account");
                        return View("~/Views/Account/Login.aspx", model);
                    }
                }

                // If we got this far, admin login failed, so you are just regular user
                return RedirectToAction("Overview", "Page");
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View("~/Views/Account/Login.aspx", model);
        }