public override async Task <IActionResult> GetById(Guid id) { try { UserCardDto user = await service.GetByID(id); if (user == null) { return(Ok(new APIResult <UserCardDto> { Message = Messages.NoRecord, IsSuccess = false })); } AppIdentityUser identityUser = await _userManager.FindByIdAsync(user.IdentityUserID); IList <string> identityUserRoles = await _userManager.GetRolesAsync(identityUser); user.Roles = identityUserRoles.ToList(); string str = Newtonsoft.Json.JsonConvert.SerializeObject(user); string base64Data = Convert.ToBase64String(Encoding.Default.GetBytes(str)); string encryptredData = AESEncryptDecrypt <string> .EncryptStringAES(base64Data); return(Ok(new APIResult <string> { Data = encryptredData, IsSuccess = true })); } catch (Exception ex) { return(Ok(new APIResult <string> { Message = ex.ToString(), IsSuccess = false })); } }
public async Task <IActionResult> Token(StringModel <LoginDto> StringModel) { try { LoginDto model = AESEncryptDecrypt <LoginDto> .DecryptStringAES(StringModel.Model); byte[] ecodedString = Convert.FromBase64String(model.Password); string password = Encoding.UTF8.GetString(ecodedString); Microsoft.AspNetCore.Identity.SignInResult result = await _signInManager.PasswordSignInAsync(model.Username, password, false, false); if (result.Succeeded) { AppIdentityUser appUser = _userManager.Users.SingleOrDefault(r => r.UserName == model.Username); if (appUser == null) { return(Ok(new APIResult <Guid> { Message = Messages.NoRecord, IsSuccess = false })); } IList <string> appUserRoles; appUserRoles = await _userManager.GetRolesAsync(appUser); Service.DTOs.UserCardDto user = await _userService.GetUserByIdentityID(Guid.Parse(appUser.Id)); string token = TokenBuilder.CreateJsonWebToken(appUser.UserName, appUserRoles, "https://www.tulparyazilim.com.tr", "https://www.tulparyazilim.com.tr", Guid.NewGuid(), DateTime.UtcNow.AddDays(30)); var data = new TokenDto { ValidTo = DateTime.UtcNow.AddDays(30), Value = token, Roles = string.Join(',', appUserRoles), Username = appUser.UserName, Email = appUser.Email }; string str = Newtonsoft.Json.JsonConvert.SerializeObject(data); string base64Data = Convert.ToBase64String(Encoding.Default.GetBytes(str)); string encryptredData = AESEncryptDecrypt <string> .EncryptStringAES(base64Data); return(Ok(new APIResult <string> { Message = Messages.Ok, Data = encryptredData, IsSuccess = true })); } return(Ok(new APIResult <Guid> { Message = Messages.NoRecord, IsSuccess = false })); } catch (Exception ex) { return(Ok(new APIResult <Guid> { Message = ex.ToString(), IsSuccess = false })); } }
public IActionResult GetRoleList() { try { IQueryable <AppIdentityRole> data = _roleManager.Roles; string str = Newtonsoft.Json.JsonConvert.SerializeObject(data); string base64Data = Convert.ToBase64String(Encoding.Default.GetBytes(str)); string encryptredData = AESEncryptDecrypt <string> .EncryptStringAES(base64Data); return(Ok(new APIResult <string> { Data = encryptredData, IsSuccess = true })); } catch (Exception ex) { return(Ok(new APIResult <string> { Message = ex.ToString(), IsSuccess = false })); } }
public async Task <IActionResult> GetList() { try { List <UserCardDto> data = await service.GetList(); string str = Newtonsoft.Json.JsonConvert.SerializeObject(data); string base64Data = Convert.ToBase64String(Encoding.Default.GetBytes(str)); string encryptredData = AESEncryptDecrypt <string> .EncryptStringAES(base64Data); return(Ok(new APIResult <string> { Data = encryptredData, IsSuccess = true })); } catch (Exception ex) { return(Ok(new APIResult <string> { Message = ex.ToString(), IsSuccess = false })); } }
public IActionResult GetList() { try { APIResult <string> notificationResult = oneSignalService.GetNotifications(); if (!notificationResult.IsSuccess) { return(Ok(notificationResult)); } string base64Data = Convert.ToBase64String(Encoding.Default.GetBytes(notificationResult.Data)); string encryptredData = AESEncryptDecrypt <string> .EncryptStringAES(base64Data); return(Ok(new APIResult <string> { Data = encryptredData, IsSuccess = true })); } catch (Exception ex) { return(Ok(new APIResult <string> { Message = ex.ToString(), IsSuccess = false })); } }