Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- login: function (email, password) {
- var deferred = $q.defer();
- $http({
- url: global.API_URL + '/Auth/Login',
- method: 'POST',
- data: { email: email, password: encodeURIComponent(password)}
- }).then(function (response) {
- if (response.data.code == 0) {
- //If success go to home
- $state.go("dashboard");
- });
- [ActionName("Login")]
- [HttpPost]
- public JsonResult Index(string email, string password)
- {
- AwmsResponse response = new AwmsResponse();
- //Get the logged in user data
- Dal.User user = userService.GetUser(email);
- //Get the hash
- string hash = PasswordUtil.CreatePasswordHash(user.Salt, password);
- //Custom membership provider
- AwmsMembershipProvider provider = new AwmsMembershipProvider();
- bool isValid = provider.ValidateUser(email, hash);
- //if valid send response code 0
- response.code = 0;
- response.message = "Success";
- response.data = isValid ;
- return Json(response);
- }
- public class AwmsMembershipProvider : MembershipProvider
- {
- public override bool ValidateUser(string email, string hash)
- {
- bool isValid = false;
- using (var db = new AwmsContext())
- {
- User user = db.Users.SingleOrDefault(a => a.Email == email);
- if (user != null && user.PasswordHash != null && user.PasswordHash.Equals(hash))
- {
- isValid = true;
- }
- }
- return isValid;
- }
- .....
- <authentication mode="Forms">
- <forms loginUrl="~/Account/Login" timeout="20" />
- </authentication>
- ......
- <profile defaultProvider="DefaultProfileProvider">
- <providers>
- <clear/>
- <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
- </providers>
- </profile>
- public JsonResult GetRoles()
- {
- String token = (String)System.Web.HttpContext.Current.Session["TOKEN"];
- .....
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement