コード例 #1
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (model.UserName.Length > 16 || model.UserName.Length < 6)
            {
                ModelState.AddModelError("UserName", "The username should be between 6 and 16 characters long.");
            }

            if (ModelState.IsValid)
            {
                // Create a local login before signing in the user
                var user = new ApplicationUser { UserName = model.UserName, Points = 10};
                var result = await IdentityManager.Users.CreateLocalUserAsync(user, model.Password);
                if (result.Success)
                {
                    await IdentityManager.Authentication.SignInAsync(AuthenticationManager, user.Id, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #2
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Create a local login before signing in the user
                var user = new ApplicationUser(model.UserName);
                var result = await IdentityManager.Users.CreateLocalUserAsync(user, model.Password);
                if (result.Success)
                {
                    await IdentityManager.Authentication.SignInAsync(AuthenticationManager, user.Id, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

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