Example #1
0
        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
                }));
            }
        }
Example #3
0
        public async Task <IActionResult> Register(StringModel <RegisterDto> StringModel)
        {
            try
            {
                RegisterDto model = AESEncryptDecrypt <RegisterDto> .DecryptStringAES(StringModel.Model);

                byte[] ecodedString = Convert.FromBase64String(model.Password);
                string password     = Encoding.UTF8.GetString(ecodedString);

                AppIdentityUser identityUser = new AppIdentityUser
                {
                    UserName    = model.Username,
                    Email       = model.Email,
                    PhoneNumber = model.Phone
                };

                IdentityResult result = await _userManager.CreateAsync(identityUser, password);

                if (result.Succeeded)
                {
                    if (model.Roles != null && model.Roles.Any())
                    {
                        IdentityResult rolesResult = await _userManager.AddToRolesAsync(identityUser, model.Roles);
                    }

                    APIResult <Guid> userResult = await service.Register(model, Guid.Parse(identityUser.Id));

                    if (userResult.IsSuccess)
                    {
                        return(Ok(userResult));
                    }
                    else
                    {
                        await _userManager.DeleteAsync(identityUser);

                        return(Ok(userResult));
                    }
                }
                else
                {
                    return(Ok(new APIResult <List <string> > {
                        Message = Messages.Error, Data = result.Errors.Select(x => x.Description).ToList(), IsSuccess = false
                    }));
                }
            }
            catch (Exception ex)
            {
                return(Ok(new APIResult <List <string> > {
                    Message = Messages.Error, Data = new List <string> {
                        ex.ToString()
                    }, IsSuccess = false
                }));
            }
        }
Example #4
0
        /// <summary>
        /// Update User
        /// </summary>
        /// <param name="StringModel"></param>
        /// <returns></returns>
        public override async Task <IActionResult> Update(StringModel <UserUpdateDto> StringModel)
        {
            try
            {
                UserUpdateDto userUpdateDto = AESEncryptDecrypt <UserUpdateDto> .DecryptStringAES(StringModel.Model);

                APIResult <Guid> userUpdateResult = await service.Update(userUpdateDto, GetUserId <Guid>());

                if (userUpdateResult.Message != Messages.Ok)
                {
                    return(Ok(userUpdateResult));
                }

                AppIdentityUser identityUser = await _userManager.FindByIdAsync(userUpdateDto.IdentityUserID);

                IList <string> identityUserRoles = await _userManager.GetRolesAsync(identityUser);

                IdentityResult removeRolesResult = await _userManager.RemoveFromRolesAsync(identityUser, identityUserRoles);

                if (!removeRolesResult.Succeeded)
                {
                    return(Ok(new APIResult <List <string> > {
                        Message = Messages.Error, Data = removeRolesResult.Errors.Select(x => x.Description).ToList(), IsSuccess = false
                    }));
                }
                IdentityResult addRolesResult = await _userManager.AddToRolesAsync(identityUser, userUpdateDto.Roles);

                if (!addRolesResult.Succeeded)
                {
                    return(Ok(new APIResult <List <string> > {
                        Message = Messages.Error, Data = addRolesResult.Errors.Select(x => x.Description).ToList(), IsSuccess = false
                    }));
                }

                return(Ok(userUpdateResult));
            }
            catch (Exception ex)
            {
                return(Ok(new APIResult <List <string> > {
                    Data = new List <string> {
                        ex.ToString()
                    }, Message = Messages.Error, IsSuccess = false
                }));
            }
        }
Example #5
0
        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
                }));
            }
        }
Example #6
0
        public IActionResult XMLDecryptAndValidationWithOpenSSL([FromBody] Payload payload)
        {
            XmlDocument doc = new XmlDocument();

            try
            {
                doc.LoadXml(payload.xmlData);
                AESEncryptDecrypt.DecryptXml(doc);
                var isValidated = X509_Signature.X509_Signature.ValidateSignedinXmlDocument(doc.OuterXml);
                if (isValidated)
                {
                    string sendervid = "", receiverVid = "";

                    sendervid   = doc.GetElementsByTagName("DbtrAcct").Item(0).InnerText;
                    receiverVid = doc.GetElementsByTagName("CdtrAcct").Item(0).InnerText;
                    string amountstr = "";
                    amountstr = doc.GetElementsByTagName("IntrBkSttlmAmt").Item(0).InnerText;

                    string strDockerName     = System.Environment.MachineName;
                    string dtApiResponseTime = DateTime.Now.ToShortDateString();
                    try
                    {
                        DBUtility.WriteData(Guid.NewGuid().ToString(), "Hello-World", strDockerName, dtApiResponseTime, dtApiResponseTime);
                    }
                    catch (Exception)
                    {
                        throw;
                    }

                    return(new JsonResult(new { StatusCode = HttpStatusCode.OK, Message = "Direct Pay Successfull" }));
                }
                else
                {
                    return(new JsonResult(new { StatusCode = HttpStatusCode.BadRequest, Message = "XML validation failed" }));
                }
            }
            catch (Exception ex)
            {
                return(new JsonResult(new { StatusCode = HttpStatusCode.BadRequest, Message = ex.Message }));
            }
        }
Example #7
0
        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 Send(StringModel <NotificationModel> StringModel)
        {
            try
            {
                NotificationModel notificationModel = AESEncryptDecrypt <NotificationModel> .DecryptStringAES(StringModel.Model);

                var sendResult = oneSignalService.SendToNotification(notificationModel.Title, notificationModel.Message, notificationModel.Users, notificationModel.SendDate);
                if (!sendResult.IsSuccess)
                {
                    return(Ok(sendResult));
                }
                return(Ok(new APIResult <string> {
                    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
                }));
            }
        }