public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new UserEntity()
                {
                    Login = model.UserName,
                    E_mail = model.UserEmail,
                    Password = model.Password,
                    Role_Id = 2
                };

                MembershipUser membershipUser = ((CustomMembershipProvider)Membership.Provider).CreateUser(user);

                if (membershipUser != null)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", "Registration error.");
                }
            }
            return View(model);
        }
 public ActionResult Create(RegisterModel user)
 {
     
     var blluser = new UserEntity()
     {
         Login = user.UserName,
         Role_Id = 2, // user
         RegistryDate = DateTime.Now,
         Password = "******",
         E_mail = "12345"                
     };
     service.Create(blluser);
     return RedirectToAction("Index");
 }
Esempio n. 3
0
        public ActionResult Register(RegisterModel viewModel)
        {
            if (viewModel.Captcha != (string)Session[CaptchaImage.CaptchaValueKey])
            {
                ModelState.AddModelError("Captcha", "Captcha Image is incorrect, try again");
                return View(viewModel);
            }
            var anyUser = userService.GetAllEntities().Any(u => u.Email.Contains(viewModel.Email));
            if (anyUser)
            {
                ModelState.AddModelError("Email", "The email is already used");
                return View(viewModel);
            }

            if (ModelState.IsValid)
            {
                MembershipUser membershipUser = ((CustomMembershipProvider)Membership.Provider).CreateUser(viewModel.Email, viewModel.Password);
                if (membershipUser != null)
                {
                    FormsAuthentication.SetAuthCookie(viewModel.Email, false);
                    return RedirectToAction("Index", "File");
                }
                else
                    ModelState.AddModelError("", "Error with registration");
            }
            return View(viewModel);
        }