public string GenerateJSONWebToken(PassengerAcc passengerAcc)
        {
            var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"]));

            var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);

            var token = new JwtSecurityToken(_config["Jwt:Issuer"], _config["Jwt:Issuer"], null, expires: DateTime.Now.AddMinutes(30), signingCredentials: credentials);

            return(new JwtSecurityTokenHandler().WriteToken(token));
        }
示例#2
0
        public int RegisterNewPassenger(PassengerAcc user)
        {
            int result = 0;

            if (sysdb != null)
            {
                sysdb.PassengerAcc.Add(user);
                result = sysdb.SaveChanges();
            }
            return(result);
        }
        public IActionResult Register(PassengerAcc newpass)
        {
            _log4net.Info("MVCAdminController - Register");

            using (var httpclient = new HttpClient())
            {
                httpclient.BaseAddress = new Uri("https://localhost:44368/api/Admin/");
                var postPassData = httpclient.PostAsJsonAsync <PassengerAcc>("RegisterNewPassenger", newpass);
                var res          = postPassData.Result;

                if (res.IsSuccessStatusCode)
                {
                    return(RedirectToAction("AllPassenger"));
                }
            }
            return(View(newpass));
        }
        public PassengerAcc AuthenticateUser(User user)
        {
            PassengerAcc passenger = null;

            List <PassengerAcc> allpassenger = _sysdb.PassengerAcc.ToList();

            foreach (var v in allpassenger)
            {
                int passId = int.Parse(user.PassengerId);

                if (v.PassengerId == passId && v.PassengerPassword == user.PassengerPassword)
                {
                    passenger = new PassengerAcc {
                        PassengerId = passId, PassengerPassword = user.PassengerPassword
                    };
                }
            }
            return(passenger);
        }
        string GenerateJSONWebToken(PassengerAcc user)
        {
            _log4net.Info("TokenValidateController - GenerateToken");

            var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"]));

            var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);

            var claims = new[]
            {
                new Claim(System.IdentityModel.Tokens.Jwt.JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
            };

            var token = new JwtSecurityToken(_config["Jwt: Issuer"], _config["Jwt: Issuer"], null, expires: DateTime.Now.AddMinutes(120), signingCredentials: credentials);

            var encodetoken = new JwtSecurityTokenHandler().WriteToken(token);

            return(encodetoken);
        }
示例#6
0
        public IActionResult RegisterNewPassenger([FromBody] PassengerAcc user)
        {
            _log4net.Info("AdminController - RegisterNewPassenger");

            try
            {
                var register = adm.RegisterNewPassenger(user);
                if (register > 0)
                {
                    return(Ok(register));
                }
                else
                {
                    return(NoContent());
                }
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
示例#7
0
        public void RegisterNewPassenger_InvalidInput_ReturnsBadRequest()
        {
            try
            {
                var mock = new Mock <admin>(sysdb);

                AdminController obj = new AdminController(mock.Object);

                PassengerAcc pass = new PassengerAcc {
                    Id = 24, PassengerId = 2225, PassengerPassword = "******", PassengerName = "Rahul", PassengerAddress = "Lane24", PassengerMobile = "7737425842"
                };

                var data = obj.RegisterNewPassenger(pass);

                var res = data as BadRequestObjectResult;

                Assert.AreEqual(400, res.StatusCode);
            }
            catch (Exception e)
            {
                Assert.AreEqual("Object reference not set to an instance of an object.", e.Message);
            }
        }
示例#8
0
        public void RegisterNewPassenger_ValidInput_OkRequest()
        {
            try
            {
                var mock = new Mock <admin>(sysdb);

                AdminController obj = new AdminController(mock.Object);

                PassengerAcc pass = new PassengerAcc {
                    Id = 21, PassengerId = 2222, PassengerPassword = "******", PassengerName = "Keshav", PassengerAddress = "Lane21", PassengerMobile = "8872892242"
                };

                var data = obj.RegisterNewPassenger(pass);

                var res = data as ObjectResult;

                Assert.AreEqual(200, res.StatusCode);
            }
            catch (Exception e)
            {
                Assert.AreEqual("Object reference not set to an instance of an object.", e.Message);
            }
        }