Esempio n. 1
0
        public ActionResult Register(RegisterModel model)
        {
            if (model.Password != model.ConfirmPassword)
            {
                ModelState.AddModelError("", "Потверждение введенного пароля не совпадает");
                return View(model);
            }
            model.UserName = Guid.NewGuid().ToString();

            backend.Objects.User fusr = backend.Objects.User.GetByEmail(model.Email);
            if (fusr != null)
            {
                ModelState.AddModelError("", "Логин занят");
                return View(model);
            }
            backend.Objects.User usr = new backend.Objects.User()
                {
                    Login = model.UserName,
                    Password = model.Password,
                    Email = model.Email
                };
            usr = backend.Objects.User.Insert(usr);
            backend.Objects.Employee e = new backend.Objects.Employee()
            {
                FamilyName = model.FamilyName,
                Name = model.FirstName,
                LastName = model.LastName
            };
            backend.Objects.Employee.Insert(usr, e);

            backend.MailInformer.SendAfterRegistration(usr);

            return RedirectToAction("Login");
            //throw new NotImplementedException();
            //if (ModelState.IsValid)
            //{
            //    // Attempt to register the user
            //    try
            //    {
            //        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);
        }
Esempio n. 2
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            Session["userId"] = null;
            backend.Objects.User usr = backend.Objects.User.GetByEmail(model.Email, model.Password);
            if (usr != null)
            {
                Session["userId"] = usr.Id;
                FormsAuthentication.SetAuthCookie(usr.Login, true);
                return RedirectToLocal(returnUrl);
            }
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
            //if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            //{
            //    return RedirectToLocal(returnUrl);
            //}

            //// If we got this far, something failed, redisplay form
            //ModelState.AddModelError("", "The user name or password provided is incorrect.");
            //return View(model);
            //throw new NotImplementedException();
        }