Пример #1
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var customMembership = (CustomMembershipProvider)Membership.Provider;
            var membershipUser = customMembership.CreateUser(model);
            if (membershipUser == null)
            {
                ModelState.AddModelError(string.Empty, "This login already exists!");
                return View();
            }
            FormsAuthentication.SetAuthCookie(model.Login, false);
            return RedirectToAction("App", "Home");
        }
        public MembershipUser CreateUser(RegisterViewModel register)
        {
            if (usersDb.Get(u => u.Login == register.Login) != null)
            {
                return null;
            }

            var user = Mapper.Map<RegisterViewModel, User>(register);
            user.Account = accountsDb.Get(acc => acc.Name == "Base");
            user.Role = rolesDb.Get(u => u.Name == "user");
            user.Password = GetMD5Hash(user.Password);

            usersDb.Add(user);
            usersDb.Save();

            return GetUser(user.Login, false);
        }