예제 #1
0
        public object GetToken([FromBody] ValidateDto validateDto)
        {
            var key = "WebApiTestingKey";

            if (validateDto.Account == validateDto.Password)
            {
                var claims = new[] {
                    new Claim(ClaimTypes.Name, validateDto.Account)
                };

                var creds = new SigningCredentials(new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key)),
                                                   SecurityAlgorithms.HmacSha256);

                var token = new JwtSecurityToken(
                    claims: claims,
                    expires: DateTime.Now.AddHours(1),
                    signingCredentials: creds
                    );

                var responseToken = new { token = new JwtSecurityTokenHandler().WriteToken(token) };
                return(Ok(responseToken));
            }
            else
            {
                return(BadRequest("wrong account or password"));
            }
        }
예제 #2
0
        public List <ValidateDto> Validateuser(string connection, string strUserId, string strIPAddr, string strUserPwd)
        {
            using (IDbConnection db = new SqlConnection(connection))
            {
                DynamicParameters objparmaeters = new DynamicParameters();
                objparmaeters.Add("@strUserId", strUserId);
                objparmaeters.Add("@strIPAddr", strIPAddr);
                objparmaeters.Add("@strUserPwd", dbType: DbType.String, value: strUserPwd, direction: ParameterDirection.Output, size: 5215585);
                objparmaeters.Add("@FailureMsg", dbType: DbType.String, value: null, direction: ParameterDirection.Output, size: 5215585);
                objparmaeters.Add("@InvalidLoginAttempts", dbType: DbType.Int16, value: 0, direction: ParameterDirection.Output, size: 5215585);
                var validdetials = db.Query("crm.ValidateUser", objparmaeters, commandType: CommandType.StoredProcedure, commandTimeout: 0);
                //Getting the out parameter value of stored procedure
                ValidateDto validate = new ValidateDto();
                validate.strUserPwd           = objparmaeters.Get <string>("@strUserPwd");
                validate.FailureMsg           = objparmaeters.Get <string>("@FailureMsg");
                validate.InvalidLoginAttempts = objparmaeters.Get <Int16>("@InvalidLoginAttempts");

                List <ValidateDto> Validatelist = new List <ValidateDto>();
                Validatelist.Add(validate);

                return(Validatelist);
            }
        }
예제 #3
0
        public IActionResult Create([FromBody] CompanyDto body)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                ValidateDto validate = _companyService.Validate(body);
                if (!validate.IsValid)
                {
                    return(BadRequest(validate.Msg));
                }

                long id = _companyService.Create(body);

                return(StatusCode(201, new { id }));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.ToString()));
            }
        }
예제 #4
0
        public IActionResult Test([FromForm] ValidateDto dto)
        {
            var name = HttpUtility.UrlEncode(dto.Id);

            return(Ok(name));
        }
예제 #5
0
 public IActionResult Index([FromBody] ValidateDto dto)
 {
     throw new CustomException("aaa");
 }