public async Task <IActionResult> PutPushToken(int id, PushToken pushToken) { if (id != pushToken.Id) { return(BadRequest()); } _context.Entry(pushToken).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PushTokenExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <PushToken> > PostPushToken(PushToken pushToken) { _context.Token.Add(pushToken); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPushToken", new { id = pushToken.Id }, pushToken)); }
//[Authorize(Roles = "admin")]///测试方法 public string GetMyToken() { //var claimsIdentity= this.User.Identity as ClaimsIdentity; //var userId= claimsIdentity.FindFirst(ClaimTypes.Name) var myClaims = this.User.Claims; string Authorization = ""; if (myClaims != null) { Authorization = PushToken.PushMyToken(configuration, myClaims); } return(Authorization); var myId = myClaims?.FirstOrDefault(c => c.Type.Equals("id", StringComparison.OrdinalIgnoreCase))?.Value; return(myId); //var schemeProvider = accessor.HttpContext.RequestServices.GetService(typeof(IAuthenticationSchemeProvider)) as IAuthenticationSchemeProvider; //var defaultAuthenticate = schemeProvider.GetDefaultAuthenticateSchemeAsync(); //if (defaultAuthenticate != null) //{ // var result = await accessor.HttpContext.AuthenticateAsync(defaultAuthenticate.Name); // var user = result?.Principal; // if (user != null) // { // account = user.Identity.Name; // } //} }
/// <summary> /// Registers a push token for the current user and application. /// Documentation https://developers.google.com/games/v1/reference/pushtokens/update /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Games service.</param> /// <param name="body">A valid Games v1 body.</param> /// <param name="optional">Optional paramaters.</param> public static void Update(GamesService service, PushToken body, PushtokensUpdateOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } // Building the initial request. var request = service.Pushtokens.Update(body); // Applying optional parameters to the request. request = (PushtokensResource.UpdateRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. request.Execute(); } catch (Exception ex) { throw new Exception("Request Pushtokens.Update failed.", ex); } }
public async Task <IActionResult> registlogin([FromForm] RegistLogin regist) { string key = $"Email{ regist.email}"; if (db.KeyExists(key)) { RegistGetDb registGetDb = RedisHelper.ConvertFromRedis <RegistGetDb>(await db.HashGetAllAsync(key)); if (registGetDb.guid == regist.guid) { User user = userRepository.Register(registGetDb.pwd); IEnumerable <Claim> claims = new Claim[] { new Claim("id", user.Id.ToString()), new Claim(ClaimTypes.Role, "admin") }; string jwtToken = PushToken.PushMyToken(configuration, claims); if (user.Id != 0) { return(Ok(new AjaxResult() { status = "ok", result = new { Id = user.Id, Name = user.Name, Authorization = jwtToken } })); } } } return(BadRequest(new AjaxResult() { status = "err" })); }
public async Task DeleteToken() { var value = "token"; var userId = 1; var tokenType = PushTokenType.Android; var token = new PushToken { Value = value, Type = tokenType, UserId = userId }; Suite.PushTokenRepositoryMock .Setup(m => m.ByValue(value)) .ReturnsAsync(token); var result = await Suite.PushTokenService.DeleteToken(value, tokenType, userId); Suite.PushTokenRepositoryMock .Setup( m => m.Remove( It.Is <PushToken>( e => e.Value.Equals(value) && e.Type.Equals(tokenType) && e.UserId.Equals(userId)))); Suite.PushTokenRepositoryMock.Verify(m => m.Save(), Times.Once); Assert.Equal(value, token.Value); Assert.Equal(tokenType, token.Type); Assert.Equal(userId, token.UserId); }
public async Task ReadTokensForFewUser() { var usersId = new int[] { 1, 2 }; var token1 = new PushToken { Value = "token1", Type = PushTokenType.Android, UserId = usersId[0] }; var token2 = new PushToken { Value = "token2", Type = PushTokenType.iOS, UserId = usersId[0] }; var token3 = new PushToken { Value = "token3", Type = PushTokenType.iOS, UserId = usersId[1] }; var tokens = new List <PushToken> { token1, token2, token3 }; Suite.PushTokenRepositoryMock .Setup(m => m.Get(usersId)) .ReturnsAsync(tokens); var result = await Suite.PushTokenService.ReadTokens(usersId); Assert.Equal(3, result.Count); Assert.Contains(token1, result); Assert.Contains(token2, result); Assert.Contains(token3, result); }
public async Task ReadTokensForOneUser() { var userId = 1; var token1 = new PushToken { Value = "token1", Type = PushTokenType.Android, UserId = userId }; var token2 = new PushToken { Value = "token2", Type = PushTokenType.iOS, UserId = userId }; var tokens = new List <PushToken> { token1, token2 }; Suite.PushTokenRepositoryMock .Setup(m => m.Get(new int [] { userId })) .ReturnsAsync(tokens); var result = await Suite.PushTokenService.ReadTokens(userId); Assert.Equal(2, result.Count); Assert.All(result, e => e.UserId.Equals(userId)); Assert.Contains(token1, result); Assert.Contains(token2, result); }
public void StorePushToken(string phoneId, string pushToken) { Account account = accountRepository.GetAccountByPhoneId(phoneId); if (account == null) { throw new HttpStatusCodeException( HttpStatusCode.NotFound, $"Account [{phoneId}] doesn't exist"); } else { PushToken newToken = new PushToken { Token = pushToken, Account = account }; pushTokenRepository.Add(newToken); } theaterScheduleUnitOfWork.Save(); }
public async Task DeleteTokensByUserId() { var userId = 1; var token1 = new PushToken { Value = "token1", Type = PushTokenType.Android, UserId = userId }; var token2 = new PushToken { Value = "token2", Type = PushTokenType.iOS, UserId = userId }; var token3 = new PushToken { Value = "token3", Type = PushTokenType.iOS, UserId = userId }; var tokens = new List <PushToken> { token1, token2, token3 }; Suite.PushTokenRepositoryMock .Setup(m => m.Get(new int [] { userId })) .ReturnsAsync(tokens); Suite.PushTokenRepositoryMock .Setup(m => m.ByValue("token1")) .ReturnsAsync(token1); Suite.PushTokenRepositoryMock .Setup(m => m.ByValue("token2")) .ReturnsAsync(token2); Suite.PushTokenRepositoryMock .Setup(m => m.ByValue("token3")) .ReturnsAsync(token3); await Suite.PushTokenService.DeleteTokensByUser(userId); Suite.PushTokenRepositoryMock.Verify(m => m.Get(new int [] { userId }), Times.Once); Suite.PushTokenRepositoryMock.Verify(m => m.Remove(token1), Times.Once); Suite.PushTokenRepositoryMock.Verify(m => m.Remove(token2), Times.Once); Suite.PushTokenRepositoryMock.Verify(m => m.Remove(token3), Times.Once); }
public async Task DeleteDifferentTokenType() { var value = "token"; var tokenType = PushTokenType.Android; var token = new PushToken { Value = value, Type = tokenType }; Suite.PushTokenRepositoryMock .Setup(m => m.ByValue(value)) .ReturnsAsync(token); await Assert.ThrowsAsync <ArgumentException>( () => Suite.PushTokenService.DeleteToken( value, PushTokenType.iOS, 1)); }
public async Task <IActionResult> login([FromForm] MyLogin myLogin) { var a = Request.RouteValues; var user = await userRepository.Login(myLogin.id, myLogin.pwd); if (user == null) { return(Ok(new AjaxResult() { status = "err", msg = "账号或密码错误" })); } IEnumerable <Claim> claims = new Claim[] { new Claim("id", user.Id.ToString()), new Claim(ClaimTypes.Role, "admin") }; string jwtToken = PushToken.PushMyToken(configuration, claims); return(Ok(new AjaxResult() { status = "ok", result = new { Id = user.Id, Name = user.Name, Authorization = jwtToken } })); }
public void Add(PushToken pushToken) { db.PushToken.Add(pushToken); }