Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. function PostLogin() {
  2. var Emp = {};
  3. Emp.UserName = $("#txtUserName").val();
  4. var pass = $("#txtPassword").val();
  5. var hash = $.sha1(RequestToken + pass);
  6. $('#txtPassword').val(hash);
  7. Emp.Password= hash;
  8. Emp.RequestToken=RequestToken;
  9. var createurl = "http://localhost:54/api/Login";
  10. $.ajax({
  11. type: "POST",
  12. url: createurl,
  13. contentType: "application/json; charset=utf-8",
  14. data: JSON.stringify(Emp),
  15. statusCode: {
  16. 200: function () {
  17. $("#txtmsg").val("done");
  18. toastr.success('Success.', '');
  19. }
  20. },
  21. error:
  22. function (res) {
  23. toastr.error('Error.', 'sorry either your username of password was incorrect.');
  24. }
  25. });
  26. };
  27.  
  28. [AllowAnonymous]
  29. [HttpPost]
  30. public LoginModelOAuth PostLogin([FromBody]LoginModelOAuth model)
  31. {
  32. var accessResponse = OAuthServiceBase.Instance.AccessToken(model.RequestToken, "User", model.Username, model.Password, model.RememberMe);
  33.  
  34. if (!accessResponse.Success)
  35. {
  36. OAuthServiceBase.Instance.UnauthorizeToken(model.RequestToken);
  37. var requestResponse = OAuthServiceBase.Instance.RequestToken();
  38.  
  39. model.ErrorMessage = "Invalid Credentials";
  40.  
  41. return model;
  42. }
  43. else
  44. {
  45. // to do return accessResponse
  46.  
  47. return model;
  48. }
  49.  
  50. }
  51.  
  52. <configuration>
  53. <configSections>
  54. <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  55. <section name="oauth" type="MillionNodes.Configuration.OAuthSection, MillionNodes, Version=1.0.0.0, Culture=neutral"/>
  56. <sectionGroup name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth.Core">
  57. <section name="messaging" type="DotNetOpenAuth.Configuration.MessagingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" />
  58. <section name="reporting" type="DotNetOpenAuth.Configuration.ReportingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" />
  59. </sectionGroup>
  60. </configSections>
  61. <oauth defaultProvider="DemoProvider" defaultService="DemoService">
  62. <providers>
  63. <add name="DemoProvider" type="MillionNodes.OAuth.DemoProvider, MillionNodes" />
  64. </providers>
  65. <services>
  66. <add name="DemoService" type="MillionNodes.OAuth.DemoService, MillionNodes" />
  67. </services>
  68. </oauth>
  69. <system.web>
  70. <httpModules>
  71. <add name="OAuthAuthentication" type="MillionNodes.Module.OAuthAuthenticationModule, MillionNodes, Version=1.0.0.0, Culture=neutral"/>
  72. </httpModules>
  73. <compilation debug="true" targetFramework="4.0" />
  74. <authentication mode="Forms">
  75. <forms loginUrl="~/Account/Login" timeout="2880" />
  76. </authentication>
  77. <pages>
  78. <namespaces>
  79. <add namespace="System.Web.Helpers" />
  80. <add namespace="System.Web.Mvc" />
  81. <add namespace="System.Web.Mvc.Ajax" />
  82. <add namespace="System.Web.Mvc.Html" />
  83. <add namespace="System.Web.Optimization" />
  84. <add namespace="System.Web.Routing" />
  85. <add namespace="System.Web.WebPages" />
  86. </namespaces>
  87. </pages>
  88. </system.web>
  89. <system.webServer>
  90. <validation validateIntegratedModeConfiguration="false" />
  91. <modules>
  92. <add name="OAuthAuthentication" type="MillionNodes.Module.OAuthAuthenticationModule, MillionNodes, Version=1.0.0.0, Culture=neutral" preCondition="" />
  93. </modules>
  94. <httpProtocol>
  95. <customHeaders>
  96. <add name="Access-Control-Allow-Origin" value="*" />
  97. </customHeaders>
  98. </httpProtocol>
  99. </system.webServer>
  100. <dotNetOpenAuth>
  101. <messaging>
  102. <untrustedWebRequest>
  103. <whitelistHosts>
  104. <!-- Uncomment to enable communication with localhost (should generally not activate in production!) -->
  105. <!--<add name="localhost" />-->
  106. </whitelistHosts>
  107. </untrustedWebRequest>
  108. </messaging>
  109. <!-- Allow DotNetOpenAuth to publish usage statistics to library authors to improve the library. -->
  110. <reporting enabled="true" />
  111.  
  112. <httpProtocol>
  113. <customHeaders>
  114. <add name="Access-Control-Allow-Origin" value="*" />
  115. <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
  116. </customHeaders>
  117. </httpProtocol>
  118.  
  119. header("Access-Control-Allow-Origin: *");
  120. header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
  121.  
  122. header('Access-Control-Allow-Methods: GET, POST, PUT');
  123.  
  124. header('Access-Control-Allow-Origin: *');
  125. header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
  126. header('Access-Control-Allow-Methods: GET, POST, PUT');
  127.  
  128. add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since';
  129.  
  130. add_header 'Access-Control-Allow-Origin' '*';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement