public ResponseModel Logout()
        {
            ResponseModel resp = new ResponseModel();

            string token = Convert.ToString(Request.Headers["X-Authorized-Token"]);

            token = SecurityService.DecryptStringAES(token);

            RedisCacheService radisCacheService = new RedisCacheService(_radisCacheServerAddress);

            if (!radisCacheService.Exists(token))
            {
                radisCacheService.Remove(token);
            }

            securityCaller newSecurityCaller = new securityCaller();

            newSecurityCaller.Logout(new SecurityService(_connectioSting), token);

            resp.Status       = true;
            resp.StatusCode   = (int)EnumMaster.StatusCode.Success;
            resp.ResponseData = null;
            resp.Message      = "Logout Successfully!";

            return(resp);
        }
Exemple #2
0
        public void Exists_DifferentValues_Success(bool expected)
        {
            var key = _fixture.Create <string>();

            var expectedKey = $"{_keyPrefix}{key}";

            _dataBase.Setup(b => b.KeyExists(expectedKey, CommandFlags.None)).Returns(expected);


            var result = _target.Exists(key);


            _mockRepository.VerifyAll();

            Assert.AreEqual(expected, result);
        }
Exemple #3
0
        public ResponseModel UpdatePassword(string cipherEmailId, string Password)
        {
            ResponseModel objResponseModel = new ResponseModel();

            try
            {
                StoreSecurityCaller newSecurityCaller = new StoreSecurityCaller();

                CommonService commonService = new CommonService();

                EmailProgramCode bsObj            = new EmailProgramCode();
                string           encryptedEmailId = commonService.Decrypt(cipherEmailId);
                if (encryptedEmailId != null)
                {
                    bsObj = JsonConvert.DeserializeObject <EmailProgramCode>(encryptedEmailId);
                }

                string _data = "";
                if (bsObj.ProgramCode != null)
                {
                    // bsObj.ProgramCode = SecurityService.DecryptStringAES(bsObj.ProgramCode);

                    RedisCacheService cacheService = new RedisCacheService(_radisCacheServerAddress);
                    if (cacheService.Exists("Con" + bsObj.ProgramCode))
                    {
                        _data = cacheService.Get("Con" + bsObj.ProgramCode);
                        _data = JsonConvert.DeserializeObject <string>(_data);
                    }
                }
                bool isUpdate = newSecurityCaller.UpdatePassword(new StoreSecurityService(_data), bsObj.EmailID, Password);

                if (isUpdate)
                {
                    objResponseModel.Status       = true;
                    objResponseModel.StatusCode   = (int)EnumMaster.StatusCode.Success;
                    objResponseModel.Message      = CommonFunction.GetEnumDescription((EnumMaster.StatusCode)(int) EnumMaster.StatusCode.Success);
                    objResponseModel.ResponseData = "Update password successfully";
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(objResponseModel);
        }
Exemple #4
0
        public IActionResult Index()
        {
            //var cacheKey = "key";
            //string result;
            //if(string.IsNullOrWhiteSpace(_memoryCache.GetString(cacheKey)))
            //{
            //    result = DateTime.Now.ToString();
            //    _memoryCache.SetString(cacheKey, result);
            //}
            var cacheKey = "key";

            if (_cache.Exists(cacheKey))
            {
                var cacheValue = _cache.Get <string>(cacheKey);
                return(Content(cacheValue));
            }
            else
            {
                _cache.Add(cacheKey, DateTime.Now.ToString());
                return(View());
            }
        }
        public ResponseModel ForgetPassword(string EmailId)
        {
            ResponseModel objResponseModel = new ResponseModel();

            try
            {
                /////Validate User
                string X_Authorized_Programcode = Convert.ToString(Request.Headers["X-Authorized-Programcode"]);
                string X_Authorized_Domainname  = Convert.ToString(Request.Headers["X-Authorized-Domainname"]);
                string _data = "";
                if (X_Authorized_Programcode != null)
                {
                    X_Authorized_Programcode = SecurityService.DecryptStringAES(X_Authorized_Programcode);

                    RedisCacheService cacheService = new RedisCacheService(_radisCacheServerAddress);
                    if (cacheService.Exists("Con" + X_Authorized_Programcode))
                    {
                        _data = cacheService.Get("Con" + X_Authorized_Programcode);
                        _data = JsonConvert.DeserializeObject <string>(_data);
                    }
                }

                if (X_Authorized_Domainname != null)
                {
                    X_Authorized_Domainname = SecurityService.DecryptStringAES(X_Authorized_Domainname);
                }
                securityCaller securityCaller = new securityCaller();
                Authenticate   authenticate   = securityCaller.validateUserEmailId(new SecurityService(_data, _radisCacheServerAddress), EmailId);
                if (authenticate.UserMasterID > 0)
                {
                    MasterCaller masterCaller = new MasterCaller();
                    SMTPDetails  sMTPDetails  = masterCaller.GetSMTPDetails(new MasterServices(_data), authenticate.TenantId);

                    CommonService commonService    = new CommonService();
                    string        encryptedEmailId = commonService.Encrypt(EmailId);
                    string        url = X_Authorized_Domainname.TrimEnd('/') + "/storeUserforgotPassword?Id:" + encryptedEmailId;
                    // string body = "Hello, This is Demo Mail for testing purpose. <br/>" + url;

                    string content = "";
                    string subject = "";

                    securityCaller.GetForgetPassowrdMailContent(new SecurityService(_connectioSting), authenticate.TenantId, url, EmailId, out content, out subject);

                    bool isUpdate = securityCaller.sendMail(new SecurityService(_connectioSting), sMTPDetails, EmailId, subject, content, authenticate.TenantId);

                    if (isUpdate)
                    {
                        objResponseModel.Status       = true;
                        objResponseModel.StatusCode   = (int)EnumMaster.StatusCode.Success;
                        objResponseModel.Message      = CommonFunction.GetEnumDescription((EnumMaster.StatusCode)(int) EnumMaster.StatusCode.Success);
                        objResponseModel.ResponseData = "Mail sent successfully";
                    }
                    else
                    {
                        objResponseModel.Status       = false;
                        objResponseModel.StatusCode   = (int)EnumMaster.StatusCode.InternalServerError;
                        objResponseModel.Message      = CommonFunction.GetEnumDescription((EnumMaster.StatusCode)(int) EnumMaster.StatusCode.InternalServerError);
                        objResponseModel.ResponseData = "Mail sent failure";
                    }
                }
                else
                {
                    objResponseModel.Status       = false;
                    objResponseModel.StatusCode   = (int)EnumMaster.StatusCode.RecordNotFound;
                    objResponseModel.Message      = CommonFunction.GetEnumDescription((EnumMaster.StatusCode)(int) EnumMaster.StatusCode.RecordNotFound);
                    objResponseModel.ResponseData = "Sorry User does not exist or active";
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(objResponseModel);
        }
        public ResponseModel AuthenticateUser()
        {
            string X_Authorized_Programcode = Convert.ToString(Request.Headers["X-Authorized-Programcode"]);
            string X_Authorized_userId      = Convert.ToString(Request.Headers["X-Authorized-userId"]);
            string X_Authorized_password    = Convert.ToString(Request.Headers["X-Authorized-password"]);
            string X_Authorized_Domainname  = Convert.ToString(Request.Headers["X-Authorized-Domainname"]);

            ResponseModel resp = new ResponseModel();

            try
            {
                securityCaller newSecurityCaller = new securityCaller();
                AccountModal   account           = new AccountModal();
                string         Programcode       = X_Authorized_Programcode.Replace(' ', '+');
                string         Domainname        = X_Authorized_Domainname.Replace(' ', '+');
                string         userId            = X_Authorized_userId.Replace(' ', '+');
                string         password          = X_Authorized_password.Replace(' ', '+');


                string _data = "";
                if (X_Authorized_Programcode != null)
                {
                    X_Authorized_Programcode = SecurityService.DecryptStringAES(X_Authorized_Programcode);

                    RedisCacheService cacheService = new RedisCacheService(_radisCacheServerAddress);
                    if (cacheService.Exists("Con" + X_Authorized_Programcode))
                    {
                        _data = cacheService.Get("Con" + X_Authorized_Programcode);
                        _data = JsonConvert.DeserializeObject <string>(_data);
                    }
                }

                if (!string.IsNullOrEmpty(Programcode) && !string.IsNullOrEmpty(Domainname) && !string.IsNullOrEmpty(userId) && !string.IsNullOrEmpty(password))
                {
                    account = newSecurityCaller.validateUser(new SecurityService(_data, _radisCacheServerAddress), Programcode, Domainname, userId, password);

                    if (!string.IsNullOrEmpty(account.Token))
                    {
                        account.IsActive  = true;
                        resp.Status       = true;
                        resp.StatusCode   = (int)EnumMaster.StatusCode.Success;
                        resp.ResponseData = account;
                        resp.Message      = "Valid Login";
                    }
                    else
                    {
                        account.IsActive  = false;
                        resp.Status       = true;
                        resp.StatusCode   = (int)EnumMaster.StatusCode.Success;
                        resp.ResponseData = account;
                        resp.Message      = "In-Valid Login";
                    }
                }
                else
                {
                    resp.Status       = false;
                    resp.ResponseData = account;
                    resp.Message      = "Invalid Login";
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(resp);
        }
Exemple #7
0
        public ResponseModel SendMailforchangepassword(int userID, int IsStoreUser = 1)
        {
            CustomChangePassword customChangePassword = new CustomChangePassword();
            ResponseModel        objResponseModel     = new ResponseModel();

            try
            {
                string       token        = Convert.ToString(Request.Headers["X-Authorized-Token"]);
                Authenticate authenticate = new Authenticate();
                authenticate = SecurityService.GetAuthenticateDataFromToken(_radisCacheServerAddress, SecurityService.DecryptStringAES(token));
                string            _data        = "";
                string            ProgramCode  = authenticate.ProgramCode;
                RedisCacheService cacheService = new RedisCacheService(_radisCacheServerAddress);
                if (cacheService.Exists("Con" + ProgramCode))
                {
                    _data = cacheService.Get("Con" + ProgramCode);
                    _data = JsonConvert.DeserializeObject <string>(_data);
                }
                string X_Authorized_Domainname = Convert.ToString(Request.Headers["X-Authorized-Domainname"]);
                if (X_Authorized_Domainname != null)
                {
                    X_Authorized_Domainname = SecurityService.DecryptStringAES(X_Authorized_Domainname);
                }
                UserCaller userCaller = new UserCaller();

                customChangePassword = userCaller.SendMailforchangepassword(new UserServices(_data), userID, authenticate.TenantId, IsStoreUser);
                if (customChangePassword.UserID > 0 && customChangePassword.Password != null && customChangePassword.EmailID != null)
                {
                    MasterCaller   masterCaller     = new MasterCaller();
                    SMTPDetails    sMTPDetails      = masterCaller.GetSMTPDetails(new MasterServices(_data), authenticate.TenantId);
                    securityCaller _securityCaller  = new securityCaller();
                    CommonService  commonService    = new CommonService();
                    string         encryptedEmailId = SecurityService.Encrypt(customChangePassword.EmailID);

                    string decriptedPassword = SecurityService.DecryptStringAES(customChangePassword.Password);
                    string url      = configuration.GetValue <string>("websiteURL") + "/ChangePassword";
                    string body     = "Dear User, <br/>Please find the below details.  <br/><br/>" + "Your Email ID  : " + customChangePassword.EmailID + "<br/>" + "Your Password : "******"<br/><br/>" + "Click on Below link to change the Password <br/>" + url + "?Id:" + encryptedEmailId;
                    bool   isUpdate = _securityCaller.sendMailForChangePassword(new SecurityService(_connectioSting), sMTPDetails, customChangePassword.EmailID, body, authenticate.TenantId);
                    if (isUpdate)
                    {
                        objResponseModel.Status       = true;
                        objResponseModel.StatusCode   = (int)EnumMaster.StatusCode.Success;
                        objResponseModel.Message      = CommonFunction.GetEnumDescription((EnumMaster.StatusCode)(int) EnumMaster.StatusCode.Success);
                        objResponseModel.ResponseData = "Mail sent successfully";
                    }
                    else
                    {
                        objResponseModel.Status       = false;
                        objResponseModel.StatusCode   = (int)EnumMaster.StatusCode.InternalServerError;
                        objResponseModel.Message      = CommonFunction.GetEnumDescription((EnumMaster.StatusCode)(int) EnumMaster.StatusCode.InternalServerError);
                        objResponseModel.ResponseData = "Mail sent failure";
                    }
                }

                else
                {
                    objResponseModel.Status       = false;
                    objResponseModel.StatusCode   = (int)EnumMaster.StatusCode.RecordNotFound;
                    objResponseModel.Message      = CommonFunction.GetEnumDescription((EnumMaster.StatusCode)(int) EnumMaster.StatusCode.RecordNotFound);
                    objResponseModel.ResponseData = "Sorry User does not exist or active";
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(objResponseModel);
        }
        private AuthenticateResult Authenticate()
        {
            //ETSContext _DBContext = new ETSContext();
            string token  = Context.Request.Headers["X-Authorized-Token"];
            string userId = Context.Request.Headers["X-Authorized-userId"];

            if (token == null)
            {
                return(AuthenticateResult.Fail("No Authorization token provided"));
            }
            try
            {
                //string _userId = Decrypt(userId);
                //string isValidToken = validatetoken(token, _userId);

                //if (isValidToken == "1")
                //{
                //    var claims = new[] { new Claim(ClaimTypes.Name, isValidToken) };
                //    var identity = new ClaimsIdentity(claims, Scheme.Name);
                //    var principal = new ClaimsPrincipal(identity);
                //    var ticket = new AuthenticationTicket(principal, Scheme.Name);
                //    return AuthenticateResult.Success(ticket);

                //}
                //else
                //{
                //    return AuthenticateResult.Fail("Invalid Authorization");
                //}

                var routeData = Context.Request.Path.Value;
                //var XAuthorizedToken = Convert.ToString(context.Request.Headers["X-Authorized-Token"]);
                if (!string.IsNullOrEmpty(routeData))
                {
                    if (!routeData.Contains("dev-Ticketingsecuritymodule"))
                    {
                        if (!routeData.Contains("validateprogramcode"))
                        {
                            var XAuthorizedProgramcode = Convert.ToString(Context.Request.Headers["X-Authorized-Programcode"]);
                            if (string.IsNullOrEmpty(XAuthorizedProgramcode))
                            {
                                var XAuthorizedToken = Convert.ToString(Context.Request.Headers["X-Authorized-Token"]);

                                Authenticate authenticates = new Authenticate();
                                authenticates          = SecurityService.GetAuthenticateDataFromToken(_radisCacheServerAddress, SecurityService.DecryptStringAES(XAuthorizedToken));
                                XAuthorizedProgramcode = authenticates.ProgramCode;
                            }
                            else
                            {
                                XAuthorizedProgramcode = SecurityService.DecryptStringAES(XAuthorizedProgramcode);
                            }
                            if (XAuthorizedProgramcode != null)
                            {
                                RedisCacheService cacheService = new RedisCacheService(_radisCacheServerAddress);
                                if (cacheService.Exists("Con" + XAuthorizedProgramcode))
                                {
                                    string _data = cacheService.Get("Con" + XAuthorizedProgramcode);
                                    _data = JsonConvert.DeserializeObject <string>(_data);
                                    Configurations["ConnectionStrings:DataAccessMySqlProvider"] = _data;
                                }
                            }
                        }
                    }
                }


                Authenticate authenticate = SecurityService.GetAuthenticateDataFromToken(_radisCacheServerAddress, SecurityService.DecryptStringAES(token));

                if (!string.IsNullOrEmpty(authenticate.Token))
                {
                    var claims    = new[] { new Claim(ClaimTypes.Name, "1") };
                    var identity  = new ClaimsIdentity(claims, Scheme.Name);
                    var principal = new ClaimsPrincipal(identity);
                    var ticket    = new AuthenticationTicket(principal, Scheme.Name);
                    return(AuthenticateResult.Success(ticket));
                }
                else
                {
                    return(AuthenticateResult.Fail("Invalid Authorization"));
                }
            }
            catch (Exception ex)
            {
                return(AuthenticateResult.Fail("Failed to validate token"));
            }
        }
Exemple #9
0
 public void Exists_NullKey_Throws()
 {
     Assert.Throws <NullKeyException>(() => _target.Exists(null));
 }