Пример #1
0
        public static bool CreateUserAndAccount(RegisterModel model)
        {
            User u = new User()
            {
                Name = model.Name,
                Surname = model.Surname,
                Email = model.Email,
                NTLogin = model.UserName,
                Password = CryptographyHelper.Encrypt(model.Password)
            };

            var objUser = TTRepository.GetUser(model.UserName);
            if (objUser != null)
                throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateUserName);

            objUser = TTRepository.GetUserByMail(model.Email);
            if (objUser != null)
                throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateEmail);

            var id = TTRepository.InsertUser(u);

            return true;
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    SecurityHelper.CreateUserAndAccount(model);
                    SecurityHelper.Login(model.UserName, model.Password);

                    //WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    //WebSecurity.Login(model.UserName, model.Password);
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

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