Advertisement
Guest User

Untitled

a guest
Jul 14th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. public class BasicAuthenticationAttribute : AuthorizationFilterAttribute
  2. {
  3.  
  4. public static bool VaidateUserRoleWise(string username, string password, int RoleId)
  5. {
  6. //DO DATABASE CONNECTION DO QUERY HERE
  7. if (Username == username && Password == password)
  8. {
  9. return true;
  10. }
  11. else
  12. {
  13. return false;
  14. }
  15. }
  16. public override void OnAuthorization(QuizzrApi.Controllers.QuizzrController.InputParamAdminLogin LoginDetails)
  17. {
  18. System.Web.Http.Controllers.HttpActionContext actionContext = null;
  19. if (LoginDetails == null)
  20. {
  21. actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
  22. }
  23. else
  24. {
  25. //Bellow is the static method called above will return true or false if user matches
  26. if (!VaidateUserRoleWise(LoginDetails.UserName, LoginDetails.Password, 1))
  27. {
  28. actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
  29. }
  30. }
  31.  
  32. base.OnAuthorization(actionContext);
  33. }
  34.  
  35. }
  36.  
  37. [Route("AuthorizeSystemAdmin")]
  38. [HttpPost]
  39. [BasicAuthentication]
  40. public HttpResponseMessage Login([FromBody] InputParamAdminLogin AdminLoginInput)
  41. {
  42. //do your logic here
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement