コード例 #1
0
ファイル: AccountController.cs プロジェクト: dnmsk/rProject
        public ActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid) {
                var result = BusinessLogic.AccountProvider.RegisterWithEmail(CurrentUser.GuestID, model.Email,
                    model.Password);
                if (result) {
                    var accountID = BusinessLogic.AccountProvider.LoginWithEmail(model.Email, model.Password);
                    CurrentUser = new SessionModule(CurrentUser.GuestID, accountID.Item2);
                    return RedirectToAction("Index", "Home");
                }
            }

            return View(model);
        }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: dnmsk/rProject
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            //ModelState.AddModelError("", error);
            if (!ModelState.IsValid) {
                return View(model);
            }

            var guestAndAccount = BusinessLogic.AccountProvider.LoginWithEmail(model.Email, model.Password);
            if (guestAndAccount != null) {
                CurrentUser = new SessionModule((int) guestAndAccount.Item1, guestAndAccount.Item2);
                return RedirectToLocal(returnUrl);
            }
            ModelState.AddModelError("", "Неверный логин/пароль.");
            return View(model);
        }
コード例 #3
0
ファイル: SessionModuleTest.cs プロジェクト: dnmsk/rProject
 public void SerializeSessionModuleTest(int accountID, int guestID, string expected)
 {
     var actual = new SessionModule(guestID, accountID).ModuleToString();
     Assert.AreEqual(expected, actual);
 }
コード例 #4
0
ファイル: SessionModuleTest.cs プロジェクト: dnmsk/rProject
 public void IsAthenticatedTest()
 {
     var actual = new SessionModule(13, 31);
     Assert.True(actual.IsAuthenticated());
 }
コード例 #5
0
ファイル: AccountController.cs プロジェクト: dnmsk/rProject
        public ActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid) {
                var result = BusinessLogic.AccountProvider.RegisterWithEmail(CurrentUser.GuestID, model.Email, model.Password);// UserManager.Create(user, model.Password);
                if (result) {
                    var accountID = BusinessLogic.AccountProvider.LoginWithEmail(model.Email, model.Password);
                    CurrentUser = new SessionModule((int) accountID.Item1, accountID.Item2);
                    //SignInManager.SignIn(user, false, false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(new[] {
                    "Error register with email and password"
                });
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #6
0
ファイル: AccountController.cs プロジェクト: dnmsk/rProject
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            var loginModel = new LoginViewModel(this, model);
            if (!ModelState.IsValid) {
                return View(loginModel);
            }

            var loginResult = BusinessLogic.AccountProvider.LoginWithEmail(model.Email, model.Password);
            if (loginResult != null) {
                CurrentUser = new SessionModule((int)loginResult.Item1, loginResult.Item2);
                return RedirectToLocal(returnUrl);
            }

            ModelState.AddModelError("", "Invalid login attempt.");
            return View(loginModel);
            /*
            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = SignInManager.PasswordSignIn(loginModel.Email, loginModel.Password, loginModel.RememberMe, false);
            switch (result) {
                case SignInStatus.Success:
                    return RedirectToLocal(returnUrl);
                case SignInStatus.LockedOut:
                    return View("Lockout");
                case SignInStatus.RequiresVerification:
                    return RedirectToAction("SendCode", new {ReturnUrl = returnUrl, loginModel.RememberMe});
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", "Invalid login attempt.");
                    return View(loginModel);
            }
            */
        }