public async Task <JsonResult> Post([FromBody] UserGame value) { if (value == null) { return(Json(SimpleResponse.Error("Invalid value"))); } var claims = User.Claims; var claim = claims.FirstOrDefault(x => x.Type == CustomClaimTypes.OwnsUserGame); int id = int.Parse(claim.Value); if (id != value.Id) { return(Json(SimpleResponse.Error("Invalid value"))); } var userGame = await _repo.GetUserGame(id); if (userGame != null) { var result = await _repo.ReplaceUserGame(id, value); return(Json(SimpleResponse.Success())); } else { await _repo.AddUserGame(value); return(Json(SimpleResponse.Success())); } }
private async Task <ApplicationUser> AutoRegister(LoginViewModel model) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; user.Claims.Add(new MongoClaim { Type = CustomClaimTypes.CanUseApi, Value = "", Issuer = "AutoRegister" }); user.Claims.Add(new MongoClaim { Type = CustomClaimTypes.OwnsUserGame, Value = user.Id.ToString(), Issuer = "AutoRegister" }); var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password through api AutoRegister."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id.ToString(), code, Request.Scheme); await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl); await _userGameRepo.AddUserGame(new UserGame() { Id = user.Id }); return(user); } AddErrors(result); return(null); }