コード例 #1
0
 public IActionResult Associate(int?characterId = null)
 {
     if (characterId == null)
     {
         return(RedirectToAction("ExternalLogin", "Authentication"));
     }
     else
     {
         _profileManager.AssociateCharacter(User, (int)characterId);
     }
     return(RedirectToAction("Index"));
 }
コード例 #2
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.UserName, Email = model.Email
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    if (TempData.Peek("AssociateCharacterWithRegistration") != null)
                    {
                        try
                        {
                            CharacterDetails character = JsonConvert.DeserializeObject <CharacterDetails>(TempData["AssociateCharacterWithRegistration"].ToString());
                            _profileManager.AssociateCharacter(user, character);
                        }
                        catch (Exception)
                        {
                            _logger.LogError("Unable to associate character when logging in with existing account");
                        }
                    }

                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

            return(View(model));
        }