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")); } }
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); } }
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())); } }
public IActionResult Test([FromForm] ValidateDto dto) { var name = HttpUtility.UrlEncode(dto.Id); return(Ok(name)); }
public IActionResult Index([FromBody] ValidateDto dto) { throw new CustomException("aaa"); }