Advertisement
Guest User

Untitled

a guest
Sep 13th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. login: function (email, password) {
  2. var deferred = $q.defer();
  3. $http({
  4. url: global.API_URL + '/Auth/Login',
  5. method: 'POST',
  6. data: { email: email, password: encodeURIComponent(password)}
  7. }).then(function (response) {
  8. if (response.data.code == 0) {
  9. //If success go to home
  10. $state.go("dashboard");
  11. });
  12.  
  13. [ActionName("Login")]
  14. [HttpPost]
  15. public JsonResult Index(string email, string password)
  16. {
  17. AwmsResponse response = new AwmsResponse();
  18. //Get the logged in user data
  19. Dal.User user = userService.GetUser(email);
  20.  
  21. //Get the hash
  22. string hash = PasswordUtil.CreatePasswordHash(user.Salt, password);
  23.  
  24. //Custom membership provider
  25. AwmsMembershipProvider provider = new AwmsMembershipProvider();
  26. bool isValid = provider.ValidateUser(email, hash);
  27.  
  28. //if valid send response code 0
  29. response.code = 0;
  30. response.message = "Success";
  31. response.data = isValid ;
  32.  
  33. return Json(response);
  34. }
  35.  
  36. public class AwmsMembershipProvider : MembershipProvider
  37. {
  38. public override bool ValidateUser(string email, string hash)
  39. {
  40. bool isValid = false;
  41. using (var db = new AwmsContext())
  42. {
  43. User user = db.Users.SingleOrDefault(a => a.Email == email);
  44. if (user != null && user.PasswordHash != null && user.PasswordHash.Equals(hash))
  45. {
  46. isValid = true;
  47. }
  48. }
  49. return isValid;
  50. }
  51.  
  52. .....
  53. <authentication mode="Forms">
  54. <forms loginUrl="~/Account/Login" timeout="20" />
  55. </authentication>
  56. ......
  57. <profile defaultProvider="DefaultProfileProvider">
  58. <providers>
  59. <clear/>
  60. <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
  61. </providers>
  62. </profile>
  63.  
  64. public JsonResult GetRoles()
  65. {
  66. String token = (String)System.Web.HttpContext.Current.Session["TOKEN"];
  67. .....
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement