Advertisement
Guest User

Untitled

a guest
Sep 29th, 2017
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.24 KB | None | 0 0
  1. angular.js:14642 TypeError: myService.post is not a function
  2.  
  3. [OperationContract]
  4. [WebInvoke(Method = "POST",
  5. RequestFormat = WebMessageFormat.Json,
  6. ResponseFormat = WebMessageFormat.Json,
  7. //BodyStyle = WebMessageBodyStyle.WrappedRequest,
  8. UriTemplate = "/AuthenticateUser")]
  9. bool AuthenticateUser(UserLogin userLogin);
  10.  
  11. public bool AuthenticateUser(UserLogin userLogin)
  12. {
  13. // ConfigurationManager class is in System.Configuration namespace
  14. string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
  15. // SqlConnection is in System.Data.SqlClient namespace
  16. using (SqlConnection con = new SqlConnection(CS))
  17. {
  18. SqlCommand cmd = new SqlCommand("spAuthenticateUser", con);
  19. cmd.CommandType = CommandType.StoredProcedure;
  20.  
  21. //Formsauthentication is in system.web.security
  22. string encryptedpassword = FormsAuthentication.HashPasswordForStoringInConfigFile(userLogin.Password, "SHA1");
  23.  
  24. //sqlparameter is in System.Data namespace
  25. SqlParameter paramUsername = new SqlParameter("@UserName", userLogin.Username);
  26. SqlParameter paramPassword = new SqlParameter("@Password", encryptedpassword);
  27.  
  28. cmd.Parameters.Add(paramUsername);
  29. cmd.Parameters.Add(paramPassword);
  30.  
  31. con.Open();
  32. SqlDataReader rdr = cmd.ExecuteReader();
  33. while (rdr.Read())
  34. {
  35. int RetryAttempts = Convert.ToInt32(rdr["RetryAttempts"]);
  36. if (Convert.ToBoolean(rdr["AccountLocked"]))
  37. {
  38. return true;
  39. }
  40. else if (RetryAttempts > 0)
  41. {
  42. int AttemptsLeft = (4 - RetryAttempts);
  43. //lblMessage.Text = "Invalid user name and/or password. " +
  44. // AttemptsLeft.ToString() + "attempt(s) left";
  45. }
  46. else if (Convert.ToBoolean(rdr["Authenticated"]))
  47. {
  48. return true;
  49. }
  50.  
  51. }
  52. return false;
  53. }
  54. }
  55.  
  56. var app = angular.module("WebClientModule", [])
  57.  
  58. .controller('Web_Client_Controller', ["$scope", 'myService', function ($scope, myService) {
  59.  
  60. $scope.OperType = 1;
  61.  
  62. //1 Mean New Entry
  63.  
  64. //To Clear all input controls.
  65. function ClearModels() {
  66. $scope.OperType = 1;
  67. $scope.Username = "";
  68. $scope.Password = "";
  69.  
  70.  
  71. }
  72.  
  73.  
  74. $scope.login = function () {
  75. var User = {
  76. Username: $scope.Username,
  77. Password: $scope.Password,
  78.  
  79.  
  80. };
  81. if ($scope.OperType === 1) {
  82. var promisePost = myService.AuthenticateUser(User);//Error on this line
  83. promisePost.then(function (pl) {
  84. $scope.Id = pl.data.Id;
  85. window.location.href = "/Login/WelcomePage";
  86.  
  87. ClearModels();
  88. }, function (err) {
  89. $scope.msg = "Password Incorrect !";
  90. console.log("Some error Occured" + err);
  91. });
  92. }
  93.  
  94. };
  95.  
  96.  
  97.  
  98. }]);
  99.  
  100. app.service("myService", function ($http) {
  101. // Create new record
  102.  
  103. this.AuthenticateUser = function (User) {
  104. return $http.post("http://localhost:52098/HalifaxIISService.svc/AuthenticateUser", JSON.stringify(User));
  105. }
  106. })
  107.  
  108. @{
  109. Layout = null;
  110. }
  111.  
  112. <!DOCTYPE html>
  113.  
  114. <html ng-app="WebClientModule">
  115. <head>
  116. <meta name="viewport" content="width=device-width" />
  117. <title>Index</title>
  118. <script src="~/Scripts/angular.min.js"></script>
  119.  
  120. <script src="~/RegistrationScript/LoginScript.js"></script>
  121. </head>
  122. <body>
  123. <table id="tblContainer" data-ng-controller="Web_Client_Controller">
  124. <tr>
  125. <td>
  126.  
  127. </td>
  128. </tr>
  129. <tr>
  130. <td>
  131. <div style="color: red;">{{Message}}</div>
  132. <table style="border: solid 4px Red; padding: 2px;">
  133.  
  134. <tr>
  135. <td></td>
  136. <td>
  137. <span>Username</span>
  138. </td>
  139. <td>
  140. <input type="text" id="username" data-ng-model="Username" required="" />
  141. </td>
  142. </tr>
  143. <tr>
  144. <td></td>
  145. <td>
  146. <span>Password</span>
  147. </td>
  148. <td>
  149. <input type="password" id="password" required data-ng-model="Password" require="" />
  150. </td>
  151. </tr>
  152.  
  153. <tr>
  154. <td></td>
  155. <td></td>
  156. <td>
  157. <input type="button" id="Login" value="Login" data-ng-click="login()" />
  158.  
  159. </td>
  160. </tr>
  161. </table>
  162. </td>
  163. </tr>
  164. </table>
  165. </body>
  166. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement